From cf610d5d60b68421e94522072078a691f4f7b4fd Mon Sep 17 00:00:00 2001 From: "erwin@splunk" <122808896+technimad-splunk@users.noreply.github.com> Date: Tue, 22 Oct 2024 21:53:51 +0200 Subject: [PATCH] [symfony] Fix: Set span status according to otel convention (#308) * Only set error status if we know the response code is 500 or higher. * fix linting error --- src/Instrumentation/Symfony/src/SymfonyInstrumentation.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Instrumentation/Symfony/src/SymfonyInstrumentation.php b/src/Instrumentation/Symfony/src/SymfonyInstrumentation.php index 7d511488..3b205355 100644 --- a/src/Instrumentation/Symfony/src/SymfonyInstrumentation.php +++ b/src/Instrumentation/Symfony/src/SymfonyInstrumentation.php @@ -104,7 +104,9 @@ public static function register(): void $span->recordException($exception, [ TraceAttributes::EXCEPTION_ESCAPED => true, ]); - $span->setStatus(StatusCode::STATUS_ERROR, $exception->getMessage()); + if (null !== $response && $response->getStatusCode() >= Response::HTTP_INTERNAL_SERVER_ERROR) { + $span->setStatus(StatusCode::STATUS_ERROR, $exception->getMessage()); + } } if (null === $response) { @@ -159,8 +161,7 @@ public static function register(): void Span::getCurrent() ->recordException($throwable, [ TraceAttributes::EXCEPTION_ESCAPED => true, - ]) - ->setStatus(StatusCode::STATUS_ERROR, $throwable->getMessage()); + ]); return $params; },