diff --git a/composer.json b/composer.json index e0a56c6..f12abf5 100644 --- a/composer.json +++ b/composer.json @@ -43,7 +43,7 @@ "phpspec/prophecy-phpunit": "^2.0", "friendsofphp/php-cs-fixer": "^3.4", "phpstan/phpstan": "^1.2", - "sentry/sentry-symfony": "^4.0", + "sentry/sentry-symfony": "^4.5", "symfony/framework-bundle": "^4.0 || ^5.0 || ^6.0", "nyholm/psr7": "^1.2", "doctrine/mongodb-odm": "^2.2", @@ -59,7 +59,7 @@ }, "conflict": { "doctrine/doctrine-bundle": "<2.1.1", - "sentry/sentry-symfony": "<4.0.0", + "sentry/sentry-symfony": "<4.5.0", "spiral/roadrunner-metrics": "<2.0.1" }, "scripts": { diff --git a/src/DependencyInjection/BaldinofRoadRunnerExtension.php b/src/DependencyInjection/BaldinofRoadRunnerExtension.php index b8c4c4e..105145d 100644 --- a/src/DependencyInjection/BaldinofRoadRunnerExtension.php +++ b/src/DependencyInjection/BaldinofRoadRunnerExtension.php @@ -12,6 +12,7 @@ use Baldinof\RoadRunnerBundle\Integration\PHP\NativeSessionMiddleware; use Baldinof\RoadRunnerBundle\Integration\Sentry\SentryListener; use Baldinof\RoadRunnerBundle\Integration\Sentry\SentryMiddleware; +use Baldinof\RoadRunnerBundle\Integration\Sentry\SentryTracingRequestListenerDecorator; use Baldinof\RoadRunnerBundle\Integration\Symfony\ConfigureVarDumperListener; use Baldinof\RoadRunnerBundle\Reboot\AlwaysRebootStrategy; use Baldinof\RoadRunnerBundle\Reboot\ChainRebootStrategy; @@ -20,6 +21,7 @@ use Baldinof\RoadRunnerBundle\Reboot\OnExceptionRebootStrategy; use Doctrine\Persistence\ManagerRegistry; use Psr\Log\LoggerInterface; +use Sentry\SentryBundle\EventListener\TracingRequestListener; use Sentry\State\HubInterface; use Spiral\RoadRunner\GRPC\ServiceInterface; use Spiral\RoadRunner\Metrics\Collector; @@ -143,6 +145,14 @@ private function loadIntegrations(ContainerBuilder $container, array $config): v ->addArgument(new Reference(HubInterface::class)) ->setAutoconfigured(true); + $container + ->register(SentryTracingRequestListenerDecorator::class) + ->setDecoratedService(TracingRequestListener::class) + ->setArguments([ + new Reference(SentryTracingRequestListenerDecorator::class.'.inner'), + new Reference(HubInterface::class), + ]); + $beforeMiddlewares[] = SentryMiddleware::class; } diff --git a/src/Integration/Sentry/SentryTracingRequestListenerDecorator.php b/src/Integration/Sentry/SentryTracingRequestListenerDecorator.php new file mode 100644 index 0000000..aad71bb --- /dev/null +++ b/src/Integration/Sentry/SentryTracingRequestListenerDecorator.php @@ -0,0 +1,45 @@ +innerListener = $innerListener; + $this->hub = $hub; + } + + public function handleKernelRequestEvent(RequestEvent $event): void + { + $this->innerListener->handleKernelRequestEvent($event); + } + + public function handleKernelResponseEvent(ResponseEvent $event): void + { + $this->innerListener->handleKernelResponseEvent($event); + $transaction = $this->hub->getTransaction(); + + if (null === $transaction) { + return; + } + + $transaction->finish(); + } + + public function handleKernelTerminateEvent(TerminateEvent $event): void + { + // do nothing + } +}