Adding scope does not work
GrantAnt opened this issue · 2 comments
I have tried multiple ways to add scope after Sentry::init(). The new tags are not showing up.
e.g.: I am calling this from in my AppController->before
\Sentry\configureScope(function (\Sentry\State\Scope $scope): void {
$scope->setUser(['email' => $this->user->email]);
$scope->setTag('email', $this->user->email);
});
or I have been implementing certain EventListenerInterface and set the tags there. They never show up.
So I got curios and tried to add a new tag in my app.php
and the test tag was shown immediately!!
'Sentry' => [
'tags' => ['test' => 'test'],
'dsn' => env('SENTRY_DSN'),
'environment' => env('ENVIRONMENT', 'localhost'),
],
Versions:
- cakephp/cakephp: 4.2.7
- "connehito/cake-sentry": "^4.0",
- sentry/sentry (3.3.1) -- also tried with sentry/sentry (3.3.4)
Small update. I try to set the user like this:
\Sentry\configureScope(function (\Sentry\State\Scope $scope) {
$scope->setUser(['email' => 'jane.doe@example.com']);
});
When I set to user in 'CakeSentry.Client.afterSetup' Event, it's succesfully shown.
When I set to user in 'CakeSentry.Client.beforeCapture' Event, it's not shown at all.
But I need to read the user from the request, which is not available in the ''afterSetup"
I found the solution. It just needs an update in the readme file.
Tags and the user can be set like this:
class SentryOptionsContext implements EventListenerInterface
{
public function implementedEvents(): array
{
return [
'CakeSentry.Client.beforeCapture' => 'setContext',
];
}
public function setContext(Event $event): void
{
$event->getSubject()->getHub()->configureScope(function (\Sentry\State\Scope $scope) {
$scope->setUser(['email' => 'jane.doe@example.com']);
});
}
}