feat(core): Remove span from ScopeData - #23225
Conversation
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.
ba2311e to
5176783
Compare
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 5176783. Configure here.
|
|
||
| expect(processedEvent?.transaction).toBe('/users/:id'); | ||
| }); | ||
| }); |
There was a problem hiding this comment.
Missing integration or E2E tests
Low Severity
This is a feat PR but only adds unit tests for active-span application in prepareEvent. Per the testing conventions in the review rules, a feat PR should include at least one integration or E2E test covering the new behavior end-to-end.
Triggered by project rule: PR Review Guidelines for Cursor Bot
Reviewed by Cursor Bugbot for commit 5176783. Configure here.
We no longer need this after #23225, as this should now pick up the correct span also for otel.


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.