Skip to content
This repository has been archived by the owner on Jun 23, 2021. It is now read-only.

Commit

Permalink
III-3528 Log runtime env cli/web to Sentry
Browse files Browse the repository at this point in the history
  • Loading branch information
LucWollants committed Oct 9, 2020
1 parent 46fb893 commit bf022de
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
3 changes: 2 additions & 1 deletion app/ErrorHandlerProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ function ($app) {
return new SentryErrorHandler(
$app[HubInterface::class],
$app['jwt'] ?? null,
$app['auth.api_key'] ?? null
$app['auth.api_key'] ?? null,
false
);
}
);
Expand Down
11 changes: 8 additions & 3 deletions app/SentryErrorHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,15 @@ class SentryErrorHandler
/** @var ApiKey|null */
private $apiKey;

public function __construct(HubInterface $sentryHub, ?Udb3Token $udb3Token, ?ApiKey $apiKey)
/** @var boolean */
private $console;

public function __construct(HubInterface $sentryHub, ?Udb3Token $udb3Token, ?ApiKey $apiKey, bool $console)
{
$this->sentryHub = $sentryHub;
$this->udb3Token = $udb3Token;
$this->apiKey = $apiKey;
$this->console = $console;
}

public function handle(Throwable $throwable): void
Expand All @@ -36,7 +40,7 @@ public function handle(Throwable $throwable): void

$this->sentryHub->configureScope(function (Scope $scope) {
$scope->setUser($this->createUser($this->udb3Token));
$scope->setTags($this->createTags($this->apiKey));
$scope->setTags($this->createTags($this->apiKey, $this->console));
});

$this->sentryHub->captureException($throwable);
Expand All @@ -56,10 +60,11 @@ private function createUser(?Udb3Token $udb3Token): array
];
}

private function createTags(?ApiKey $apiKey): array
private function createTags(?ApiKey $apiKey, bool $console): array
{
return [
'api_key' => $apiKey ? $apiKey->toNative() : 'null',
'runtime.env' => $console ? 'cli' : 'web',
];
}
}

0 comments on commit bf022de

Please sign in to comment.