8000 Deprecation free by andrew-demb · Pull Request #18 · code-tool/jaeger-client-symfony-bridge · GitHub
[go: up one dir, main page]

Skip to content

Deprecation free #18

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

Merged
merged 2 commits into from
Jun 29, 2021
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
19 changes: 18 additions & 1 deletion src/Bridge/AppStartSpanListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Jaeger\Tag\SpanKindServerTag;
use Jaeger\Tracer\TracerInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\KernelEvent;
use Symfony\Component\HttpKernel\Event\RequestEvent;

class AppStartSpanListener implements EventSubscriberInterface
Expand All @@ -27,7 +28,7 @@ public static function getSubscribedEvents(): array
public function onRequest(RequestEvent $event)
{
$request = $event->getRequest();
if (false === $event->isMasterRequest()) {
if (false === $this->isMainRequestEvent($event)) {
return $this;
}
$this->tracer
Expand All @@ -40,4 +41,20 @@ public function onRequest(RequestEvent $event)

return $this;
}

/**
* Use non-deprecated check method if availble
*
* @param KernelEvent $event
*
* @return bool
*/
private function isMainRequestEvent(KernelEvent $event): bool
{
if (\method_exists($event, 'isMainRequest')) {
return $event->isMainRequest();
}

return $event->isMasterRequest();
}
}
19 changes: 18 additions & 1 deletion src/Bridge/ContextListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Jaeger\Tracer\InjectableInterface;
use Symfony\Component\Console\Event\ConsoleCommandEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\KernelEvent;
use Symfony\Component\HttpKernel\Event\RequestEvent;

class ContextListener implements EventSubscriberInterface
Expand Down Expand Up @@ -46,9 +47,25 @@ public function inject(): void

public function onRequest(RequestEvent $event): void
{
if (false === $event->isMasterRequest()) {
if (false === $this->isMainRequestEvent($event)) {
return;
}
$this->inject();
}

/**
* Use non-deprecated check method if availble
*
* @param KernelEvent $event
*
* @return bool
*/
private function isMainRequestEvent(KernelEvent $event): bool
{
if (\method_exists($event, 'isMainRequest')) {
return $event->isMainRequest();
}

return $event->isMasterRequest();
}
}
19 changes: 18 additions & 1 deletion src/Bridge/DebugListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Symfony\Component\Console\Event\ConsoleCommandEvent;
use Symfony\Component\Console\Event\ConsoleTerminateEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\KernelEvent;
use Symfony\Component\HttpKernel\Event\RequestEvent;
use Symfony\Component\HttpKernel\Event\TerminateEvent;

Expand Down Expand Up @@ -48,12 +49,28 @@ public function onCommand(): void

public function onRequest(RequestEvent $event)
{
if (false === $event->isMasterRequest()) {
if (false === $this->isMainRequestEvent($event)) {
return;
}
if ('' === ($debugId = $this->extractor->getDebug())) {
return;
}
$this->debuggable->enable($debugId);
}

/**
* Use non-deprecated check method if availble
*
* @param KernelEvent $event
*
* @return bool
*/
private function isMainRequestEvent(KernelEvent $event): bool
{
if (\method_exists($event, 'isMainRequest')) {
return $event->isMainRequest();
}

return $event->isMasterRequest();
}
}
19 changes: 18 additions & 1 deletion src/Bridge/GlobalSpanListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
namespace Jaeger\Symfony\Bridge;

use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\KernelEvent;
use Symfony\Component\HttpKernel\Event\RequestEvent;
use Symfony\Component\HttpKernel\Event\TerminateEvent;

Expand Down Expand Up @@ -33,11 +34,27 @@ public function onTerminate()

public function onRequest(RequestEvent $event)
{
if (false === $event->isMasterRequest()) {
if (false === $this->isMainRequestEvent($event)) {
return $this;
}
$this->handler->start($event->getRequest());

return $this;
}

/**
* Use non-deprecated check method if availble
*
* @param KernelEvent $event
*
* @return bool
*/
private function isMainRequestEvent(KernelEvent $event): bool
{
if (\method_exists($event, 'isMainRequest')) {
return $event->isMainRequest();
}

return $event->isMasterRequest();
}
}
21 changes: 19 additions & 2 deletions src/Bridge/RequestSpanListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Jaeger\Tracer\TracerInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\ExceptionEvent;
use Symfony\Component\HttpKernel\Event\KernelEvent;
use Symfony\Component\HttpKernel\Event\RequestEvent;
use Symfony\Component\HttpKernel\Event\ResponseEvent;

Expand Down Expand Up @@ -44,7 +45,7 @@ public static function getSubscribedEvents(): array

public function onResponse(ResponseEvent $event): void
{
if ($event->isMasterRequest()) {
if (false === $this->isMainRequestEvent($event)) {
return;
}
if ($this->spans->isEmpty()) {
Expand All @@ -55,7 +56,7 @@ public function onResponse(ResponseEvent $event): void

public function onRequest(RequestEvent $event): void
{
if ($event->isMasterRequest()) {
if (false === $this->isMainRequestEvent($event)) {
return;
}
$request = $event->getRequest();
Expand Down Expand Up @@ -86,4 +87,20 @@ public function onKernelException(ExceptionEvent $event): void
->addLog(new ErrorLog($exception->getMessage(), $exception->getTraceAsString()))
;
}

/**
* Use non-deprecated check method if availble
*
* @param KernelEvent $event
*
* @return bool
*/
private function isMainRequestEvent(KernelEvent $event): bool
{
if (\method_exists($event, 'isMainRequest')) {
return $event->isMainRequest();
}

return $event->isMasterRequest();
}
}
21 changes: 19 additions & 2 deletions src/Context/Extractor/HeaderContextExtractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Jaeger\Codec\CodecRegistry;
use Jaeger\Span\Context\SpanContext;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\KernelEvent;
use Symfony\Component\HttpKernel\Event\RequestEvent;
use Symfony\Component\HttpKernel\Event\TerminateEvent;

Expand Down Expand Up @@ -45,15 +46,15 @@ public function extract(): ?SpanContext

public function onTerminate(TerminateEvent $event): void
{
if (false === $event->isMasterRequest()) {
if (false === $this->isMainRequestEvent($event)) {
return;
}
$this->context = null;
}

public function onRequest(RequestEvent $event): void
{
if (false === $event->isMasterRequest()) {
if (false === $this->isMainRequestEvent($event)) {
return;
}
$request = $event->getRequest();
Expand All @@ -62,4 +63,20 @@ public function onRequest(RequestEvent $event): void
$this->context = $context;
}
}

/**
* Use non-deprecated check method if availble
*
* @param KernelEvent $event
*
* @return bool
*/
private function isMainRequestEvent(KernelEvent $event): bool
{
if (\method_exists($event, 'isMainRequest')) {
return $event->isMainRequest();
}

return $event->isMasterRequest();
}
}
21 changes: 19 additions & 2 deletions src/Debug/Extractor/CookieDebugExtractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
namespace Jaeger\Symfony\Debug\Extractor;

use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\KernelEvent;
use Symfony\Component\HttpKernel\Event\RequestEvent;
use Symfony\Component\HttpKernel\Event\TerminateEvent;

Expand All @@ -20,7 +21,7 @@ public function __construct(string $cookieName)

public function onRequest(RequestEvent $event): void
{
if (false === $event->isMasterRequest()) {
if (false === $this->isMainRequestEvent($event)) {
return;
}
$request = $event->getRequest();
Expand All @@ -32,7 +33,7 @@ public function onRequest(RequestEvent $event): void

public function onTerminate(TerminateEvent $event): void
{
if (false === $event->isMasterRequest()) {
if (false === $this->isMainRequestEvent($event)) {
return;
}
$this->debugId = '';
Expand All @@ -50,4 +51,20 @@ public static function getSubscribedEvents(): array
TerminateEvent::class => ['onTerminate'],
];
}

/**
* Use non-deprecated check method if availble
*
* @param KernelEvent $event
*
* @return bool
*/
private function isMainRequestEvent(KernelEvent $event): bool
{
if (\method_exists($event, 'isMainRequest')) {
return $event->isMainRequest();
}

return $event->isMasterRequest();
}
}
50 changes: 50 additions & 0 deletions src/DependencyInjection/DeprecatedAliasesCompilerPass.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php
declare(strict_types=1);

namespace Jaeger\Symfony\DependencyInjection;

use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Dumper\Preloader;

class DeprecatedAliasesCompilerPass implements CompilerPassInterface
{
public function process(ContainerBuilder $container): void
{
$container->getAlias('jaeger.span.handler.gloabal')
->setDeprecated(
...
$this->getDeprecationMsg(
'The "%alias_id%" service is deprecated. Use "jaeger.span.handler.global".',
'3.5.0'
)
);
}

/**
* Returns the correct deprecation param's as an array for setDeprecated.
*
* symfony/dependency-injection v5.1 introduces a deprecation notice when calling
* setDeprecation() with less than 3 args and the
* `Symfony\Component\DependencyInjection\Dumper\Preloader` class was
* introduced at the same time. By checking if this class exists,
* we can determine the correct param count to use when calling setDeprecated.
*
* @param string $message
* @param string $version
*
* @return array
*/
private function getDeprecationMsg(string $message, string $version): array
{
if (class_exists(Preloader::class)) {
return [
'code-tool/jaeger-client-symfony-bridge',
$version,
$message,
];
}

return [$message];
}
}
4 changes: 3 additions & 1 deletion src/JaegerBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Jaeger\Symfony\DependencyInjection\CodecRegistryCompilerPass;
use Jaeger\Symfony\DependencyInjection\ContextExtractorChainCompilerPass;
use Jaeger\Symfony\DependencyInjection\DebugExtractorChainCompilerPass;
use Jaeger\Symfony\DependencyInjection\DeprecatedAliasesCompilerPass;
use Jaeger\Symfony\DependencyInjection\NameGeneratorChainCompilerPass;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Bundle\Bundle;
Expand All @@ -19,6 +20,7 @@ public function build(ContainerBuilder $container)
->addCompilerPass(new CodecRegistryCompilerPass())
->addCompilerPass(new ContextExtractorChainCompilerPass())
->addCompilerPass(new DebugExtractorChainCompilerPass())
->addCompilerPass(new NameGeneratorChainCompilerPass());
->add 558 CompilerPass(new NameGeneratorChainCompilerPass())
->addCompilerPass(new DeprecatedAliasesCompilerPass());
}
}
7 changes: 4 additions & 3 deletions src/Resources/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,6 @@ services:
jaeger.span.handler.background:
class: Jaeger\Symfony\Bridge\BackgroundSpanHandler
arguments: ['@jaeger.tracer']
jaeger.span.handler.gloabal:
alias: jaeger.span.handler.global
deprecated: 'The "%alias_id%" service is deprecated. Use "jaeger.span.handler.global".'
jaeger.span.handler.global:
class: Jaeger\Symfony\Bridge\GlobalSpanHandler
arguments: ['@jaeger.tracer', '@jaeger.name.generator']
Expand Down Expand Up @@ -198,3 +195,7 @@ services:
- '@jaeger.span.manager'
tags:
- {name: 'kernel.event_subscriber'}
# deprecated since 3.5.0
jaeger.span.handler.gloabal:
alias: jaeger.span.handler.global

0