Skip to content

Commit

Permalink
Merge pull request #45 from jcchavezs/adds_kernel_controller_listener
Browse files Browse the repository at this point in the history
feat: adds support for the kernel.controller listener.
  • Loading branch information
jcchavezs committed Jun 9, 2019
2 parents 666308d + ee94477 commit 1ca8856
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 6 deletions.
4 changes: 2 additions & 2 deletions .circleci/config.yml
Expand Up @@ -15,7 +15,7 @@ jobs:
php -r "if (hash_file('SHA384', 'composer-setup.php') === trim(file_get_contents('https://composer.github.io/installer.sig'))) { echo 'Installer verified'; } else { echo 'Installer invalid'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
php -r "unlink('composer-setup.php');"
- run: curl -sSL https://zipkin.io/quickstart.sh | bash -s
- run: curl -sSL https://zipkin.apache.org/quickstart.sh | bash -s
- run:
background: true
command: java -jar zipkin.jar
Expand Down Expand Up @@ -48,7 +48,7 @@ jobs:
php -r "if (hash_file('SHA384', 'composer-setup.php') === trim(file_get_contents('https://composer.github.io/installer.sig'))) { echo 'Installer verified'; } else { echo 'Installer invalid'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
php -r "unlink('composer-setup.php');"
- run: curl -sSL https://zipkin.io/quickstart.sh | bash -s
- run: curl -sSL https://zipkin.apache.org/quickstart.sh | bash -s
- run:
background: true
command: java -jar zipkin.jar
Expand Down
33 changes: 29 additions & 4 deletions src/ZipkinBundle/Middleware.php
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 1ca8856

Please sign in to comment.