Skip to content

Commit

Permalink
add status change when response status code is in the technical error…
Browse files Browse the repository at this point in the history
… range

Signed-off-by: Vincent Free <[email protected]>
  • Loading branch information
vincentfree committed Aug 19, 2024
1 parent 3d8333f commit 265dee4
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion otelmiddleware/tracing.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package otelmiddleware

import (
"go.opentelemetry.io/otel/codes"
"net/http"

"go.opentelemetry.io/otel"
Expand Down Expand Up @@ -110,7 +111,11 @@ func TraceWithOptions(opt ...TraceOption) func(next http.Handler) http.Handler {
next.ServeHTTP(wrapperRes, r)
// add the response status code to the span
if span.IsRecording() {
span.SetAttributes(semconv.HTTPAttributesFromHTTPStatusCode(wrapperRes.Status())...)
statusCode := wrapperRes.Status()
span.SetAttributes(semconv.HTTPAttributesFromHTTPStatusCode(statusCode)...)
if statusCode >= 500 {
span.SetStatus(codes.Error, http.StatusText(statusCode))
}
}
}

Expand Down

0 comments on commit 265dee4

Please sign in to comment.