• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

FriendsOfOpenTelemetry / opentelemetry-bundle / 12750969892

13 Jan 2025 03:51PM UTC coverage: 88.441% (-0.4%) from 88.791%
12750969892

push

github

web-flow
refactor(DependencyInjection): move configurate in compiler passes (#107)

* refactor(DependencyInjection): move tag configuration in compiler passes

* feat(DependencyInjection): do not instrument services if packages are missing

75 of 98 new or added lines in 11 files covered. (76.53%)

2020 of 2284 relevant lines covered (88.44%)

6.88 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

55.56
/src/DependencyInjection/Compiler/CacheInstrumentationPass.php
1
<?php
2

3
namespace FriendsOfOpenTelemetry\OpenTelemetryBundle\DependencyInjection\Compiler;
4

5
use Symfony\Component\Cache\CacheItem;
6
use Symfony\Component\DependencyInjection\ChildDefinition;
7
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
8
use Symfony\Component\DependencyInjection\ContainerBuilder;
9
use Symfony\Component\DependencyInjection\Definition;
10
use Symfony\Component\DependencyInjection\Reference;
11

12
class CacheInstrumentationPass implements CompilerPassInterface
13
{
14
    public function process(ContainerBuilder $container): void
15
    {
16
        if (false === $container->hasParameter('open_telemetry.instrumentation.cache.tracing.enabled')
7✔
17
            || false === $container->getParameter('open_telemetry.instrumentation.cache.tracing.enabled')) {
7✔
18
            $container->removeDefinition('open_telemetry.instrumentation.cache.trace.tag_aware_adapter');
6✔
19
            $container->removeDefinition('open_telemetry.instrumentation.cache.trace.adapter');
6✔
20

21
            return;
6✔
22
        }
23

24
        if (!class_exists(CacheItem::class)) {
1✔
NEW
25
            throw new \LogicException('Cache instrumentation cannot be enabled because the symfony/cache package is not installed.');
×
26
        }
27

28
        foreach ($container->findTaggedServiceIds('cache.pool') as $serviceId => $tags) {
1✔
29
            $cachePoolDefinition = $container->getDefinition($serviceId);
1✔
30
            if ($cachePoolDefinition->isAbstract()) {
1✔
NEW
31
                continue;
×
32
            }
33

34
            $definitionClass = $this->resolveDefinitionClass($container, $cachePoolDefinition);
1✔
35
            if (null === $definitionClass) {
1✔
NEW
36
                continue;
×
37
            }
38

39
            $traceableCachePoolDefinition = new ChildDefinition('open_telemetry.instrumentation.cache.trace.adapter');
1✔
40
            $traceableCachePoolDefinition
1✔
41
                ->setDecoratedService($serviceId)
1✔
42
                ->setArgument('$adapter', new Reference('.inner'));
1✔
43

44
            $container->setDefinition($serviceId.'.tracer', $traceableCachePoolDefinition);
1✔
45
        }
46

47
        foreach ($container->findTaggedServiceIds('cache.taggable') as $serviceId => $tags) {
1✔
NEW
48
            $cachePoolDefinition = $container->getDefinition($serviceId);
×
NEW
49
            if ($cachePoolDefinition->isAbstract()) {
×
NEW
50
                continue;
×
51
            }
52

NEW
53
            $definitionClass = $this->resolveDefinitionClass($container, $cachePoolDefinition);
×
NEW
54
            if (null === $definitionClass) {
×
NEW
55
                continue;
×
56
            }
57

NEW
58
            $traceableCachePoolDefinition = new ChildDefinition('open_telemetry.instrumentation.cache.trace.tag_aware_adapter');
×
NEW
59
            $traceableCachePoolDefinition
×
NEW
60
                ->setDecoratedService($serviceId)
×
NEW
61
                ->setArgument('$adapter', new Reference('.inner'));
×
62

NEW
63
            $container->setDefinition($serviceId.'.tracer', $traceableCachePoolDefinition);
×
64
        }
65
    }
66

67
    private function resolveDefinitionClass(ContainerBuilder $container, Definition $definition): ?string
68
    {
69
        $class = $definition->getClass();
1✔
70

71
        while (null === $class && $definition instanceof ChildDefinition) {
1✔
NEW
72
            $definition = $container->findDefinition($definition->getParent());
×
NEW
73
            $class = $definition->getClass();
×
74
        }
75

76
        return $class;
1✔
77
    }
78
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc