Skip to content

Commit

Permalink
enable context on CLI scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
christopheg committed Sep 12, 2024
1 parent 12153bf commit 9a1b13a
Showing 1 changed file with 20 additions and 10 deletions.
30 changes: 20 additions & 10 deletions lib/Skeleton/Error/Handler/SentrySdk.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,28 @@ public function handle() {
\Sentry\SentrySdk::getCurrentHub()->bindClient($builder->getClient());

// Assign the session to the extra context
$environment = [];
if (isset($_SESSION)) {
\Sentry\SentrySdk::getCurrentHub()->configureScope(function (\Sentry\State\Scope $scope): void {
$scope->setContext('environment', [
'session' => $_SESSION,
'post' => $_POST,
'get' => $_GET,
'server' => $_SERVER,
]);
if (isset($_SERVER['REMOTE_ADDR'])) {
$scope->setUser(['ip_address' => $_SERVER['REMOTE_ADDR'] ]);
$environment['session'] = $_SESSION;
}
if (!empty($_POST)) {
$environment['post'] = $_POST;
}
if (!empty($_GET)) {
$environment['get'] = $_GET;
}
if (isset($_SERVER)) {
$environment['server'] = $_SERVER;
}
if (count($environment) > 0) {
\Sentry\SentrySdk::getCurrentHub()->configureScope(
function (\Sentry\State\Scope $scope) use ($environment): void {
$scope->setContext('environment', $environment);
if (isset($_SERVER['REMOTE_ADDR'])) {
$scope->setUser(['ip_address' => $_SERVER['REMOTE_ADDR'] ]);
}
}
});
);
}

\Sentry\SentrySdk::getCurrentHub()->captureException($this->exception);
Expand Down

0 comments on commit 9a1b13a

Please sign in to comment.