Skip to content

fix(core): Improve waiting for tracing channel bindings#21815

Merged
mydea merged 8 commits into
developfrom
fn/tracing-channel-bindings
Jun 29, 2026
Merged

fix(core): Improve waiting for tracing channel bindings#21815
mydea merged 8 commits into
developfrom
fn/tracing-channel-bindings

Conversation

@mydea

@mydea mydea commented Jun 26, 2026

Copy link
Copy Markdown
Member

We rely on the async local storage instance for the tracing channel bindings.

Previously, this was picked up from the otel context manager (in otel-mode). However, this is only setup after the integrations run, leading to a race condition where this was not available yet.

The "fix" for this we used so far was to setup the channel-based listeners in the next tick via Promise.resolve(). Apart from being a bit hacky, this also has a concrete problem: If code runs synchrounsly after Sentry.init(), this could be unhandled by our integration (this was surfaced when moving vercel ai v6 to use orchestrion, where this failed in CJS).

So this PR changes this a bit, so that in the happy path where we use our own context manager, we can use a consistent instance of async local storage even before the manager is setup. In this case, we can setup the integrations in a sync way and everything just works.

If users use a custom context manager, this will/may not work though. So in this case we continue to use the lookup from the context manager (this can be removed in v11). Since this means we have the same problems as before, I added a small utility waitForTracingChannelBinding to abstract this away - this will try to see if this is setup and if so, exectute the provided callback synchronously. Else, it will wait a tick and try again (mirroring what we had before).

While at this, I also cleaned up internal exports from core a bit - one of them can be reproduced with more public APIs already, we just never exported getAsyncContextStrategy from core but this is fine to export IMHO.

I also adjusted the type a bit so that asyncLocalStorage in the binding is unknown but non nullable, as this could accidentally become undefined which would not be caught by types but is not really intended - in this case the whole binding should be undefined.

Comment thread packages/core/src/asyncContext/tracing-channel-binding.ts Outdated
@github-actions

github-actions Bot commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

size-limit report 📦

Path Size % Change Change
@sentry/browser 27.48 kB - -
@sentry/browser - with treeshaking flags 25.91 kB - -
@sentry/browser (incl. Tracing) 45.97 kB - -
@sentry/browser (incl. Tracing + Span Streaming) 47.72 kB - -
@sentry/browser (incl. Tracing, Profiling) 50.76 kB - -
@sentry/browser (incl. Tracing, Replay) 85.22 kB - -
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 74.81 kB - -
@sentry/browser (incl. Tracing, Replay with Canvas) 89.91 kB - -
@sentry/browser (incl. Tracing, Replay, Feedback) 102.57 kB - -
@sentry/browser (incl. Feedback) 44.66 kB - -
@sentry/browser (incl. sendFeedback) 32.26 kB - -
@sentry/browser (incl. FeedbackAsync) 37.4 kB - -
@sentry/browser (incl. Metrics) 28.54 kB - -
@sentry/browser (incl. Logs) 28.78 kB - -
@sentry/browser (incl. Metrics & Logs) 29.47 kB - -
@sentry/react 29.27 kB - -
@sentry/react (incl. Tracing) 48.28 kB - -
@sentry/vue 32.63 kB - -
@sentry/vue (incl. Tracing) 47.84 kB - -
@sentry/svelte 27.5 kB - -
CDN Bundle 29.89 kB +0.01% +1 B 🔺
CDN Bundle (incl. Tracing) 47.9 kB +0.02% +6 B 🔺
CDN Bundle (incl. Logs, Metrics) 31.44 kB +0.02% +5 B 🔺
CDN Bundle (incl. Tracing, Logs, Metrics) 49.24 kB +0.02% +5 B 🔺
CDN Bundle (incl. Replay, Logs, Metrics) 70.77 kB -0.02% -10 B 🔽
CDN Bundle (incl. Tracing, Replay) 85.41 kB +0.02% +12 B 🔺
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 86.68 kB +0.01% +3 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback) 91.2 kB +0.02% +15 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 92.45 kB +0.01% +5 B 🔺
CDN Bundle - uncompressed 88.95 kB +0.01% +5 B 🔺
CDN Bundle (incl. Tracing) - uncompressed 145.02 kB -0.01% -3 B 🔽
CDN Bundle (incl. Logs, Metrics) - uncompressed 93.65 kB +0.01% +6 B 🔺
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 149 kB -0.01% -2 B 🔽
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 218.63 kB +0.01% +2 B 🔺
CDN Bundle (incl. Tracing, Replay) - uncompressed 264.04 kB -0.01% -8 B 🔽
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 268 kB -0.01% -7 B 🔽
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 277.74 kB -0.01% -8 B 🔽
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 281.69 kB -0.01% -7 B 🔽
@sentry/nextjs (client) 50.67 kB - -
@sentry/sveltekit (client) 46.37 kB - -
@sentry/core/server 77.6 kB +0.08% +57 B 🔺
@sentry/core/browser 63.92 kB +0.07% +44 B 🔺
@sentry/node-core 61.44 kB -0.12% -68 B 🔽
@sentry/node 123.45 kB -0.04% -40 B 🔽
@sentry/node/import (ESM hook with diagnostics-channel injection) 69.95 kB - -
@sentry/node/light 50.4 kB - -
@sentry/node - without tracing 73.56 kB -0.07% -47 B 🔽
@sentry/aws-serverless 84.36 kB -0.05% -37 B 🔽
@sentry/cloudflare (withSentry) - minified 180.31 kB - -
@sentry/cloudflare (withSentry) 446.3 kB +0.02% +68 B 🔺

View base workflow run

Comment thread packages/opentelemetry/src/nodeAsyncContextStrategy.ts Outdated
Comment thread packages/opentelemetry/src/index.ts
@mydea mydea requested a review from logaretm June 26, 2026 11:50
@mydea mydea marked this pull request as ready for review June 26, 2026 11:50
@mydea mydea requested a review from a team as a code owner June 26, 2026 11:50
@mydea mydea requested review from JPeer264 and andreiborza and removed request for a team June 26, 2026 11:50

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

There are 2 total unresolved issues (including 1 from previous review).

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 113ee44. Configure here.

Comment thread packages/vercel-edge/src/sdk.ts Outdated
Comment thread packages/vercel-edge/src/sdk.ts
@mydea mydea force-pushed the fn/tracing-channel-bindings branch from 35ef394 to 63995bd Compare June 29, 2026 07:41
@mydea mydea requested a review from nicohrubec June 29, 2026 08:13
@mydea mydea merged commit 78526ba into develop Jun 29, 2026
558 of 560 checks passed
@mydea mydea deleted the fn/tracing-channel-bindings branch June 29, 2026 09:33
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