Refactor span error recording into tracing helper and unify error-path instrumentation#6638
Conversation
|
@copilot resolve the merge conflicts in this pull request |
There was a problem hiding this comment.
Pull request overview
This PR centralizes OpenTelemetry span error instrumentation by introducing a helper that consistently records errors (with stack traces) and sets span status, then updates tool execution and HTTP tracing paths to use it.
Changes:
- Added
tracing.RecordSpanError(...)(and a multi-span variant) to unifyRecordError + SetStatusbehavior. - Refactored unified tool execution error paths to use the helper (including rate-limit paths across multiple spans).
- Updated HTTP 5xx span handling to use the helper and tightened tests to assert exception stack traces are present.
Show a summary per file
| File | Description |
|---|---|
| internal/tracing/span_helpers.go | Introduces helper(s) to record span errors with stack traces and set error status consistently. |
| internal/server/unified.go | Replaces duplicated error instrumentation across tool execution error paths with the new helper(s). |
| internal/tracing/http.go | Uses the helper to record 5xx responses as span errors (exception event + status). |
| internal/tracing/provider_test.go | Strengthens 5xx tracing assertions to require an exception event containing a stack trace attribute. |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 2/2 changed files
- Comments generated: 1
| if srw.StatusCode >= 500 { | ||
| span.SetStatus(codes.Error, http.StatusText(srw.StatusCode)) | ||
| msg := http.StatusText(srw.StatusCode) | ||
| RecordSpanError(span, errors.New(msg), msg) | ||
| } |
Resolved. This branch already contains the merge commit |
|
@copilot address review feedback |
Addressed in 541d061. Added a fallback for unknown/custom 5xx status text in |
This change addresses duplicated OpenTelemetry error instrumentation (
RecordError+SetStatus) across server/tool execution and HTTP tracing paths. It centralizes the pattern in one helper to keep behavior consistent and eliminate drift (including the rate-limit path that previously missed stack-trace recording).Centralize span error instrumentation
internal/tracing/span_helpers.gowith:RecordSpanError(span, err, msg)Replace duplicated call sites in unified tool flow
internal/server/unified.goto usetracing.RecordSpanError(...)for:execSpanandtoolSpanApply same helper in HTTP 5xx tracing
internal/tracing/http.goso 5xx response handling uses the same helper, aligning server-span behavior with tool-span behavior.Tighten behavior assertion for 5xx spans
internal/tracing/provider_test.goto assert 5xx spans include anexceptionevent withexception.stacktrace, ensuring helper-backed semantics are preserved.