Skip to content

Commit

Permalink
Fix Sentry integration when tracing is disabled (#107)
Browse files Browse the repository at this point in the history
  • Loading branch information
Baldinof authored Apr 16, 2023
1 parent 1a4785c commit 0c25061
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/DependencyInjection/BaldinofRoadRunnerExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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),
Expand Down
39 changes: 39 additions & 0 deletions tests/BaldinofRoadRunnerBundleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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([], []);
Expand Down

0 comments on commit 0c25061

Please sign in to comment.