From 6123ef4a2e63c06c7752cedff8031696fbf40502 Mon Sep 17 00:00:00 2001 From: Erwin Vrolijk <122808896+technimad-splunk@users.noreply.github.com> Date: Wed, 2 Oct 2024 01:43:33 +0200 Subject: [PATCH] [Symfony] Fix: Set span status according to otel convention (#295) * Set span status according to otel convention The span status was always set to error for responses with status code 400 and up. According to the otel semantic conventions, for 4xx status, the span status MUST be left unset for spans with SpanKind.SERVER This commit adds the logic to implement this behaviour. Ref: https://opentelemetry.io/docs/specs/semconv/http/http-spans/#status * Do not set error status on internal spans with status 4xx Internal spans could have an error status, while the accompanying server span didn't have an error status. This changes this behaviour to ONLY set error status on requests with status code >= 500 regardless of the span kind. --- src/Instrumentation/Symfony/src/SymfonyInstrumentation.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Instrumentation/Symfony/src/SymfonyInstrumentation.php b/src/Instrumentation/Symfony/src/SymfonyInstrumentation.php index 0c05a9b3..7d511488 100644 --- a/src/Instrumentation/Symfony/src/SymfonyInstrumentation.php +++ b/src/Instrumentation/Symfony/src/SymfonyInstrumentation.php @@ -113,7 +113,7 @@ public static function register(): void return; } - if ($response->getStatusCode() >= Response::HTTP_BAD_REQUEST) { + if ($response->getStatusCode() >= Response::HTTP_INTERNAL_SERVER_ERROR) { $span->setStatus(StatusCode::STATUS_ERROR); } $span->setAttribute(TraceAttributes::HTTP_RESPONSE_STATUS_CODE, $response->getStatusCode());