Skip to content

Commit

Permalink
improve readability of traces
Browse files Browse the repository at this point in the history
  • Loading branch information
Iosif Ch committed Sep 4, 2023
1 parent c8e79a8 commit 50b3859
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public static function register(): void
/** @psalm-suppress ArgumentTypeCoercion */
$builder = $instrumentation
->tracer()
->spanBuilder(\sprintf('HTTP %s', $params[0]))
->spanBuilder(\sprintf('HTTP %s %s', $params[0], parse_url($params[1], PHP_URL_HOST)))
->setSpanKind(SpanKind::KIND_CLIENT)
->setAttribute(TraceAttributes::HTTP_URL, (string) $params[1])
->setAttribute(TraceAttributes::HTTP_METHOD, $params[0])
Expand Down
10 changes: 9 additions & 1 deletion src/Instrumentation/Symfony/src/SymfonyInstrumentation.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public static function register(): void
/** @psalm-suppress ArgumentTypeCoercion */
$builder = $instrumentation
->tracer()
->spanBuilder(\sprintf('HTTP %s', $request?->getMethod() ?? 'unknown'))
->spanBuilder(\sprintf('HTTP %s', $request?->getMethod() ?? 'unknown method'))
->setSpanKind(SpanKind::KIND_SERVER)
->setAttribute(TraceAttributes::CODE_FUNCTION, $function)
->setAttribute(TraceAttributes::CODE_NAMESPACE, $class)
Expand Down Expand Up @@ -79,6 +79,14 @@ public static function register(): void
$span = Span::fromContext($scope->context());

$request = ($params[0] instanceof Request) ? $params[0] : null;
if ($params[1] === HttpKernelInterface::MAIN_REQUEST) {
$span->updateName(\sprintf(
'HTTP %s %s',
$request?->getMethod() ?? 'unknown method',
$request?->attributes->get('_route', 'unknown route')
));
}

if (null !== $request) {
$routeName = $request->attributes->get('_route', '');

Expand Down

0 comments on commit 50b3859

Please sign in to comment.