From b95c3163a624d9040f55c0f4572dab90a3c72231 Mon Sep 17 00:00:00 2001 From: waleed Date: Tue, 7 Jul 2026 08:16:47 -0700 Subject: [PATCH] fix(copilot): surface error cause chain in sim-to-go span status 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. --- apps/sim/lib/copilot/request/otel.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/apps/sim/lib/copilot/request/otel.ts b/apps/sim/lib/copilot/request/otel.ts index 5ceb78c8a73..e93f9f53d5a 100644 --- a/apps/sim/lib/copilot/request/otel.ts +++ b/apps/sim/lib/copilot/request/otel.ts @@ -10,7 +10,7 @@ import { TraceFlags, trace, } from '@opentelemetry/api' -import { toError } from '@sim/utils/errors' +import { describeError, toError } from '@sim/utils/errors' import { RequestTraceV1Outcome } from '@/lib/copilot/generated/request-trace-v1' import { CopilotBranchKind, @@ -95,10 +95,14 @@ export function isActionableErrorStatus(code: number): boolean { export function markSpanForError(span: Span, error: unknown): void { const asError = toError(error) span.recordException(asError) + const described = describeError(error) + if (described.code) { + span.setAttribute(TraceAttr.ErrorCode, described.code) + } if (!isExplicitUserStopError(error)) { span.setStatus({ code: SpanStatusCode.ERROR, - message: asError.message, + message: described.causeChain ? described.causeChain.join(' <- ') : asError.message, }) } }