diff --git a/src/DependencyInjection/BaldinofRoadRunnerExtension.php b/src/DependencyInjection/BaldinofRoadRunnerExtension.php index 105145d..f8575d3 100644 --- a/src/DependencyInjection/BaldinofRoadRunnerExtension.php +++ b/src/DependencyInjection/BaldinofRoadRunnerExtension.php @@ -28,6 +28,7 @@ use Spiral\RoadRunner\Metrics\MetricsInterface; use Symfony\Component\Config\FileLocator; use Symfony\Component\DependencyInjection\ContainerBuilder; +use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\DependencyInjection\Definition; use Symfony\Component\DependencyInjection\Exception\LogicException; use Symfony\Component\DependencyInjection\Extension\Extension; @@ -147,7 +148,7 @@ private function loadIntegrations(ContainerBuilder $container, array $config): v $container ->register(SentryTracingRequestListenerDecorator::class) - ->setDecoratedService(TracingRequestListener::class) + ->setDecoratedService(TracingRequestListener::class, null, 0, ContainerInterface::IGNORE_ON_INVALID_REFERENCE) ->setArguments([ new Reference(SentryTracingRequestListenerDecorator::class.'.inner'), new Reference(HubInterface::class), diff --git a/tests/BaldinofRoadRunnerBundleTest.php b/tests/BaldinofRoadRunnerBundleTest.php index 85f6447..d5b4061 100644 --- a/tests/BaldinofRoadRunnerBundleTest.php +++ b/tests/BaldinofRoadRunnerBundleTest.php @@ -10,6 +10,7 @@ use Baldinof\RoadRunnerBundle\Integration\Doctrine\DoctrineORMMiddleware; use Baldinof\RoadRunnerBundle\Integration\PHP\NativeSessionMiddleware; use Baldinof\RoadRunnerBundle\Integration\Sentry\SentryMiddleware; +use Baldinof\RoadRunnerBundle\Integration\Sentry\SentryTracingRequestListenerDecorator; use Baldinof\RoadRunnerBundle\Integration\Symfony\StreamedResponseListener; use Baldinof\RoadRunnerBundle\Reboot\AlwaysRebootStrategy; use Baldinof\RoadRunnerBundle\Reboot\ChainRebootStrategy; @@ -56,6 +57,44 @@ public function test_it_loads_sentry_middleware_if_needed() $this->assertTrue($c->has(SentryMiddleware::class)); } + public function test_with_sentry_tracing_disabled() + { + $k = $this->getKernel([ + 'sentry' => [ + 'tracing' => [ + 'enabled' => false, + ], + ], + ], [ + new SentryBundle(), + ]); + + $k->boot(); + + $c = $k->getContainer()->get('test.service_container'); + + $this->assertFalse($c->has(SentryTracingRequestListenerDecorator::class)); + } + + public function test_with_sentry_tracing_enabled() + { + $k = $this->getKernel([ + 'sentry' => [ + 'tracing' => [ + 'enabled' => true, + ], + ], + ], [ + new SentryBundle(), + ]); + + $k->boot(); + + $c = $k->getContainer()->get('test.service_container'); + + $this->assertTrue($c->has(SentryTracingRequestListenerDecorator::class)); + } + public function test_it_does_not_load_sentry_middleware_if_not_needed() { $k = $this->getKernel([], []);