• 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

77.78
/src/DependencyInjection/Compiler/HttpClientInstrumentationPass.php
1
<?php
2

3
namespace FriendsOfOpenTelemetry\OpenTelemetryBundle\DependencyInjection\Compiler;
4

5
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
6
use Symfony\Component\DependencyInjection\ContainerBuilder;
7
use Symfony\Component\DependencyInjection\Reference;
8
use Symfony\Component\HttpClient\HttpClient;
9

10
class HttpClientInstrumentationPass implements CompilerPassInterface
11
{
12
    public function process(ContainerBuilder $container): void
13
    {
14
        if (false === $container->hasParameter('open_telemetry.instrumentation.http_client.tracing.enabled')
8✔
15
            || false === $container->getParameter('open_telemetry.instrumentation.http_client.tracing.enabled')) {
8✔
16
            $container->removeDefinition('open_telemetry.instrumentation.http_client.trace.client');
6✔
17

18
            return;
6✔
19
        }
20

21
        if (!class_exists(HttpClient::class)) {
2✔
NEW
22
            throw new \LogicException('Http client instrumentation cannot be enabled because the symfony/http-client package is not installed.');
×
23
        }
24

25
        $decoratedService = $this->getDecoratedService($container);
2✔
26
        if (null === $decoratedService) {
2✔
NEW
27
            $container->removeDefinition('open_telemetry.instrumentation.http_client.trace.client');
×
28

NEW
29
            return;
×
30
        }
31

32
        $container->getDefinition('open_telemetry.instrumentation.http_client.trace.client')
2✔
33
            ->setArgument('$client', new Reference('.inner'))
2✔
34
            ->setDecoratedService($decoratedService[0], null, $decoratedService[1]);
2✔
35
    }
36

37
    /**
38
     * @return array{string, int}|null
39
     */
40
    private function getDecoratedService(ContainerBuilder $container): ?array
41
    {
42
        if ($container->hasDefinition('http_client.transport')) {
2✔
43
            return ['http_client.transport', -15];
1✔
44
        }
45

46
        if ($container->hasDefinition('http_client')) {
1✔
47
            return ['http_client', 15];
1✔
48
        }
49

50
        return null;
×
51
    }
52
}
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