Skip to content

Commit

Permalink
feat: adds support for the kernel.controller listener.
Browse files Browse the repository at this point in the history
  • Loading branch information
jcchavezs committed Jun 7, 2019
1 parent 666308d commit 92ce552
Showing 1 changed file with 29 additions and 4 deletions.
33 changes: 29 additions & 4 deletions src/ZipkinBundle/Middleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@
use Psr\Log\LoggerInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
use Symfony\Component\HttpKernel\Event\PostResponseEvent;
use Symfony\Component\HttpKernel\Event\FilterControllerEvent;
use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
use Zipkin\Kind;
use Zipkin\Tags;
use Zipkin\Propagation\Map;
use Zipkin\Propagation\SamplingFlags;
use Zipkin\Propagation\TraceContext;
use Zipkin\Tags;
use Zipkin\Propagation\SamplingFlags;
use function Zipkin\Timestamp\now;
use Zipkin\Tracer;
use Zipkin\Tracing;

Expand Down Expand Up @@ -55,6 +57,9 @@ public function __construct(
$this->spanCustomizers = $spanCustomizers;
}

/**
* @see https://symfony.com/doc/3.4/reference/events.html#kernel-request
*/
public function onKernelRequest(GetResponseEvent $event)
{
if (!$event->isMasterRequest()) {
Expand Down Expand Up @@ -85,19 +90,39 @@ public function onKernelRequest(GetResponseEvent $event)
$this->scopeCloser = $this->tracing->getTracer()->openScope($span);
}

public function onKernelException(GetResponseForExceptionEvent $event)
/**
* @see https://symfony.com/doc/3.4/reference/events.html#kernel-controller
*/
public function onKernelController(FilterControllerEvent $event)
{
if (!$event->isMasterRequest()) {
return;
}

$span = $this->tracing->getTracer()->getCurrentSpan();
if ($span !== null) {
$span->annotate('symfony.kernel.controller', now());
}
}

/**
* @see https://symfony.com/doc/3.4/reference/events.html#kernel-exception
*/
public function onKernelException(GetResponseForExceptionEvent $event)
{
if (!$event->isMasterRequest()) {
return;
}

$span = $this->tracing->getTracer()->getCurrentSpan();
if ($span !== null) {
$span->tag(Tags\ERROR, $event->getException()->getMessage());
}
}

/**
* @see https://symfony.com/doc/3.4/reference/events.html#kernel-terminate
*/
public function onKernelTerminate(PostResponseEvent $event)
{
if (!$event->isMasterRequest()) {
Expand Down

0 comments on commit 92ce552

Please sign in to comment.