Skip to content

Commit 4bbc15b

Browse files
authored
Merge pull request #16 from code-tool/name-generator
Name generator
2 parents 5cf21a4 + b90f1cd commit 4bbc15b

23 files changed

+366
-42
lines changed

README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,29 @@ jaeger:
3636
- 'healthcheck'
3737
- 'metrics'
3838
```
39+
40+
41+
## Name generation options
42+
43+
You can configure custom name generators based on regular expression pattern, which will be evaluated for operation name.
44+
45+
Configuration for this feature looks like key-value list, where key - regexp pattern, value - custom name generator DI service id (see details below).
46+
47+
Name generator should implement an `Jaeger\Symfony\Name\Generator\NameGeneratorInterface` interface.
48+
As a custom name generator you can specify a full DI service id, or just the suffix if your name generator service is named as `jaeger.name.generator.*`.
49+
Keys are considered body of the regular expression pattern, do not put any modifiers (e.g. `/i`, `/g`) or slashes; `route` of the request or `name` of the command should match to use alternative generator.
50+
Expressions are checked top to bottom, if no match is found, default generator will be used
51+
52+
Example bundle config with name generation feature:
53+
54+
```yaml
55+
# config/jaeger.yaml
56+
jaeger:
57+
name_generator:
58+
max_length: 32
59+
command:
60+
'^app:report:.+': 'my_service_generator_alias'
61+
.* : 'controller'
62+
request:
63+
'user_routes_\w+': 'my_service_generator_alias'
64+
```

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
}
88
},
99
"require": {
10-
"php": ">=7.1",
10+
"php": ">=7.4",
1111
"code-tool/jaeger-client-php": "^3.1",
1212
"symfony/config": "^4.3|^5.0",
1313
"symfony/console": "^4.3|^5.0",

src/Bridge/BackgroundSpanHandler.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
use Jaeger\Http\HttpMethodTag;
77
use Jaeger\Http\HttpUriTag;
8-
use Jaeger\Span\Span;
8+
use Jaeger\Span\SpanInterface;
99
use Jaeger\Symfony\Tag\SymfonyBackgroundTag;
1010
use Jaeger\Symfony\Tag\SymfonyComponentTag;
1111
use Jaeger\Symfony\Tag\SymfonyVersionTag;
@@ -15,12 +15,9 @@
1515

1616
class BackgroundSpanHandler
1717
{
18-
/**
19-
* @var Span
20-
*/
21-
private $span;
18+
private ?SpanInterface $span = null;
2219

23-
private $tracer;
20+
private TracerInterface $tracer;
2421

2522
public function __construct(TracerInterface $tracer)
2623
{
@@ -50,6 +47,7 @@ public function flush(): BackgroundSpanHandler
5047
return $this;
5148
}
5249
$this->span->finish();
50+
$this->span = null;
5351

5452
return $this;
5553
}

src/Bridge/GlobalSpanListener.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,29 +10,29 @@
1010

1111
class GlobalSpanListener implements EventSubscriberInterface
1212
{
13-
private $handler;
13+
private GlobalSpanHandler $handler;
1414

1515
public function __construct(GlobalSpanHandler $handler)
1616
{
1717
$this->handler = $handler;
1818
}
1919

20-
public static function getSubscribedEvents()
20+
public static function getSubscribedEvents(): array
2121
{
2222
return [
2323
RequestEvent::class => ['onRequest', 30],
2424
TerminateEvent::class => ['onTerminate', 4096],
2525
];
2626
}
2727

28-
public function onTerminate()
28+
public function onTerminate(): GlobalSpanListener
2929
{
3030
$this->handler->finish();
3131

3232
return $this;
3333
}
3434

35-
public function onRequest(RequestEvent $event)
35+
public function onRequest(RequestEvent $event): GlobalSpanListener
3636
{
3737
if (false === $this->isMainRequestEvent($event)) {
3838
return $this;

src/Bridge/HandlerFlushListener.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ public function __construct(BackgroundSpanHandler $backgroundHandler, GlobalSpan
1818
$this->globalHandler = $globalHandler;
1919
}
2020

21-
public static function getSubscribedEvents()
21+
public static function getSubscribedEvents(): array
2222
{
23-
return [TerminateEvent::class => ['onTerminate', -16384],];
23+
return [TerminateEvent::class => ['onTerminate', -16384]];
2424
}
2525

2626
public function onTerminate()

src/Context/Extractor/ContextExtractorChain.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@ public function extract(): ?SpanContext
2525
{
2626
$queue = clone $this->queue;
2727
while (false === $queue->isEmpty()) {
28-
if (null !== ($context = $queue->extract()->extract())) {
28+
/** @var ContextExtractorInterface $extractor */
29+
$extractor = $queue->extract();
30+
$context = $extractor->extract();
31+
if (null !== $context) {
2932
return $context;
3033
}
3134
}

src/Debug/Extractor/DebugExtractorChain.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@ public function getDebug(): string
2323
{
2424
$queue = clone $this->queue;
2525
while (false === $queue->isEmpty()) {
26-
if ('' !== ($debugId = $queue->extract()->getDebug())) {
26+
/** @var DebugExtractorInterface $extractor */
27+
$extractor = $queue->extract();
28+
$debugId = $extractor->getDebug();
29+
if ('' !== $debugId) {
2730
return $debugId;
2831
}
2932
}

src/DependencyInjection/CodecRegistryCompilerPass.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
class CodecRegistryCompilerPass implements CompilerPassInterface
1111
{
12-
public function process(ContainerBuilder $container)
12+
public function process(ContainerBuilder $container): void
1313
{
1414
if (false === $container->hasDefinition('jaeger.codec.registry')) {
1515
throw new \RuntimeException(

src/DependencyInjection/Configuration.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,20 @@ public function getConfigTreeBuilder(): TreeBuilder
2828
->end()
2929
->end()
3030
->end()
31+
->arrayNode('name_generator')
32+
->canBeEnabled()
33+
->children()
34+
->integerNode('max_length')->defaultValue(64)->end()
35+
->arrayNode('command')
36+
->useAttributeAsKey('pattern')
37+
->scalarPrototype()->end()
38+
->end()
39+
->arrayNode('request')
40+
->useAttributeAsKey('pattern')
41+
->scalarPrototype()->end()
42+
->end()
43+
->end()
44+
->end()
3145
->end();
3246
// @formatter:on
3347

src/DependencyInjection/ContextExtractorChainCompilerPass.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
class ContextExtractorChainCompilerPass implements CompilerPassInterface
1111
{
12-
public function process(ContainerBuilder $container)
12+
public function process(ContainerBuilder $container): void
1313
{
1414
if (false === $container->hasDefinition('jaeger.context.extractor.chain')) {
1515
throw new \RuntimeException(

0 commit comments

Comments
 (0)