Skip to content

Commit b90f1cd

Browse files
authored
Merge pull request #17 from andrew-demb/name-generator-suggestion
Name generator suggestions
2 parents 2b81358 + 9dddbbf commit b90f1cd

16 files changed

+62
-40
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ You can configure custom name generators based on regular expression pattern, wh
4444
4545
Configuration for this feature looks like key-value list, where key - regexp pattern, value - custom name generator DI service id (see details below).
4646
47-
Name generator should implement an 'TODO' interface.
47+
Name generator should implement an `Jaeger\Symfony\Name\Generator\NameGeneratorInterface` interface.
4848
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.*`.
4949
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.
5050
Expressions are checked top to bottom, if no match is found, default generator will be used

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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@ public function getConfigTreeBuilder(): TreeBuilder
3333
->children()
3434
->integerNode('max_length')->defaultValue(64)->end()
3535
->arrayNode('command')
36-
->useAttributeAsKey('name')
36+
->useAttributeAsKey('pattern')
3737
->scalarPrototype()->end()
3838
->end()
3939
->arrayNode('request')
40-
->useAttributeAsKey('name')
40+
->useAttributeAsKey('pattern')
4141
->scalarPrototype()->end()
4242
->end()
4343
->end()

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(

src/DependencyInjection/DebugExtractorChainCompilerPass.php

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

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

src/DependencyInjection/JaegerExtension.php

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,14 @@
1111

1212
class JaegerExtension extends Extension
1313
{
14-
public function load(array $configs, ContainerBuilder $container)
14+
public function load(array $configs, ContainerBuilder $container): void
1515
{
1616
$loader = new YamlFileLoader(
1717
$container,
1818
new FileLocator(__DIR__ . '/../Resources')
1919
);
2020
$loader->load('services.yml');
21+
2122
$configuration = new Configuration();
2223
$config = $this->processConfiguration($configuration, $configs);
2324

@@ -31,35 +32,35 @@ public function load(array $configs, ContainerBuilder $container)
3132
$loader->load('shorten.yml');
3233
$container->setParameter('jaeger.name.max_length', $config['name_generator']['max_length']);
3334
}
34-
foreach ($config['name_generator']['request'] as $item => $customGeneratorId) {
35-
$regexp = \sprintf('/%s/', $item);
35+
36+
foreach ($config['name_generator']['request'] as $pattern => $customGeneratorId) {
37+
$regexp = \sprintf('/%s/', $pattern);
38+
3639
$shortenedGeneratorId = \sprintf('jaeger.name.generator.%s', $customGeneratorId);
3740
if ($container->has($shortenedGeneratorId)) {
38-
$container->getDefinition('jaeger.name.generator.request')->addMethodCall(
39-
'add',
40-
[$regexp, new Reference($shortenedGeneratorId)]
41-
);
42-
} else {
43-
$container->getDefinition('jaeger.name.generator.request')->addMethodCall(
41+
$customGeneratorId = $shortenedGeneratorId;
42+
}
43+
44+
$container->getDefinition('jaeger.name.generator.request')
45+
->addMethodCall(
4446
'add',
4547
[$regexp, new Reference($customGeneratorId)]
4648
);
47-
}
4849
}
50+
4951
foreach ($config['name_generator']['command'] as $pattern => $customGeneratorId) {
50-
$regexp = \sprintf('/%s/', $item);
52+
$regexp = \sprintf('/%s/', $pattern);
53+
5154
$shortenedGeneratorId = \sprintf('jaeger.name.generator.%s', $customGeneratorId);
5255
if ($container->has($shortenedGeneratorId)) {
53-
$container->getDefinition('jaeger.name.generator.command')->addMethodCall(
54-
'add',
55-
[$regexp, new Reference($shortenedGeneratorId)]
56-
);
57-
} else {
58-
$container->getDefinition('jaeger.name.generator.command')->addMethodCall(
56+
$customGeneratorId = $shortenedGeneratorId;
57+
}
58+
59+
$container->getDefinition('jaeger.name.generator.command')
60+
->addMethodCall(
5961
'add',
6062
[$regexp, new Reference($customGeneratorId)]
6163
);
62-
}
6364
}
6465
}
6566
}

src/DependencyInjection/NameGeneratorChainCompilerPass.php

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

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

0 commit comments

Comments
 (0)