Skip to content

Commit 7dcfc3d

Browse files
committed
fix: fall back to low cardinality
1 parent 58f4669 commit 7dcfc3d

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

src/Instrumentation/Laravel/src/Hooks/Illuminate/Contracts/Http/Kernel.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ protected function hookHandle(): bool
4444
/** @psalm-suppress ArgumentTypeCoercion */
4545
$builder = $this->instrumentation
4646
->tracer()
47-
->spanBuilder(sprintf('%s', $request?->method() ?? 'unknown'))
47+
->spanBuilder(sprintf('HTTP %s', $request?->method() ?? 'unknown'))
4848
->setSpanKind(SpanKind::KIND_SERVER)
4949
->setAttribute(TraceAttributes::CODE_FUNCTION_NAME, $function)
5050
->setAttribute(TraceAttributes::CODE_NAMESPACE, $class)
@@ -87,7 +87,12 @@ protected function hookHandle(): bool
8787
$route = $request?->route();
8888

8989
if ($request && $route instanceof Route) {
90-
$span->updateName("{$request->method()} /" . ltrim($route->uri, '/'));
90+
if (method_exists($route, 'getName') && $route->getName() && strpos($route->getName(), 'generated::') !== 0) {
91+
$span->updateName("{$request->method()} " . $route->getName());
92+
$span->setAttribute('laravel.route.name', $route->getName());
93+
} else {
94+
$span->updateName("HTTP {$request->method()}");
95+
}
9196
$span->setAttribute(TraceAttributes::HTTP_ROUTE, $route->uri);
9297
}
9398

src/Instrumentation/Laravel/src/Hooks/Illuminate/Routing/Router.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,20 @@ protected function hookPrepareResponse(): bool
7575
if (method_exists($route, 'getName') && $route->getName() && strpos($route->getName(), 'generated::') !== 0) {
7676
$span->updateName("{$request->method()} " . $route->getName());
7777
$span->setAttribute('laravel.route.name', $route->getName());
78-
} elseif (method_exists($route, 'uri')) {
78+
}
79+
80+
// Always set the HTTP route attribute from the URI pattern
81+
if (method_exists($route, 'uri')) {
7982
$path = $route->uri();
80-
$span->updateName("{$request->method()} /" . ltrim($path, '/'));
83+
if (!$route->getName() || strpos($route->getName(), 'generated::') === 0) {
84+
$span->updateName("HTTP {$request->method()}");
85+
}
8186
$span->setAttribute(TraceAttributes::HTTP_ROUTE, $path);
8287
} elseif (method_exists($route, 'getPath')) {
8388
$path = $route->getPath();
84-
$span->updateName("{$request->method()} /" . ltrim($path, '/'));
89+
if (!$route->getName() || strpos($route->getName(), 'generated::') === 0) {
90+
$span->updateName("HTTP{$request->method()}");
91+
}
8592
$span->setAttribute(TraceAttributes::HTTP_ROUTE, $path);
8693
}
8794

0 commit comments

Comments
 (0)