From 5526599c12b73a5f9b8546742f9c88650477fd2b Mon Sep 17 00:00:00 2001 From: erwin vrolijk Date: Fri, 18 Oct 2024 13:16:45 +0200 Subject: [PATCH 1/2] Only set error status if we know the response code is 500 or higher. --- 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..bb4c3413 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; }, From c3ecfb85b5638d4762d78a8c38bfd0238fecb247 Mon Sep 17 00:00:00 2001 From: erwin vrolijk Date: Tue, 22 Oct 2024 17:27:52 +0200 Subject: [PATCH 2/2] fix linting error --- 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 bb4c3413..3b205355 100644 --- a/src/Instrumentation/Symfony/src/SymfonyInstrumentation.php +++ b/src/Instrumentation/Symfony/src/SymfonyInstrumentation.php @@ -104,7 +104,7 @@ public static function register(): void $span->recordException($exception, [ TraceAttributes::EXCEPTION_ESCAPED => true, ]); - if(null !== $response && $response->getStatusCode() >= Response::HTTP_INTERNAL_SERVER_ERROR) { + if (null !== $response && $response->getStatusCode() >= Response::HTTP_INTERNAL_SERVER_ERROR) { $span->setStatus(StatusCode::STATUS_ERROR, $exception->getMessage()); } }