feat(core): Remove span from ScopeData - #23225
Conversation
We can look this up directly/manually instead.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit cdc8f0a. Configure here.
size-limit report 📦
|
| const span = getActiveSpan(finalScope); | ||
| if (span) { | ||
| applySpanToEvent(prepared, span); | ||
| } |
There was a problem hiding this comment.
Bug: When captureContext is used, scope.clone() is called but fails to copy the OpenTelemetry context (_scopeContext), causing the active span to be lost from the event.
Severity: HIGH
Suggested Fix
The Scope.clone() method should be updated to also copy the _scopeContext from the original scope to the new one. Alternatively, getActiveSpan could be modified to fall back to the global trace.getActiveSpan() if getContextFromScope(scope) returns undefined, which would align its behavior with the case where no scope is provided.
Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.
Location: packages/core/src/utils/prepareEvent.ts#L91-L94
Potential issue: When an event is captured with a `captureContext`, the associated scope
is cloned via `scope.clone()`. This cloning process does not copy the `_scopeContext`
property, which is used by the OpenTelemetry integration to link to the active OTEL
context. The new logic in `prepareEvent.ts` attempts to get the active span from this
cloned scope. Because the `_scopeContext` is missing, `getActiveSpan` returns
`undefined` and does not fall back to the global active span. This results in the active
span being dropped from the event, breaking tracing for any errors captured with a
`captureContext`.
Did we get this right? 👍 / 👎 to inform future reviews.

We can look this up directly/manually instead - this unlinks these (partially), some follow up work is still needed but this is a part of it.