Skip to content

Commit b70b21a

Browse files
authored
fix(copilot): surface error cause chain in sim-to-go span status (#5473)
markSpanForError only recorded the top-level exception message, so a fetch() failure showed up as the generic "TypeError: fetch failed" with no indication of the real cause (ENOTFOUND, ECONNREFUSED, etc). Use describeError to walk the cause chain and set it as the span status message and an error.code attribute.
1 parent e5b9432 commit b70b21a

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

  • apps/sim/lib/copilot/request

apps/sim/lib/copilot/request/otel.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
TraceFlags,
1111
trace,
1212
} from '@opentelemetry/api'
13-
import { toError } from '@sim/utils/errors'
13+
import { describeError, toError } from '@sim/utils/errors'
1414
import { RequestTraceV1Outcome } from '@/lib/copilot/generated/request-trace-v1'
1515
import {
1616
CopilotBranchKind,
@@ -95,10 +95,14 @@ export function isActionableErrorStatus(code: number): boolean {
9595
export function markSpanForError(span: Span, error: unknown): void {
9696
const asError = toError(error)
9797
span.recordException(asError)
98+
const described = describeError(error)
99+
if (described.code) {
100+
span.setAttribute(TraceAttr.ErrorCode, described.code)
101+
}
98102
if (!isExplicitUserStopError(error)) {
99103
span.setStatus({
100104
code: SpanStatusCode.ERROR,
101-
message: asError.message,
105+
message: described.causeChain ? described.causeChain.join(' <- ') : asError.message,
102106
})
103107
}
104108
}

0 commit comments

Comments
 (0)