Skip to content

Commit

Permalink
[Symfony] Fix: Set span status according to otel convention (#295)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
technimad-splunk authored Oct 1, 2024
1 parent e2ba8fa commit 6123ef4
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/Instrumentation/Symfony/src/SymfonyInstrumentation.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down

0 comments on commit 6123ef4

Please sign in to comment.