-
-
Notifications
You must be signed in to change notification settings - Fork 189
/
Copy pathLaravelContextIntegration.php
38 lines (30 loc) · 1.05 KB
/
LaravelContextIntegration.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<?php
namespace Sentry\Laravel\Integration;
use Illuminate\Support\Facades\Context;
use Sentry\Event;
use Sentry\EventHint;
use Sentry\EventType;
use Sentry\Integration\IntegrationInterface;
use Sentry\SentrySdk;
use Sentry\State\Scope;
class LaravelContextIntegration implements IntegrationInterface
{
public function setupOnce(): void
{
// Context was introduced in Laravel 11 so we need to check if we can use it otherwise we skip the event processor
if (!class_exists(Context::class)) {
return;
}
Scope::addGlobalEventProcessor(static function (Event $event, ?EventHint $hint = null): Event {
$self = SentrySdk::getCurrentHub()->getIntegration(self::class);
if (!$self instanceof self) {
return $event;
}
if (!in_array($event->getType(), [EventType::event(), EventType::transaction()], true)) {
return $event;
}
$event->setContext('laravel', Context::all());
return $event;
});
}
}