Skip to content

Commit 94f85a0

Browse files
authored
fix(Instrumentation/Routing): handle array controller for reflection on attribute parsing (#182)
* fix(Instrumentation/Routing): handle array controller for reflection on attribute parsing * chore: format
1 parent b438205 commit 94f85a0

4 files changed

Lines changed: 52 additions & 1 deletion

File tree

src/Instrumentation/Symfony/Framework/Routing/TraceableRouteLoader.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@ private static function parseAttribute(Route $route): void
5757
{
5858
try {
5959
$controller = $route->getDefault('_controller');
60-
if (true === str_contains($controller, '::')) {
60+
if (is_array($controller) && 2 === count($controller)) {
61+
$reflection = new \ReflectionMethod(sprintf('%s::%s', $controller[0], $controller[1]));
62+
} elseif (true === str_contains($controller, '::')) {
6163
$reflection = new \ReflectionMethod($controller);
6264
} else {
6365
$reflection = new \ReflectionClass($controller);
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
use App\Controller\Traceable\ActionTraceableController;
4+
use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator;
5+
6+
return static function (RoutingConfigurator $routingConfigurator): void {
7+
$routingConfigurator->add('php-config', '/php-config')
8+
->controller([ActionTraceableController::class, 'phpConfig'])
9+
->methods(['GET']);
10+
};

tests/Functional/Application/src/Controller/Traceable/ActionTraceableController.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,4 +120,12 @@ public function logSpanContext(LoggerInterface $logger): Response
120120
'status' => 'ok',
121121
]);
122122
}
123+
124+
#[Traceable]
125+
public function phpConfig(): Response
126+
{
127+
return $this->json([
128+
'status' => 'ok',
129+
]);
130+
}
123131
}

tests/Functional/Instrumentation/HttpKernel/HttpKernelAttributeTracingTest.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,4 +459,35 @@ public function testLogWithSpanContext(): void
459459

460460
self::assertLogHasSpanContext($log, $mainSpan);
461461
}
462+
463+
public function testPhpConfig(): void
464+
{
465+
$client = static::createClient();
466+
$client->request('GET', '/php-config');
467+
468+
static::assertResponseIsSuccessful();
469+
static::assertSame('{"status":"ok"}', $client->getResponse()->getContent());
470+
471+
self::assertSpansCount(1);
472+
473+
$mainSpan = self::getSpans()[0];
474+
self::assertSpanName($mainSpan, 'php-config');
475+
self::assertSpanStatus($mainSpan, StatusData::ok());
476+
self::assertSpanAttributes($mainSpan, [
477+
'url.full' => 'http://localhost/php-config',
478+
'http.request.method' => 'GET',
479+
'url.path' => '/php-config',
480+
'symfony.kernel.http.host' => 'localhost',
481+
'url.scheme' => 'http',
482+
'network.protocol.version' => '1.1',
483+
'user_agent.original' => 'Symfony BrowserKit',
484+
'network.peer.address' => '127.0.0.1',
485+
'symfony.kernel.net.peer_ip' => '127.0.0.1',
486+
'server.address' => 'localhost',
487+
'server.port' => 80,
488+
'http.route' => 'php-config',
489+
'http.response.status_code' => Response::HTTP_OK,
490+
]);
491+
self::assertSpanEventsCount($mainSpan, 0);
492+
}
462493
}

0 commit comments

Comments
 (0)