Skip to content

Commit

Permalink
Merge pull request #59 from wadjei/amend-kernel-listener-example
Browse files Browse the repository at this point in the history
Amend bundle kernel listener example
  • Loading branch information
bobstrecansky authored May 20, 2022
2 parents 5106605 + c69a5de commit 9418b3f
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/Symfony/OtelSdkBundle/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ use OpenTelemetry\API\Trace\SpanInterface;
use OpenTelemetry\SDK\Trace\Tracer;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\HttpKernel\Event\RequestEvent;
use Symfony\Component\HttpKernel\Event\TerminateEvent;
class TracingKernelSubscriber implements EventSubscriberInterface
Expand All @@ -221,12 +222,15 @@ class TracingKernelSubscriber implements EventSubscriberInterface
// store a reference to the Tracer instance in case we want to create
// more spans on different events (not covered in this example)
$this->tracer = $tracer;
}
public function onRequestEvent(RequestEvent $event)
{
// Create our main span and activate it
$this->mainSpan = $tracer->spanBuilder('main')->startSpan();
$this->mainSpan = $this->tracer->spanBuilder('main')->startSpan();
$this->mainSpan->activate();
}
public function onTerminateEvent(TerminateEvent $event): void
{
// end our main span once the request has been processed and the kernel terminates.
Expand All @@ -236,9 +240,11 @@ class TracingKernelSubscriber implements EventSubscriberInterface
public static function getSubscribedEvents(): array
{
// return the subscribed events, their methods and priorities
// use a very low negative integer for the priority, so the listener
// will be the last one to be called.
// use a very high integer for the Request priority and a
// very low negative integer for the Terminate priority, so the listener
// will be the first and last one to be called respectively.
return [
KernelEvents::TERMINATE => [['onRequestEvent', 10000]],
KernelEvents::TERMINATE => [['onTerminateEvent', -10000]],
];
}
Expand Down

0 comments on commit 9418b3f

Please sign in to comment.