Skip to content

Commit 5cf21a4

Browse files
authored
Merge pull request #18 from andrew-demb/deprecation-free
Deprecation free
2 parents a80cd45 + e746361 commit 5cf21a4

File tree

10 files changed

+186
-14
lines changed

10 files changed

+186
-14
lines changed

src/Bridge/AppStartSpanListener.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Jaeger\Tag\SpanKindServerTag;
99
use Jaeger\Tracer\TracerInterface;
1010
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
11+
use Symfony\Component\HttpKernel\Event\KernelEvent;
1112
use Symfony\Component\HttpKernel\Event\RequestEvent;
1213

1314
class AppStartSpanListener implements EventSubscriberInterface
@@ -27,7 +28,7 @@ public static function getSubscribedEvents(): array
2728
public function onRequest(RequestEvent $event)
2829
{
2930
$request = $event->getRequest();
30-
if (false === $event->isMasterRequest()) {
31+
if (false === $this->isMainRequestEvent($event)) {
3132
return $this;
3233
}
3334
$this->tracer
@@ -40,4 +41,20 @@ public function onRequest(RequestEvent $event)
4041

4142
return $this;
4243
}
44+
45+
/**
46+
* Use non-deprecated check method if availble
47+
*
48+
* @param KernelEvent $event
49+
*
50+
* @return bool
51+
*/
52+
private function isMainRequestEvent(KernelEvent $event): bool
53+
{
54+
if (\method_exists($event, 'isMainRequest')) {
55+
return $event->isMainRequest();
56+
}
57+
58+
return $event->isMasterRequest();
59+
}
4360
}

src/Bridge/ContextListener.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Jaeger\Tracer\InjectableInterface;
88
use Symfony\Component\Console\Event\ConsoleCommandEvent;
99
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
10+
use Symfony\Component\HttpKernel\Event\KernelEvent;
1011
use Symfony\Component\HttpKernel\Event\RequestEvent;
1112

1213
class ContextListener implements EventSubscriberInterface
@@ -46,9 +47,25 @@ public function inject(): void
4647

4748
public function onRequest(RequestEvent $event): void
4849
{
49-
if (false === $event->isMasterRequest()) {
50+
if (false === $this->isMainRequestEvent($event)) {
5051
return;
5152
}
5253
$this->inject();
5354
}
55+
56+
/**
57+
* Use non-deprecated check method if availble
58+
*
59+
* @param KernelEvent $event
60+
*
61+
* @return bool
62+
*/
63+
private function isMainRequestEvent(KernelEvent $event): bool
64+
{
65+
if (\method_exists($event, 'isMainRequest')) {
66+
return $event->isMainRequest();
67+
}
68+
69+
return $event->isMasterRequest();
70+
}
5471
}

src/Bridge/DebugListener.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Symfony\Component\Console\Event\ConsoleCommandEvent;
99
use Symfony\Component\Console\Event\ConsoleTerminateEvent;
1010
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
11+
use Symfony\Component\HttpKernel\Event\KernelEvent;
1112
use Symfony\Component\HttpKernel\Event\RequestEvent;
1213
use Symfony\Component\HttpKernel\Event\TerminateEvent;
1314

@@ -48,12 +49,28 @@ public function onCommand(): void
4849

4950
public function onRequest(RequestEvent $event)
5051
{
51-
if (false === $event->isMasterRequest()) {
52+
if (false === $this->isMainRequestEvent($event)) {
5253
return;
5354
}
5455
if ('' === ($debugId = $this->extractor->getDebug())) {
5556
return;
5657
}
5758
$this->debuggable->enable($debugId);
5859
}
60+
61+
/**
62+
* Use non-deprecated check method if availble
63+
*
64+
* @param KernelEvent $event
65+
*
66+
* @return bool
67+
*/
68+
private function isMainRequestEvent(KernelEvent $event): bool
69+
{
70+
if (\method_exists($event, 'isMainRequest')) {
71+
return $event->isMainRequest();
72+
}
73+
74+
return $event->isMasterRequest();
75+
}
5976
}

src/Bridge/GlobalSpanListener.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
namespace Jaeger\Symfony\Bridge;
55

66
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
7+
use Symfony\Component\HttpKernel\Event\KernelEvent;
78
use Symfony\Component\HttpKernel\Event\RequestEvent;
89
use Symfony\Component\HttpKernel\Event\TerminateEvent;
910

@@ -33,11 +34,27 @@ public function onTerminate()
3334

3435
public function onRequest(RequestEvent $event)
3536
{
36-
if (false === $event->isMasterRequest()) {
37+
if (false === $this->isMainRequestEvent($event)) {
3738
return $this;
3839
}
3940
$this->handler->start($event->getRequest());
4041

4142
return $this;
4243
}
44+
45+
/**
46+
* Use non-deprecated check method if availble
47+
*
48+
* @param KernelEvent $event
49+
*
50+
* @return bool
51+
*/
52+
private function isMainRequestEvent(KernelEvent $event): bool
53+
{
54+
if (\method_exists($event, 'isMainRequest')) {
55+
return $event->isMainRequest();
56+
}
57+
58+
return $event->isMasterRequest();
59+
}
4360
}

src/Bridge/RequestSpanListener.php

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Jaeger\Tracer\TracerInterface;
1616
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
1717
use Symfony\Component\HttpKernel\Event\ExceptionEvent;
18+
use Symfony\Component\HttpKernel\Event\KernelEvent;
1819
use Symfony\Component\HttpKernel\Event\RequestEvent;
1920
use Symfony\Component\HttpKernel\Event\ResponseEvent;
2021

@@ -44,7 +45,7 @@ public static function getSubscribedEvents(): array
4445

4546
public function onResponse(ResponseEvent $event): void
4647
{
47-
if ($event->isMasterRequest()) {
48+
if (false === $this->isMainRequestEvent($event)) {
4849
return;
4950
}
5051
if ($this->spans->isEmpty()) {
@@ -55,7 +56,7 @@ public function onResponse(ResponseEvent $event): void
5556

5657
public function onRequest(RequestEvent $event): void
5758
{
58-
if ($event->isMasterRequest()) {
59+
if (false === $this->isMainRequestEvent($event)) {
5960
return;
6061
}
6162
$request = $event->getRequest();
@@ -86,4 +87,20 @@ public function onKernelException(ExceptionEvent $event): void
8687
->addLog(new ErrorLog($exception->getMessage(), $exception->getTraceAsString()))
8788
;
8889
}
90+
91+
/**
92+
* Use non-deprecated check method if availble
93+
*
94+
* @param KernelEvent $event
95+
*
96+
* @return bool
97+
*/
98+
private function isMainRequestEvent(KernelEvent $event): bool
99+
{
100+
if (\method_exists($event, 'isMainRequest')) {
101+
return $event->isMainRequest();
102+
}
103+
104+
return $event->isMasterRequest();
105+
}
89106
}

src/Context/Extractor/HeaderContextExtractor.php

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Jaeger\Codec\CodecRegistry;
88
use Jaeger\Span\Context\SpanContext;
99
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
10+
use Symfony\Component\HttpKernel\Event\KernelEvent;
1011
use Symfony\Component\HttpKernel\Event\RequestEvent;
1112
use Symfony\Component\HttpKernel\Event\TerminateEvent;
1213

@@ -45,15 +46,15 @@ public function extract(): ?SpanContext
4546

4647
public function onTerminate(TerminateEvent $event): void
4748
{
48-
if (false === $event->isMasterRequest()) {
49+
if (false === $this->isMainRequestEvent($event)) {
4950
return;
5051
}
5152
$this->context = null;
5253
}
5354

5455
public function onRequest(RequestEvent $event): void
5556
{
56-
if (false === $event->isMasterRequest()) {
57+
if (false === $this->isMainRequestEvent($event)) {
5758
return;
5859
}
5960
$request = $event->getRequest();
@@ -62,4 +63,20 @@ public function onRequest(RequestEvent $event): void
6263
$this->context = $context;
6364
}
6465
}
66+
67+
/**
68+
* Use non-deprecated check method if availble
69+
*
70+
* @param KernelEvent $event
71+
*
72+
* @return bool
73+
*/
74+
private function isMainRequestEvent(KernelEvent $event): bool
75+
{
76+
if (\method_exists($event, 'isMainRequest')) {
77+
return $event->isMainRequest();
78+
}
79+
80+
return $event->isMasterRequest();
81+
}
6582
}

src/Debug/Extractor/CookieDebugExtractor.php

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
namespace Jaeger\Symfony\Debug\Extractor;
55

66
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
7+
use Symfony\Component\HttpKernel\Event\KernelEvent;
78
use Symfony\Component\HttpKernel\Event\RequestEvent;
89
use Symfony\Component\HttpKernel\Event\TerminateEvent;
910

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

2122
public function onRequest(RequestEvent $event): void
2223
{
23-
if (false === $event->isMasterRequest()) {
24+
if (false === $this->isMainRequestEvent($event)) {
2425
return;
2526
}
2627
$request = $event->getRequest();
@@ -32,7 +33,7 @@ public function onRequest(RequestEvent $event): void
3233

3334
public function onTerminate(TerminateEvent $event): void
3435
{
35-
if (false === $event->isMasterRequest()) {
36+
if (false === $this->isMainRequestEvent($event)) {
3637
return;
3738
}
3839
$this->debugId = '';
@@ -50,4 +51,20 @@ public static function getSubscribedEvents(): array
5051
TerminateEvent::class => ['onTerminate'],
5152
];
5253
}
54+
55+
/**
56+
* Use non-deprecated check method if availble
57+
*
58+
* @param KernelEvent $event
59+
*
60+
* @return bool
61+
*/
62+
private function isMainRequestEvent(KernelEvent $event): bool
63+
{
64+
if (\method_exists($event, 'isMainRequest')) {
65+
return $event->isMainRequest();
66+
}
67+
68+
return $event->isMasterRequest();
69+
}
5370
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace Jaeger\Symfony\DependencyInjection;
5+
6+
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
7+
use Symfony\Component\DependencyInjection\ContainerBuilder;
8+
use Symfony\Component\DependencyInjection\Dumper\Preloader;
9+
10+
class DeprecatedAliasesCompilerPass implements CompilerPassInterface
11+
{
12+
public function process(ContainerBuilder $container): void
13+
{
14+
$container->getAlias('jaeger.span.handler.gloabal')
15+
->setDeprecated(
16+
...
17+
$this->getDeprecationMsg(
18+
'The "%alias_id%" service is deprecated. Use "jaeger.span.handler.global".',
19+
'3.5.0'
20+
)
21+
);
22+
}
23+
24+
/**
25+
* Returns the correct deprecation param's as an array for setDeprecated.
26+
*
27+
* symfony/dependency-injection v5.1 introduces a deprecation notice when calling
28+
* setDeprecation() with less than 3 args and the
29+
* `Symfony\Component\DependencyInjection\Dumper\Preloader` class was
30+
* introduced at the same time. By checking if this class exists,
31+
* we can determine the correct param count to use when calling setDeprecated.
32+
*
33+
* @param string $message
34+
* @param string $version
35+
*
36+
* @return array
37+
*/
38+
private function getDeprecationMsg(string $message, string $version): array
39+
{
40+
if (class_exists(Preloader::class)) {
41+
return [
42+
'code-tool/jaeger-client-symfony-bridge',
43+
$version,
44+
$message,
45+
];
46+
}
47+
48+
return [$message];
49+
}
50+
}

src/JaegerBundle.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Jaeger\Symfony\DependencyInjection\CodecRegistryCompilerPass;
77
use Jaeger\Symfony\DependencyInjection\ContextExtractorChainCompilerPass;
88
use Jaeger\Symfony\DependencyInjection\DebugExtractorChainCompilerPass;
9+
use Jaeger\Symfony\DependencyInjection\DeprecatedAliasesCompilerPass;
910
use Jaeger\Symfony\DependencyInjection\NameGeneratorChainCompilerPass;
1011
use Symfony\Component\DependencyInjection\ContainerBuilder;
1112
use Symfony\Component\HttpKernel\Bundle\Bundle;
@@ -19,6 +20,7 @@ public function build(ContainerBuilder $container)
1920
->addCompilerPass(new CodecRegistryCompilerPass())
2021
->addCompilerPass(new ContextExtractorChainCompilerPass())
2122
->addCompilerPass(new DebugExtractorChainCompilerPass())
22-
->addCompilerPass(new NameGeneratorChainCompilerPass());
23+
->addCompilerPass(new NameGeneratorChainCompilerPass())
24+
->addCompilerPass(new DeprecatedAliasesCompilerPass());
2325
}
2426
}

src/Resources/services.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,6 @@ services:
139139
jaeger.span.handler.background:
140140
class: Jaeger\Symfony\Bridge\BackgroundSpanHandler
141141
arguments: ['@jaeger.tracer']
142-
jaeger.span.handler.gloabal:
143-
alias: jaeger.span.handler.global
144-
deprecated: 'The "%alias_id%" service is deprecated. Use "jaeger.span.handler.global".'
145142
jaeger.span.handler.global:
146143
class: Jaeger\Symfony\Bridge\GlobalSpanHandler
147144
arguments: ['@jaeger.tracer', '@jaeger.name.generator']
@@ -198,3 +195,7 @@ services:
198195
- '@jaeger.span.manager'
199196
tags:
200197
- {name: 'kernel.event_subscriber'}
198+
# deprecated since 3.5.0
199+
jaeger.span.handler.gloabal:
200+
alias: jaeger.span.handler.global
201+

0 commit comments

Comments
 (0)