Skip to content

Commit cc6db45

Browse files
committed
Added docs for the regexp, moved regexp generation to the configuration
1 parent 03f3324 commit cc6db45

File tree

4 files changed

+10
-8
lines changed

4 files changed

+10
-8
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ jaeger:
4141
## Name generation options
4242
4343
You can specify just the suffix, if you name generator service is named as `jaeger.name.generator.*` or if you have any other naming scheme you can put the whole name into the configuration.
44-
Keys are considered regular expressions that `route` of the request or `name` of the command should match to use alternative generator.
44+
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.
4545
Expressions are checked top to bottom, if no match is found, default generator will be used
4646

4747
Example bundle config with name generation feature:
@@ -52,7 +52,7 @@ jaeger:
5252
name_generator:
5353
max_length: 32
5454
command:
55-
'.*': 'controller'
55+
.* : 'controller'
5656
request:
5757
'brand_routes_\d+': 'my_service_generator_alias'
5858
```

src/DependencyInjection/JaegerExtension.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,30 +29,32 @@ public function load(array $configs, ContainerBuilder $container)
2929
if ($this->isConfigEnabled($container, $config['name_generator'])) {
3030
$container->setParameter('jaeger.name.max_length', (int)$config['name_generator']['max_length']);
3131
foreach ($config['name_generator']['request'] as $item => $customGeneratorId) {
32+
$regexp = \sprintf('/%s/', $item);
3233
$shortenedGeneratorId = \sprintf('jaeger.name.generator.%s', $customGeneratorId);
3334
if ($container->has($shortenedGeneratorId)) {
3435
$container->getDefinition('jaeger.name.generator.request')->addMethodCall(
3536
'add',
36-
[$item, new Reference($shortenedGeneratorId)]
37+
[$regexp, new Reference($shortenedGeneratorId)]
3738
);
3839
} else {
3940
$container->getDefinition('jaeger.name.generator.request')->addMethodCall(
4041
'add',
41-
[$item, new Reference($customGeneratorId)]
42+
[$regexp, new Reference($customGeneratorId)]
4243
);
4344
}
4445
}
4546
foreach ($config['name_generator']['command'] as $item => $customGeneratorId) {
47+
$regexp = \sprintf('/%s/', $item);
4648
$shortenedGeneratorId = \sprintf('jaeger.name.generator.%s', $customGeneratorId);
4749
if ($container->has($shortenedGeneratorId)) {
4850
$container->getDefinition('jaeger.name.generator.command')->addMethodCall(
4951
'add',
50-
[$item, new Reference($shortenedGeneratorId)]
52+
[$regexp, new Reference($shortenedGeneratorId)]
5153
);
5254
} else {
5355
$container->getDefinition('jaeger.name.generator.command')->addMethodCall(
5456
'add',
55-
[$item, new Reference($customGeneratorId)]
57+
[$regexp, new Reference($customGeneratorId)]
5658
);
5759
}
5860
}

src/Name/Generator/CommandNameGenerator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public function __construct(array $generators = [])
2020

2121
public function add(string $regexp, NameGeneratorInterface $generator): CommandNameGenerator
2222
{
23-
$this->generators[sprintf('/%s/', $regexp)] = $generator;
23+
$this->generators[$regexp] = $generator;
2424

2525
return $this;
2626
}

src/Name/Generator/RequestNameGenerator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public function __construct(array $generators = [])
2020

2121
public function add(string $regexp, NameGeneratorInterface $generator): RequestNameGenerator
2222
{
23-
$this->generators[sprintf('/%s/', $regexp)] = $generator;
23+
$this->generators[$regexp] = $generator;
2424

2525
return $this;
2626
}

0 commit comments

Comments
 (0)