-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(DependencyInjection): move configurate in compiler passes
- Loading branch information
1 parent
24c7fc3
commit d8c7610
Showing
21 changed files
with
184 additions
and
161 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
src/DependencyInjection/Compiler/CacheInstrumentationPass.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
<?php | ||
|
||
namespace FriendsOfOpenTelemetry\OpenTelemetryBundle\DependencyInjection\Compiler; | ||
|
||
use Symfony\Component\DependencyInjection\ChildDefinition; | ||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
use Symfony\Component\DependencyInjection\Definition; | ||
use Symfony\Component\DependencyInjection\Reference; | ||
|
||
class CacheInstrumentationPass implements CompilerPassInterface | ||
{ | ||
public function process(ContainerBuilder $container): void | ||
{ | ||
if (false === $container->hasParameter('open_telemetry.instrumentation.cache.tracing.enabled') | ||
|| false === $container->getParameter('open_telemetry.instrumentation.cache.tracing.enabled')) { | ||
$container->removeDefinition('open_telemetry.instrumentation.cache.trace.tag_aware_adapter'); | ||
$container->removeDefinition('open_telemetry.instrumentation.cache.trace.adapter'); | ||
|
||
return; | ||
} | ||
|
||
foreach ($container->findTaggedServiceIds('cache.pool') as $serviceId => $tags) { | ||
$cachePoolDefinition = $container->getDefinition($serviceId); | ||
if ($cachePoolDefinition->isAbstract()) { | ||
continue; | ||
} | ||
|
||
$definitionClass = $this->resolveDefinitionClass($container, $cachePoolDefinition); | ||
if (null === $definitionClass) { | ||
continue; | ||
} | ||
|
||
$traceableCachePoolDefinition = new ChildDefinition('open_telemetry.instrumentation.cache.trace.adapter'); | ||
$traceableCachePoolDefinition | ||
->setDecoratedService($serviceId) | ||
->setArgument('$adapter', new Reference('.inner')); | ||
|
||
$container->setDefinition($serviceId.'.tracer', $traceableCachePoolDefinition); | ||
} | ||
|
||
foreach ($container->findTaggedServiceIds('cache.taggable') as $serviceId => $tags) { | ||
$cachePoolDefinition = $container->getDefinition($serviceId); | ||
if ($cachePoolDefinition->isAbstract()) { | ||
continue; | ||
} | ||
|
||
$definitionClass = $this->resolveDefinitionClass($container, $cachePoolDefinition); | ||
if (null === $definitionClass) { | ||
continue; | ||
} | ||
|
||
$traceableCachePoolDefinition = new ChildDefinition('open_telemetry.instrumentation.cache.trace.tag_aware_adapter'); | ||
$traceableCachePoolDefinition | ||
->setDecoratedService($serviceId) | ||
->setArgument('$adapter', new Reference('.inner')); | ||
|
||
$container->setDefinition($serviceId.'.tracer', $traceableCachePoolDefinition); | ||
} | ||
} | ||
|
||
private function resolveDefinitionClass(ContainerBuilder $container, Definition $definition): ?string | ||
{ | ||
$class = $definition->getClass(); | ||
|
||
while (null === $class && $definition instanceof ChildDefinition) { | ||
$definition = $container->findDefinition($definition->getParent()); | ||
$class = $definition->getClass(); | ||
} | ||
|
||
return $class; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.