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

FriendsOfOpenTelemetry / opentelemetry-bundle / 24231063947

10 Apr 2026 07:07AM UTC coverage: 91.667%. Remained the same
24231063947

Pull #161

github

web-flow
Merge 03b00bd55 into c74bf59c9
Pull Request #161: Update flake.lock

2255 of 2460 relevant lines covered (91.67%)

59.17 hits per line

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

82.35
/src/Instrumentation/Symfony/Framework/Routing/TraceableRouteLoader.php
1
<?php
2

3
namespace FriendsOfOpenTelemetry\OpenTelemetryBundle\Instrumentation\Symfony\Framework\Routing;
4

5
use FriendsOfOpenTelemetry\OpenTelemetryBundle\Instrumentation\Attribute\Traceable;
6
use Symfony\Component\Config\Loader\LoaderInterface;
7
use Symfony\Component\Config\Loader\LoaderResolverInterface;
8
use Symfony\Component\Routing\Route;
9
use Symfony\Component\Routing\RouteCollection;
10

11
class TraceableRouteLoader implements LoaderInterface
12
{
13
    public const DEFAULT_KEY = '_traceable';
14
    public const TRACER_KEY = '_tracer';
15
    public const OPTION_KEY = 'traceable';
16

17
    public function __construct(private LoaderInterface $loader)
18
    {
19
    }
32✔
20

21
    public function load(mixed $resource, ?string $type = null): RouteCollection
22
    {
23
        $routes = $this->loader->load($resource, $type);
32✔
24

25
        /** @var Route $route */
26
        foreach ($routes as $route) {
32✔
27
            self::parseAttribute($route);
32✔
28

29
            $traceable = $route->getOption(self::OPTION_KEY);
32✔
30
            if (null !== $traceable) {
32✔
31
                $route->addDefaults([
28✔
32
                    self::DEFAULT_KEY => $traceable,
28✔
33
                    self::TRACER_KEY => $route->getOption(self::TRACER_KEY),
28✔
34
                ]);
28✔
35
            }
36
        }
37

38
        return $routes;
32✔
39
    }
40

41
    public function supports(mixed $resource, ?string $type = null): bool
42
    {
43
        return $this->loader->supports($resource, $type);
×
44
    }
45

46
    public function getResolver(): LoaderResolverInterface
47
    {
48
        return $this->loader->getResolver();
×
49
    }
50

51
    public function setResolver(LoaderResolverInterface $resolver): void
52
    {
53
        $this->loader->setResolver($resolver);
×
54
    }
55

56
    private static function parseAttribute(Route $route): void
57
    {
58
        try {
59
            $controller = $route->getDefault('_controller');
32✔
60
            if (is_array($controller) && 2 === count($controller)) {
32✔
61
                $reflection = self::createReflectionMethod(sprintf('%s::%s', $controller[0], $controller[1]));
16✔
62
            } elseif (true === str_contains($controller, '::')) {
32✔
63
                $reflection = self::createReflectionMethod($controller);
24✔
64
            } else {
65
                $reflection = new \ReflectionClass($controller);
32✔
66
            }
67
        } catch (\ReflectionException) {
×
68
            return;
×
69
        }
70

71
        if ($reflection instanceof \ReflectionMethod) {
32✔
72
            $attribute = $reflection->getAttributes(Traceable::class)[0] ?? $reflection->getDeclaringClass()->getAttributes(Traceable::class)[0] ?? null;
24✔
73
        } else {
74
            $attribute = $reflection->getAttributes(Traceable::class)[0] ?? null;
24✔
75
        }
76

77
        if (null !== $attribute) {
32✔
78
            $traceable = $attribute->newInstance();
28✔
79
            $route->addOptions([
28✔
80
                self::OPTION_KEY => true,
28✔
81
                self::TRACER_KEY => $traceable->tracer ?? null,
28✔
82
            ]);
28✔
83
        }
84
    }
85

86
    private static function createReflectionMethod(string $method): \ReflectionMethod
87
    {
88
        if (\PHP_VERSION_ID >= 80400) {
24✔
89
            return \ReflectionMethod::createFromMethodName($method);
24✔
90
        }
91

92
        return new \ReflectionMethod($method);
×
93
    }
94
}
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