diff --git a/modules/caddyhttp/tracing/module_test.go b/modules/caddyhttp/tracing/module_test.go index e0975a9ad..0e677334a 100644 --- a/modules/caddyhttp/tracing/module_test.go +++ b/modules/caddyhttp/tracing/module_test.go @@ -366,9 +366,10 @@ func TestTracing_OpenTelemetry_Span_Attributes(t *testing.T) { // Verify that the span attributes were set correctly with placeholder replacement expectedAttributes := map[string]string{ - "placeholder": "POST", - "static": "test-service", - "mixed": "prefix-POST-suffix", + "placeholder": "POST", + "static": "test-service", + "mixed": "prefix-POST-suffix", + "http.response.status_code": "200", // OTEL default } actualAttributes := make(map[string]string) diff --git a/modules/caddyhttp/tracing/tracer.go b/modules/caddyhttp/tracing/tracer.go index 8e4b1162f..d4b7c1d4c 100644 --- a/modules/caddyhttp/tracing/tracer.go +++ b/modules/caddyhttp/tracing/tracer.go @@ -104,6 +104,9 @@ func (ot *openTelemetryWrapper) serveHTTP(w http.ResponseWriter, r *http.Request } } + next := ctx.Value(nextCallCtxKey).(*nextCall) + next.err = next.next.ServeHTTP(w, r) + // Add custom span attributes to the current span span := trace.SpanFromContext(ctx) if span.IsRecording() && len(ot.spanAttributes) > 0 { @@ -116,9 +119,6 @@ func (ot *openTelemetryWrapper) serveHTTP(w http.ResponseWriter, r *http.Request } span.SetAttributes(attributes...) } - - next := ctx.Value(nextCallCtxKey).(*nextCall) - next.err = next.next.ServeHTTP(w, r) } // ServeHTTP propagates call to the by wrapped by `otelhttp` next handler.