File "LaravelContextIntegration.php"
Full Path: /var/www/drive/sentry/sentry-laravel/src/Sentry/Laravel/Integration/LaravelContextIntegration.php
File size: 1.05 KB
MIME-type: text/x-php
Charset: utf-8
<?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;
});
}
}