Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: adds support for the kernel.controller listener. #45

Merged
merged 2 commits into from
Jun 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
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
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