Skip to content

Commit 061834c

Browse files
cursoragentclaude
andcommitted
fix(opentelemetry): Fix reversed fallback logic in getTraceData
The fallback condition in getTraceData was reversed, making the scope context path unreachable dead code. api.trace.setSpan() always returns a truthy Context object, so placing it first in the OR expression meant the fallback (scope && getContextFromScope(scope)) could never be evaluated. This fix restores the correct order: check scope context first, then fall back to setSpan if the scope doesn't exist. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent aa83a81 commit 061834c

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

packages/opentelemetry/src/utils/getTraceData.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export function getTraceData({
2424
if (span) {
2525
const { scope } = getCapturedScopesOnSpan(span);
2626
// fall back to current context if for whatever reason we can't find the one of the span
27-
ctx = api.trace.setSpan(api.context.active(), span) || (scope && getContextFromScope(scope));
27+
ctx = (scope && getContextFromScope(scope)) || api.trace.setSpan(api.context.active(), span);
2828
}
2929

3030
const { traceId, spanId, sampled, dynamicSamplingContext } = getInjectionData(ctx, { scope, client });

0 commit comments

Comments
 (0)