Skip to content

feat(server-utils): Implement setAsyncLocalStorageAsyncContextStrategy - #22889

Merged
isaacs merged 5 commits into
fn/bun-http-integrationfrom
fn/acs-server-utils
Jul 31, 2026
Merged

feat(server-utils): Implement setAsyncLocalStorageAsyncContextStrategy#22889
isaacs merged 5 commits into
fn/bun-http-integrationfrom
fn/acs-server-utils

Conversation

@mydea

@mydea mydea commented Jul 31, 2026

Copy link
Copy Markdown
Member

This unifies the ACS strategy from cloudflare and deno into server-utils.
Eventually this will also be used in node (when not in otel mode).
Also, this makes it easier to adjust this in follow ups as there is more centralization now.

This also adds an export to server utils package @sentry/server-utils/no-diagnostic-channel which can be used e.g. by cloudflare or in the future by vercel-edge, in runtimes where this is not supported.

Comment thread packages/opentelemetry/src/asyncContextStrategy.ts Outdated
@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.3% -89 B 🔽
@sentry/browser - with treeshaking flags 28.02 kB -0.33% -91 B 🔽
@sentry/browser (incl. Tracing) 47.08 kB -0.63% -298 B 🔽
@sentry/browser (incl. Tracing + Span Streaming) 47.09 kB -0.62% -293 B 🔽
@sentry/browser (incl. Tracing, Profiling) 51.82 kB -0.63% -325 B 🔽
@sentry/browser (incl. Tracing, Replay) 86.39 kB -0.38% -324 B 🔽
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 75.83 kB -0.42% -318 B 🔽
@sentry/browser (incl. Tracing, Replay with Canvas) 91.11 kB -0.35% -319 B 🔽
@sentry/browser (incl. Tracing, Replay, Feedback) 103.76 kB -0.3% -304 B 🔽
@sentry/browser (incl. Feedback) 47.13 kB -0.18% -83 B 🔽
@sentry/browser (incl. sendFeedback) 34.66 kB -0.28% -96 B 🔽
@sentry/browser (incl. FeedbackAsync) 39.76 kB -0.25% -96 B 🔽
@sentry/browser (incl. Metrics) 30.89 kB -0.31% -94 B 🔽
@sentry/browser (incl. Logs) 31.12 kB -0.32% -98 B 🔽
@sentry/browser (incl. Metrics & Logs) 31.8 kB -0.31% -98 B 🔽
@sentry/react 31.6 kB -0.41% -128 B 🔽
@sentry/react (incl. Tracing) 49.33 kB -0.64% -315 B 🔽
@sentry/vue 34.74 kB -0.71% -246 B 🔽
@sentry/vue (incl. Tracing) 49.05 kB -0.64% -313 B 🔽
@sentry/svelte 29.85 kB -0.29% -84 B 🔽
CDN Bundle 31.87 kB -0.36% -115 B 🔽
CDN Bundle (incl. Tracing) 47.45 kB -0.6% -284 B 🔽
CDN Bundle (incl. Logs, Metrics) 33.42 kB -0.38% -125 B 🔽
CDN Bundle (incl. Tracing, Logs, Metrics) 48.82 kB -0.55% -266 B 🔽
CDN Bundle (incl. Replay, Logs, Metrics) 72.78 kB -0.17% -117 B 🔽
CDN Bundle (incl. Tracing, Replay) 85.08 kB -0.34% -285 B 🔽
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 86.38 kB -0.33% -284 B 🔽
CDN Bundle (incl. Tracing, Replay, Feedback) 90.85 kB -0.34% -308 B 🔽
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 92.16 kB -0.34% -308 B 🔽
CDN Bundle - uncompressed 95.04 kB -0.48% -452 B 🔽
CDN Bundle (incl. Tracing) - uncompressed 142.27 kB -0.69% -985 B 🔽
CDN Bundle (incl. Logs, Metrics) - uncompressed 99.75 kB -0.46% -452 B 🔽
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 146.25 kB -0.67% -985 B 🔽
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 224.51 kB -0.21% -452 B 🔽
CDN Bundle (incl. Tracing, Replay) - uncompressed 261.52 kB -0.38% -985 B 🔽
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 265.49 kB -0.37% -985 B 🔽
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 275.23 kB -0.36% -985 B 🔽
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 279.18 kB -0.36% -985 B 🔽
@sentry/nextjs (client) 51.92 kB -0.57% -296 B 🔽
@sentry/sveltekit (client) 47.51 kB -0.66% -312 B 🔽
@sentry/core/server 79.6 kB -0.49% -388 B 🔽
@sentry/core/browser 51.7 kB -0.43% -219 B 🔽
@sentry/node 121.37 kB -0.2% -237 B 🔽
@sentry/node/import (ESM hook with diagnostics-channel injection) 166 B added added
@sentry/node - without tracing 84.93 kB -0.27% -224 B 🔽
@sentry/aws-serverless 93.2 kB -0.23% -212 B 🔽
@sentry/cloudflare (withSentry) - minified 198.27 kB -0.43% -853 B 🔽
@sentry/cloudflare (withSentry) 487.59 kB -0.58% -2.81 kB 🔽

View base workflow run

@mydea
mydea force-pushed the fn/acs-server-utils branch from bf0def2 to 0663385 Compare July 31, 2026 07:32
Comment thread packages/server-utils/src/async-context.ts Outdated
Comment thread packages/server-utils/src/async-context.ts
Comment thread packages/server-utils/src/async-context.ts
@mydea
mydea force-pushed the fn/acs-server-utils branch from 204c646 to cdafffe Compare July 31, 2026 08:14
Comment thread packages/server-utils/src/index.ts
Comment thread packages/server-utils/package.json
@mydea
mydea marked this pull request as ready for review July 31, 2026 09:07
@mydea
mydea requested review from a team as code owners July 31, 2026 09:07
@mydea
mydea requested review from JPeer264 and isaacs and removed request for a team July 31, 2026 09:07

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

Comment thread packages/server-utils/src/async-context.ts
@mydea
mydea force-pushed the fn/acs-server-utils branch from c04421b to 98b3378 Compare July 31, 2026 09:38
@mydea
mydea force-pushed the fn/acs-server-utils branch from 98b3378 to 313d70f Compare July 31, 2026 10:09
@mydea
mydea changed the base branch from develop to fn/bun-http-integration July 31, 2026 10:11

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

I'm curious about the removal of the redis export, but overall this is a good refactor. Great opportunity to move stuff into server-utils and reuse across SDKs :)

Comment thread packages/server-utils/src/index.ts
…er-utils

The export was dropped when index.ts was split into exports.ts, which broke the
redis-common test. It is published public API, so removing it is breaking.
The test was relocated into packages/core with a cross-package relative import;
it belongs next to the code it tests.
The strategy was derived from the deno/cloudflare one, which passes the current
scope by reference. Both the OpenTelemetry strategy and v10's node-core light
strategy clone it, so without this, current-scope mutations leak out of an
isolation fork.
Comment thread packages/server-utils/src/async-context.ts
Forking it discarded setUser/setTag/setContext calls made inside
`withScope(scope, callback)`, since those write to the isolation scope. Both the
OpenTelemetry strategy and the stack strategy share it here, as does `withScope`
without an explicit scope.
Comment thread packages/server-utils/src/async-context.ts
The Cloudflare SDK calls `init()` inside `withIsolationScope`, so the client is bound
to the scope forked for that request. Reading it from outside the handler only worked
while the current scope was shared by reference.
@andreiborza
andreiborza requested a review from isaacs July 31, 2026 15:37
@isaacs
isaacs merged commit 46f7431 into develop Jul 31, 2026
227 checks passed
@isaacs
isaacs deleted the fn/acs-server-utils branch July 31, 2026 18:41
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