Skip to content

Commit

Permalink
add url path in name
Browse files Browse the repository at this point in the history
  • Loading branch information
dkudrin committed May 15, 2024
1 parent b0a15d6 commit c5ccf03
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/HttpInstrumentation.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,11 @@ public static function register(CachedInstrumentation $instrumentation): void
Application::class,
'run',
pre: static function (Application $app, array $params, string $class, string $function, ?string $filename, ?int $lineno) use ($instrumentation, $request) {
$parsedUrl = collect(parse_url($request->url()));
$method = $request?->method();
/** @psalm-suppress ArgumentTypeCoercion */
$builder = $instrumentation->tracer()
->spanBuilder(sprintf('%s', $request?->method() ?? 'unknown'))
->spanBuilder($method ? $request?->method() . ' ' . $parsedUrl['path'] : '')
->setSpanKind(SpanKind::KIND_SERVER)
->setAttribute(TraceAttributes::CODE_FUNCTION, $function)
->setAttribute(TraceAttributes::CODE_NAMESPACE, $class)
Expand Down Expand Up @@ -73,6 +75,8 @@ public static function register(CachedInstrumentation $instrumentation): void
}
$scope->detach();
$span = Span::fromContext($scope->context());
$span->setAttribute('trace_id', $span->getContext()->getTraceId());

if ($exception) {
$span->recordException($exception, [TraceAttributes::EXCEPTION_ESCAPED => true]);
$span->setStatus(StatusCode::STATUS_ERROR, $exception->getMessage());
Expand Down
2 changes: 1 addition & 1 deletion src/Watchers/ClientRequestWatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function recordRequest(RequestSending $request): void
if ($parsedUrl->has('query')) {
$processedUrl .= '?' . $parsedUrl->get('query');
}
$span = $this->instrumentation->tracer()->spanBuilder($request->request->method())
$span = $this->instrumentation->tracer()->spanBuilder($request->request->method() . ' ' . ($parsedUrl['host'] . $parsedUrl['path'] ?? ''))
->setSpanKind(SpanKind::KIND_CLIENT)
->setAttributes([
TraceAttributes::HTTP_REQUEST_METHOD => $request->request->method(),
Expand Down

0 comments on commit c5ccf03

Please sign in to comment.