Skip to content

Commit

Permalink
Sentry Tracing (#67)
Browse files Browse the repository at this point in the history
* Added ability to use SentryTracing feature

* Update services.php

* Rename SentryTracingRequestListener to SentryTracingRequestListener.php

* Update services.php

added use Symfony\Component\DependencyInjection\ContainerInterface;

* Update composer.json

Updated sentry/sentry-symfony version (which include tracing feature)

* Updated versions and decorator events

* php < 8 fix && DI fix

* typo fix

* fixed namespace

* cs-fix && DI

* fixed typo

* DI fix

* CS fix && decoration

* Fixed DI

* Fixed DI

* ci fix

* Update src/DependencyInjection/BaldinofRoadRunnerExtension.php
  • Loading branch information
iborysenko authored Apr 5, 2023
1 parent adf9501 commit 1a4785c
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 2 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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": {
Expand Down
10 changes: 10 additions & 0 deletions src/DependencyInjection/BaldinofRoadRunnerExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
}

Expand Down
45 changes: 45 additions & 0 deletions src/Integration/Sentry/SentryTracingRequestListenerDecorator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

declare(strict_types=1);

namespace Baldinof\RoadRunnerBundle\Integration\Sentry;

use Sentry\SentryBundle\EventListener\TracingRequestListener;
use Sentry\State\HubInterface;
use Symfony\Component\HttpKernel\Event\RequestEvent;
use Symfony\Component\HttpKernel\Event\ResponseEvent;
use Symfony\Component\HttpKernel\Event\TerminateEvent;

final class SentryTracingRequestListenerDecorator
{
private TracingRequestListener $innerListener;
private HubInterface $hub;

public function __construct(TracingRequestListener $innerListener, HubInterface $hub)
{
$this->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
}
}

0 comments on commit 1a4785c

Please sign in to comment.