diff --git a/src/sentry/class_map/SentrySdk.php b/src/sentry/class_map/SentrySdk.php index 37d47ff15..299a541a6 100644 --- a/src/sentry/class_map/SentrySdk.php +++ b/src/sentry/class_map/SentrySdk.php @@ -60,6 +60,6 @@ public static function getCurrentHub(): HubInterface */ public static function setCurrentHub(HubInterface $hub): HubInterface { - return tap($hub, fn ($hub) => Context::set(__CLASS__, $hub)); + return Context::set(__CLASS__, $hub); } } diff --git a/src/sentry/publish/sentry.php b/src/sentry/publish/sentry.php index 88afa449e..b00f47fa9 100644 --- a/src/sentry/publish/sentry.php +++ b/src/sentry/publish/sentry.php @@ -87,6 +87,7 @@ 'crontab:run', 'gen:*', 'migrate*', + 'sentry:test', 'tinker', 'vendor:publish', ], diff --git a/src/sentry/src/ConfigProvider.php b/src/sentry/src/ConfigProvider.php index 03f4d332c..e7e149680 100644 --- a/src/sentry/src/ConfigProvider.php +++ b/src/sentry/src/ConfigProvider.php @@ -50,13 +50,12 @@ public function __invoke(): array 'dependencies' => [ \Sentry\ClientBuilder::class => Factory\ClientBuilderFactory::class, \Sentry\State\HubInterface::class => Factory\HubFactory::class, - // \Sentry\HttpClient\HttpClientInterface::class => HttpClient\HttpClientFactory::class, \Sentry\Transport\TransportInterface::class => Transport\CoHttpTransport::class, ], 'listeners' => [ - Listener\EventHandleListener::class, - Crons\Listener\EventHandleListener::class, - Tracing\Listener\EventHandleListener::class, + Listener\EventHandleListener::class => PHP_INT_MAX - 1, + Crons\Listener\EventHandleListener::class => PHP_INT_MAX - 1, + Tracing\Listener\EventHandleListener::class => PHP_INT_MAX, // !! Make sure it is the first one to handle the event ], 'annotations' => [ 'scan' => [ diff --git a/src/sentry/src/Listener/EventHandleListener.php b/src/sentry/src/Listener/EventHandleListener.php index f5c471977..544aae370 100644 --- a/src/sentry/src/Listener/EventHandleListener.php +++ b/src/sentry/src/Listener/EventHandleListener.php @@ -16,7 +16,6 @@ use Hyperf\Amqp\Event as AmqpEvent; use Hyperf\AsyncQueue\Event as AsyncQueueEvent; use Hyperf\Command\Event as CommandEvent; -use Hyperf\Context\Context; use Hyperf\Contract\ConfigInterface; use Hyperf\Contract\StdoutLoggerInterface; use Hyperf\Crontab\Event as CrontabEvent; @@ -44,8 +43,6 @@ */ class EventHandleListener implements ListenerInterface { - public const HUB = 'sentry.context.hub'; - protected array $missingKeys = [ // Enable 'sentry.enable.amqp', @@ -207,11 +204,6 @@ protected function captureException(?Throwable $throwable): void } } - protected function setupSentrySdk(): void - { - Context::getOrSet(static::HUB, fn () => SentrySdk::init()); - } - protected function flushEvents(): void { try { @@ -356,8 +348,6 @@ protected function handleRequestReceived(object $event): void if (! $this->feature->isEnabled('request')) { return; } - - $this->setupSentrySdk(); } /** @@ -382,8 +372,6 @@ protected function handleCommandStarting(object $event): void return; } - $this->setupSentrySdk(); - Integration::configureScope(static function (Scope $scope) use ($event): void { $scope->setTag('command', $event->getCommand()->getName()); }); @@ -456,8 +444,6 @@ protected function handleAsyncQueueJobProcessing(object $event): void return; } - $this->setupSentrySdk(); - if ($this->feature->isBreadcrumbEnabled('async_queue')) { $job = [ 'job' => $event->getMessage()->job()::class, @@ -507,8 +493,6 @@ protected function handleCrontabTaskStarting(object $event): void if (! $this->feature->isEnabled('crontab')) { return; } - - $this->setupSentrySdk(); } /** @@ -544,8 +528,6 @@ protected function handleAmqpMessageProcessing(object $event): void if (! $this->feature->isEnabled('amqp')) { return; } - - $this->setupSentrySdk(); } /** @@ -581,8 +563,6 @@ protected function handleKafkaMessageProcessing(object $event): void if (! $this->feature->isEnabled('kafka')) { return; } - - $this->setupSentrySdk(); } /** diff --git a/src/sentry/src/Tracing/Tracer.php b/src/sentry/src/Tracing/Tracer.php index d7f46bf65..a4a79e892 100644 --- a/src/sentry/src/Tracing/Tracer.php +++ b/src/sentry/src/Tracing/Tracer.php @@ -35,8 +35,11 @@ public function __construct(protected Feature $feature) */ public function startTransaction(TransactionContext $transactionContext, array $customSamplingContext = []): Transaction { - $hub = SentrySdk::init(); + $hub = SentrySdk::getCurrentHub(); $hub->pushScope(); + $hub->configureScope(static fn (Scope $scope) => $scope->clearBreadcrumbs()); + + defer(static fn () => $hub->popScope()); $transactionContext->setData(['coroutine.id' => Coroutine::id()] + $transactionContext->getData());