Skip to content

feat: Streamline isolation scope handling & reset in isolation scopes - #22890

Open
mydea wants to merge 2 commits into
fn/acs-server-utilsfrom
fn/streamline-acs-isolation-scope
Open

feat: Streamline isolation scope handling & reset in isolation scopes#22890
mydea wants to merge 2 commits into
fn/acs-server-utilsfrom
fn/streamline-acs-isolation-scope

Conversation

@mydea

@mydea mydea commented Jul 31, 2026

Copy link
Copy Markdown
Member

This PR does two things:

  1. Removes any usage of propagation context on isolation scope. We never really need/read this, as the current scope one will always overwrite this. Generally we should only ever set/read propagation context on current scope.
  2. Adjust server-side withIsolationScope to reset the propagation context unless it is continuing a trace. Today, this kind of works in otel-based places because we wrap root spans in startNewTrace. But this does not align with core/browser handling, so going forward this will be removed. instead, we want this logic to be applied in an isolation scope, so the following code will result in separate traces:
Sentry.withIsolationScope(() => {
  Sentry.startSpan({ name: 'process 1' }, () => ...);
});

Sentry.withIsolationScope(() => {
  Sentry.startSpan({ name: 'process 2' }, () => ...);
});

without this change, both of these spans would be part of the same trace, which is not what we want in server.

note: In browser, we do not actually fork the isolation scope, there is just a single one, so this does not apply.

Comment thread packages/server-utils/src/async-context.ts
@github-actions

github-actions Bot commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

size-limit report 📦

Path Size % Change Change
@sentry/browser 29.82 kB -0.02% -3 B 🔽
@sentry/browser - with treeshaking flags 28.02 kB -0.01% -2 B 🔽
@sentry/browser (incl. Tracing) 47.07 kB -0.01% -4 B 🔽
@sentry/browser (incl. Tracing + Span Streaming) 47.08 kB -0.02% -7 B 🔽
@sentry/browser (incl. Tracing, Profiling) 51.81 kB -0.02% -10 B 🔽
@sentry/browser (incl. Tracing, Replay) 86.38 kB -0.02% -14 B 🔽
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 75.82 kB -0.02% -11 B 🔽
@sentry/browser (incl. Tracing, Replay with Canvas) 91.1 kB -0.02% -11 B 🔽
@sentry/browser (incl. Tracing, Replay, Feedback) 103.75 kB -0.01% -8 B 🔽
@sentry/browser (incl. Feedback) 47.13 kB -0.01% -1 B 🔽
@sentry/browser (incl. sendFeedback) 34.66 kB -0.01% -3 B 🔽
@sentry/browser (incl. FeedbackAsync) 39.76 kB -0.01% -2 B 🔽
@sentry/browser (incl. Metrics) 30.89 kB - -
@sentry/browser (incl. Logs) 31.12 kB -0.01% -1 B 🔽
@sentry/browser (incl. Metrics & Logs) 31.8 kB -0.02% -6 B 🔽
@sentry/react 31.6 kB -0.04% -11 B 🔽
@sentry/react (incl. Tracing) 49.31 kB -0.03% -13 B 🔽
@sentry/vue 34.74 kB -0.01% -2 B 🔽
@sentry/vue (incl. Tracing) 49.04 kB -0.04% -15 B 🔽
@sentry/svelte 29.85 kB -0.01% -2 B 🔽
CDN Bundle 31.87 kB - -
CDN Bundle (incl. Tracing) 47.45 kB -0.03% -10 B 🔽
CDN Bundle (incl. Logs, Metrics) 33.42 kB -0.01% -3 B 🔽
CDN Bundle (incl. Tracing, Logs, Metrics) 48.82 kB -0.02% -7 B 🔽
CDN Bundle (incl. Replay, Logs, Metrics) 72.78 kB -0.01% -3 B 🔽
CDN Bundle (incl. Tracing, Replay) 85.06 kB -0.02% -14 B 🔽
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 86.37 kB -0.02% -14 B 🔽
CDN Bundle (incl. Tracing, Replay, Feedback) 90.84 kB -0.02% -14 B 🔽
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 92.15 kB -0.02% -14 B 🔽
CDN Bundle - uncompressed 95.04 kB -0.08% -73 B 🔽
CDN Bundle (incl. Tracing) - uncompressed 142.13 kB -0.15% -210 B 🔽
CDN Bundle (incl. Logs, Metrics) - uncompressed 99.75 kB -0.08% -73 B 🔽
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 146.11 kB -0.15% -210 B 🔽
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 224.51 kB -0.04% -73 B 🔽
CDN Bundle (incl. Tracing, Replay) - uncompressed 261.39 kB -0.09% -210 B 🔽
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 265.35 kB -0.08% -210 B 🔽
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 275.09 kB -0.08% -210 B 🔽
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 279.05 kB -0.08% -210 B 🔽
@sentry/nextjs (client) 51.91 kB -0.02% -6 B 🔽
@sentry/sveltekit (client) 47.5 kB -0.03% -12 B 🔽
@sentry/core/server 79.61 kB -0.03% -18 B 🔽
@sentry/core/browser 51.71 kB +0.01% +5 B 🔺
@sentry/node 121.41 kB +0.01% +4 B 🔺
@sentry/node/import (ESM hook with diagnostics-channel injection) 166 B - -
@sentry/node - without tracing 84.98 kB +0.09% +70 B 🔺
@sentry/aws-serverless 93.25 kB +0.07% +63 B 🔺
@sentry/cloudflare (withSentry) - minified 198.33 kB -0.02% -25 B 🔽
@sentry/cloudflare (withSentry) 487.8 kB +0.02% +49 B 🔺

View base workflow run

@mydea
mydea force-pushed the fn/streamline-acs-isolation-scope branch from 2cab26a to 1eda574 Compare July 31, 2026 07:32
Comment thread packages/server-utils/src/async-context.ts
Comment thread packages/server-utils/test/async-context.test.ts
@mydea
mydea force-pushed the fn/streamline-acs-isolation-scope branch from 1eda574 to ccf3b05 Compare July 31, 2026 07:57
Comment thread packages/server-utils/src/async-context.ts
Comment thread packages/server-utils/src/async-context.ts
@mydea
mydea force-pushed the fn/streamline-acs-isolation-scope branch from ccf3b05 to 8979856 Compare July 31, 2026 08:15

@Lms24 Lms24 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think this is a good change!


if (!hasSpansEnabled()) {
const scopePropagationContext = { ...isolationScope.getPropagationContext(), ...scope.getPropagationContext() };
const scopePropagationContext = scope.getPropagationContext();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

it seems like this removes a footgun where we potentially incorrectly merged a propagation context before here. I like it!

Comment thread packages/server-utils/src/async-context.ts
@mydea
mydea force-pushed the fn/streamline-acs-isolation-scope branch from 8979856 to 8196869 Compare July 31, 2026 08:46
Comment thread packages/core/src/exports.ts Outdated
@mydea
mydea force-pushed the fn/streamline-acs-isolation-scope branch from a2496b8 to 7e8cef9 Compare July 31, 2026 09:07
Comment thread packages/core/src/monitor.ts Outdated
@mydea
mydea force-pushed the fn/streamline-acs-isolation-scope branch from 7e8cef9 to dea8d51 Compare July 31, 2026 09:32
@mydea
mydea force-pushed the fn/streamline-acs-isolation-scope branch from dea8d51 to d1f9cac Compare July 31, 2026 09:39
@mydea
mydea force-pushed the fn/streamline-acs-isolation-scope branch from d1f9cac to 2efb184 Compare July 31, 2026 10:10
@mydea
mydea marked this pull request as ready for review July 31, 2026 10:21
@mydea
mydea requested review from a team as code owners July 31, 2026 10:21
@mydea
mydea requested review from JPeer264, isaacs, logaretm and msonnb and removed request for a team July 31, 2026 10:21

@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 65c8a4c. Configure here.

const newPropagationContext = getCurrentScope().getPropagationContext();
if (!newPropagationContext.parentSpanId) {
getCurrentScope().setPropagationContext(oldPropagationContext);
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Shared propagation context reference

Low Severity

When restoring the parent trace for non-isolateTrace monitors, setPropagationContext is given the original propagation context object from the parent scope rather than a copy. On strategies that fork the current scope, the monitor scope then aliases the parent's mutable context, so in-place field updates inside the callback can alter the parent.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 65c8a4c. Configure here.

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.

2 participants