[Repo Assist] refactor: extract RecordSpanError helper to eliminate duplicate span error recording#6632
Merged
lpcox merged 1 commit intoMay 28, 2026
Conversation
…error recording The pattern of calling span.RecordError(err, oteltrace.WithStackTrace(true)) immediately followed by span.SetStatus(codes.Error, msg) was repeated 5 times in internal/server/unified.go and once more in internal/tracing/http.go. This commit introduces two helpers in internal/tracing/span_helpers.go: - RecordSpanError: single-span error recording with stack trace + status - RecordSpanErrorOnAll: same, applied to multiple spans at once All 5 duplicate occurrences in unified.go are replaced with RecordSpanError, and the 4-line dual-span rate-limit block is collapsed into one RecordSpanErrorOnAll call. This also fixes a latent inconsistency: the two RecordError calls at the rate-limit site were missing WithStackTrace(true), unlike all other error paths. The new helper always enables stack traces. Closes #6616 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR centralizes OpenTelemetry span error recording for backend tool-call paths, reducing duplicated RecordError + SetStatus logic and making stack-trace recording consistent.
Changes:
- Adds
tracing.RecordSpanErrorandtracing.RecordSpanErrorOnAll. - Replaces duplicated span error-recording blocks in
internal/server/unified.go. - Removes the now-unused
codesimport fromunified.go.
Show a summary per file
| File | Description |
|---|---|
internal/tracing/span_helpers.go |
Adds shared helpers for recording span errors with stack traces and error status. |
internal/server/unified.go |
Uses the new tracing helpers across tool denial, DIFC denial, circuit breaker, execution failure, and rate-limit paths. |
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: 0
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🤖 This is an automated pull request from Repo Assist, an AI assistant.
Summary
Addresses the duplicate code pattern identified in #6616. The pattern:
was repeated 5 times in
internal/server/unified.go. Additionally, the dual-span rate-limit block used 4 separate lines acrossexecSpanandtoolSpan.Changes
New file:
internal/tracing/span_helpers.goRecordSpanError(span, err, msg)— records an error on a span with stack trace and sets status to ErrorRecordSpanErrorOnAll(err, msg, spans...)— same, applied to multiple spans at onceUpdated:
internal/server/unified.gotracing.RecordSpanErrortracing.RecordSpanErrorOnAllcallgo.opentelemetry.io/otel/codesimportBug fix included
The two
RecordErrorcalls at the rate-limit path (lines 525–526) were missingWithStackTrace(true)— an inconsistency noted in #6616. The new helper always enables stack traces, making all error paths consistent.Trade-offs
RecordSpanErrorOnAlluses a variadic span slice, keeping the common single-span case cleanTest Status
proxy.golang.orgis firewalled), somake agent-finishedcould not be run. The changes are a straightforward mechanical extraction — no logic change, only removing thecodesimport (verified it's unused after the refactor) and adding a new file with two small helpers.Closes #6616
Warning
Firewall blocked 1 domain
The following domain was blocked by the firewall during workflow execution:
proxy.golang.orgSee Network Configuration for more information.
Add this agentic workflows to your repo
To install this agentic workflow, run