Skip to content

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

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

feat: Streamline isolation scope handling & reset in isolation scopes#22890
mydea wants to merge 2 commits into
developfrom
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.91 kB - -
@sentry/browser - with treeshaking flags 28.11 kB - -
@sentry/browser (incl. Tracing) 47.36 kB -0.04% -15 B 🔽
@sentry/browser (incl. Tracing + Span Streaming) 47.37 kB -0.03% -14 B 🔽
@sentry/browser (incl. Tracing, Profiling) 52.14 kB -0.03% -11 B 🔽
@sentry/browser (incl. Tracing, Replay) 86.7 kB -0.02% -11 B 🔽
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 76.14 kB -0.02% -9 B 🔽
@sentry/browser (incl. Tracing, Replay with Canvas) 91.42 kB -0.01% -8 B 🔽
@sentry/browser (incl. Tracing, Replay, Feedback) 104.06 kB -0.01% -7 B 🔽
@sentry/browser (incl. Feedback) 47.22 kB - -
@sentry/browser (incl. sendFeedback) 34.76 kB - -
@sentry/browser (incl. FeedbackAsync) 39.86 kB - -
@sentry/browser (incl. Metrics) 30.99 kB - -
@sentry/browser (incl. Logs) 31.22 kB - -
@sentry/browser (incl. Metrics & Logs) 31.89 kB - -
@sentry/react 31.73 kB - -
@sentry/react (incl. Tracing) 49.62 kB -0.05% -20 B 🔽
@sentry/vue 34.98 kB - -
@sentry/vue (incl. Tracing) 49.35 kB -0.03% -13 B 🔽
@sentry/svelte 29.94 kB - -
CDN Bundle 31.98 kB - -
CDN Bundle (incl. Tracing) 47.72 kB -0.03% -10 B 🔽
CDN Bundle (incl. Logs, Metrics) 33.55 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) 49.08 kB -0.02% -8 B 🔽
CDN Bundle (incl. Replay, Logs, Metrics) 72.9 kB - -
CDN Bundle (incl. Tracing, Replay) 85.35 kB -0.02% -9 B 🔽
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 86.65 kB -0.02% -10 B 🔽
CDN Bundle (incl. Tracing, Replay, Feedback) 91.14 kB -0.02% -13 B 🔽
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 92.46 kB -0.02% -10 B 🔽
CDN Bundle - uncompressed 95.49 kB - -
CDN Bundle (incl. Tracing) - uncompressed 143.11 kB -0.1% -137 B 🔽
CDN Bundle (incl. Logs, Metrics) - uncompressed 100.2 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 147.09 kB -0.1% -137 B 🔽
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 224.96 kB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 262.37 kB -0.06% -137 B 🔽
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 266.34 kB -0.06% -137 B 🔽
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 276.08 kB -0.05% -137 B 🔽
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 280.03 kB -0.05% -137 B 🔽
@sentry/nextjs (client) 52.21 kB -0.01% -4 B 🔽
@sentry/sveltekit (client) 47.81 kB -0.02% -8 B 🔽
@sentry/core/server 80 kB +0.01% +6 B 🔺
@sentry/core/browser 51.93 kB +0.02% +7 B 🔺
@sentry/node 121.67 kB +0.04% +45 B 🔺
@sentry/node/import (ESM hook with diagnostics-channel injection) 0 B added added
@sentry/node - without tracing 85.22 kB +0.07% +52 B 🔺
@sentry/aws-serverless 93.48 kB +0.06% +53 B 🔺
@sentry/cloudflare (withSentry) - minified 199.25 kB +0.04% +69 B 🔺
⛔️ @sentry/cloudflare (withSentry) (max: 490.5 kB) 490.77 kB +0.05% +212 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.

Comment thread packages/core/src/monitor.ts
Base automatically changed from fn/acs-server-utils to develop July 31, 2026 18:41
@isaacs
isaacs force-pushed the fn/streamline-acs-isolation-scope branch from 65c8a4c to d01ded9 Compare August 1, 2026 00:30

@isaacs isaacs 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.

This is a good change, but there are a few gaps, which I think would result in bugs in trace propagation.

I rebased it onto develop, which picked up the fix for one missing case, which was fixed on 46f7431 as part of #22889.

For the others, I added commits with tests and fixes here: https://gist.github.com/isaacs/790e2d23abeebddf5b9079f53e4fbf45 or on the isaacs/fix-fn/streamline-acs-isolation-scope branch.

I figured this is probably more useful than just comments, since I'm going to be out next 2 weeks, so whoever picks this up can inspect and land with those additions, or go a different direction if you decide. 👍

Comment on lines 440 to 443
} = {
...isolationScope.getPropagationContext(),
...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.

Should this also be updated to just scope.getPropagationContext()?

Suggested change
} = scope.getPropagationContext();

or:

Suggested change
} = {
...scope.getPropagationContext(),
};

Comment thread packages/core/src/monitor.ts
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.

3 participants