mirror of
https://github.com/stack-auth/stack.git
synced 2026-07-20 21:29:36 +08:00
Browser withSpan frames can mix across concurrently interleaved async flows (no async-context primitive exists there — the reason for TC39 AsyncContext). Support BOTH policies via analytics.ambientParenting: - "exact" (default): a frame is ambient only when provably from the current flow — an exact primitive (ALS on servers/edge; AsyncContext in browsers once shipped), or the callback's SYNCHRONOUS window on the browser fallback (single-threaded sync execution cannot interleave, so prologue-open frames are exact by construction). Never wrong; can only under-attach. - "best-effort": frames also stay ambient across browser awaits (zero-glue), accepting the documented cross-flow caveat. Handle kit on every Span (browser, server, inert) — exact everywhere, both modes: span.withSpan (nested child), span.run (re-bind for callbacks/timers), span.getPropagationHeaders (non-fetch transports), span.fetch (pinned cross-tier header, same origin policy as the auto wrapper, explicit wins). Internals: sync-stack frames carry a prologueOpen flag (set false the moment the callback returns its promise); context entry runs synchronously once the ALS probe settles so sync nesting composes; getAmbientSpanRefs gains an includeSuspendedSyncFrames read policy; servers fail closed when ALS is missing. Design validated by Codex (gpt-5.5 xhigh) + a 3-lens design panel. |
||
|---|---|---|
| .. | ||
| cli | ||
| dashboard-ui-components | ||
| js | ||
| next | ||
| react | ||
| sc | ||
| shared | ||
| shared-backend | ||
| tanstack-start | ||
| template | ||
| ui | ||