You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat(tracing): HTTP response status on spans, sanitize error recording, bump semconv to v1.27.0 (#4879)
Three OTel best-practice gaps identified in the Go Fan module review:
`WrapHTTPHandler` never recorded the HTTP response status code,
`SetStatus` and `RecordError` were leaking raw error strings to trace
backends, and all files were pinned to semconv `v1.26.0` despite
`v1.27.0` being available.
## Changes
- **`tracing/http.go` — capture HTTP response status on spans**
- Added `statusResponseWriter` wrapper intercepting `WriteHeader` and
`Write` (handles implicit 200 when only `Write` is called)
- Added `Unwrap() http.ResponseWriter` to preserve optional interfaces
(`http.Flusher`, `http.Hijacker`, etc.) so streaming/SSE handlers are
not broken
- Sets `http.response.status_code` attribute and `codes.Error` span
status for 5xx via `defer`, ensuring attributes are recorded even if the
handler panics
- **`server/unified.go` — sanitize error recording**
- `execSpan.SetStatus(codes.Error, err.Error())` →
`execSpan.SetStatus(codes.Error, "tool execution failed")`
- `execSpan.RecordError(err)` → `execSpan.RecordError(fmt.Errorf("tool
execution failed"))` — prevents raw upstream error text from appearing
as `exception.message` in trace backends; the full error is still
returned to the caller via `mcp.NewErrorCallToolResult(err)`
- **semconv `v1.26.0` → `v1.27.0`** across all four affected files
(`tracing/http.go`, `tracing/provider.go`, `server/unified.go`,
`proxy/handler.go`); no go.mod/go.sum changes required as semconv is a
sub-package of the already-imported `go.opentelemetry.io/otel v1.43.0`
- **Tests** — added three new test cases to
`internal/tracing/provider_test.go` covering the HTTP status recording
behaviour:
- Explicit `WriteHeader(404)` is reflected in the span attribute; 4xx
does not set `codes.Error`
- Implicit 200 via `Write` without `WriteHeader` is correctly recorded
- 5xx sets span status to `codes.Error` with a non-empty description
0 commit comments