Skip to content

Commit cf610d5

Browse files
[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
1 parent 78a04ce commit cf610d5

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/Instrumentation/Symfony/src/SymfonyInstrumentation.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,9 @@ public static function register(): void
104104
$span->recordException($exception, [
105105
TraceAttributes::EXCEPTION_ESCAPED => true,
106106
]);
107-
$span->setStatus(StatusCode::STATUS_ERROR, $exception->getMessage());
107+
if (null !== $response && $response->getStatusCode() >= Response::HTTP_INTERNAL_SERVER_ERROR) {
108+
$span->setStatus(StatusCode::STATUS_ERROR, $exception->getMessage());
109+
}
108110
}
109111

110112
if (null === $response) {
@@ -159,8 +161,7 @@ public static function register(): void
159161
Span::getCurrent()
160162
->recordException($throwable, [
161163
TraceAttributes::EXCEPTION_ESCAPED => true,
162-
])
163-
->setStatus(StatusCode::STATUS_ERROR, $throwable->getMessage());
164+
]);
164165

165166
return $params;
166167
},

0 commit comments

Comments
 (0)