Skip to content

feat(core): Remove span from ScopeData - #23225

Open
mydea wants to merge 2 commits into
fn/use-getActiveSpanfrom
fn/remove-span-scope-data
Open

feat(core): Remove span from ScopeData#23225
mydea wants to merge 2 commits into
fn/use-getActiveSpanfrom
fn/remove-span-scope-data

Conversation

@mydea

@mydea mydea commented Aug 10, 2026

Copy link
Copy Markdown
Member

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.

We can look this up directly/manually instead.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ 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.

Comment thread packages/core/src/utils/prepareEvent.ts
@github-actions

github-actions Bot commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

size-limit report 📦

⚠️ Warning: Base artifact is not the latest one, because the latest workflow run is not done yet. This may lead to incorrect results. Try to re-run all tests to get up to date results.

Path Size % Change Change
@sentry/browser 30.37 kB +0.06% +16 B 🔺
@sentry/browser - with treeshaking flags 28.55 kB +0.1% +26 B 🔺
@sentry/browser - with treeshaking flags tracing without tracing 26.87 kB +0.08% +20 B 🔺
@sentry/browser (incl. Tracing) 48.6 kB -0.02% -9 B 🔽
@sentry/browser (incl. Tracing + Span Streaming) 48.61 kB -0.02% -9 B 🔽
@sentry/browser (incl. Tracing, Profiling) 53.45 kB -0.02% -8 B 🔽
@sentry/browser (incl. Tracing, Replay) 88.03 kB -0.02% -11 B 🔽
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 77.45 kB -0.02% -8 B 🔽
@sentry/browser (incl. Tracing, Replay with Canvas) 92.76 kB -0.02% -10 B 🔽
@sentry/browser (incl. Tracing, Replay, Feedback) 105.43 kB -0.02% -19 B 🔽
@sentry/browser (incl. Feedback) 47.69 kB +0.01% +2 B 🔺
@sentry/browser (incl. sendFeedback) 35.19 kB +0.04% +14 B 🔺
@sentry/browser (incl. FeedbackAsync) 40.35 kB +0.05% +18 B 🔺
@sentry/browser (incl. Metrics) 31.4 kB -0.08% -22 B 🔽
@sentry/browser (incl. Logs) 31.65 kB -0.02% -5 B 🔽
@sentry/browser (incl. Metrics & Logs) 32.34 kB -0.01% -2 B 🔽
@sentry/react 32.17 kB +0.1% +32 B 🔺
@sentry/react (incl. Tracing) 50.81 kB -0.02% -8 B 🔽
@sentry/vue 35.44 kB -0.02% -6 B 🔽
@sentry/vue (incl. Tracing) 50.58 kB -0.02% -9 B 🔽
@sentry/svelte 30.39 kB +0.06% +16 B 🔺
CDN Bundle 31.59 kB -0.04% -12 B 🔽
CDN Bundle (incl. Tracing) 48.91 kB -0.01% -4 B 🔽
CDN Bundle (incl. Logs, Metrics) 33.84 kB -0.03% -7 B 🔽
CDN Bundle (incl. Tracing, Logs, Metrics) 50.88 kB -0.02% -6 B 🔽
CDN Bundle (incl. Replay, Logs, Metrics) 74.37 kB -0.01% -7 B 🔽
CDN Bundle (incl. Tracing, Replay) 86.49 kB -0.01% -5 B 🔽
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 88.39 kB -0.02% -9 B 🔽
CDN Bundle (incl. Tracing, Replay, Feedback) 92.2 kB -0.01% -4 B 🔽
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 94.18 kB -0.01% -8 B 🔽
CDN Bundle - uncompressed 93.93 kB -0.02% -18 B 🔽
CDN Bundle (incl. Tracing) - uncompressed 146.9 kB -0.02% -23 B 🔽
CDN Bundle (incl. Logs, Metrics) - uncompressed 100.39 kB -0.03% -23 B 🔽
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 152.75 kB -0.02% -23 B 🔽
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 229.32 kB -0.02% -23 B 🔽
CDN Bundle (incl. Tracing, Replay) - uncompressed 266.15 kB -0.01% -23 B 🔽
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 271.99 kB -0.01% -23 B 🔽
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 279.85 kB -0.01% -23 B 🔽
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 285.68 kB -0.01% -23 B 🔽
@sentry/nextjs (client) 53.39 kB -0.02% -7 B 🔽
@sentry/sveltekit (client) 49.02 kB -0.02% -7 B 🔽
@sentry/core/server 65.57 kB -0.05% -32 B 🔽
@sentry/core/browser 51.9 kB -0.04% -20 B 🔽
@sentry/node 118.47 kB +0.01% +8 B 🔺
@sentry/node/import (ESM hook with diagnostics-channel injection) 0 B added added
@sentry/node - without tracing 82.58 kB +0.02% +12 B 🔺
@sentry/aws-serverless 91.95 kB +0.01% +6 B 🔺
@sentry/cloudflare (withSentry) - minified 214.67 kB -0.02% -30 B 🔽
@sentry/cloudflare (withSentry) 530.2 kB -0.01% -31 B 🔽

View base workflow run

@mydea
mydea marked this pull request as ready for review August 10, 2026 13:08
Comment on lines +91 to +94
const span = getActiveSpan(finalScope);
if (span) {
applySpanToEvent(prepared, span);
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant