Skip to content

v0 [1/7]: context propagation — runtime patch, startup probe, Metro helper - #21

Merged
adhorodyski merged 1 commit into
v0from
stack/1-js-sdk
Nov 25, 2026
Merged

adhorodyski merged 1 commit into
v0from
stack/1-js-sdk

Conversation

@adhorodyski

@adhorodyski adhorodyski commented Nov 25, 2026 •

Copy link
Copy Markdown
Collaborator

What

  • Context patch (§6.1, R3): carries the active OTel context from where a callback is scheduled to where it runs. It patches Promise.prototype.then, setTimeout, setImmediate, queueMicrotask and requestAnimationFrame globally; setInterval ticks run at ROOT (§6.2). setup.ts installs it once, as a singleton on a globalThis marker, so fast refresh or a second copy of the SDK never stacks wrappers.
  • Startup probe: checks that context survives await. If it doesn't, it logs one error and sets com.callstack.context.degraded=true on the SDK tracers' instrumentation scope.
  • Metro withOtel (/metro): runs setup before any app module. It throws on an unmerged config and keeps the package out of inline requires.
  • Unit tests for each; fast-js now runs the unit Jest project. Also drops the dangling ./vite export from v0's package.json.

Verified locally

bun verify static fast-js: 36 + 22 tests green (12 scenario todos until #27). SDK bundle share at the 383 873 B baseline.

Worth deciding here

  1. Global patch: the promise and timer patch applies to the whole app, third-party code included. At ROOT the original is called directly. perf-budget (v0 [3/7]: JS scenarios, hand-off fixtures and JS goldens #27, run on devices in v0 [6/7]: example apps (bare, Expo) and device and web e2e #24) gates the overhead at under 3×.
  2. Upstream internals: RNContextManager writes StackContextManager's protected _currentContext, and scope.ts mutates tracer.instrumentationScope (sdk-trace 3.1 has no API for scope attributes). Both can break on an sdk-trace upgrade; scope.ts then silently skips the degraded flag.

Not in this PR

startReactNativeSdk (#26), scenarios and goldens (#27), native cores (#22, #23).


Part of the v0 stack that replaces #20 for review, bottom-up: #21 context → #26 SDK → #27 JS scenarios → #22 Android → #23 iOS → #24 examples + e2e → #25 ops. Review fixes land as new commits on the layer they belong to, and the layers above are rebased. History before the split: v0-impl / #20. Nothing publishes: release runs only after CI on main, and the npm environment does not exist yet.

🤖 Generated with Claude Code

@adhorodyski adhorodyski changed the title v0 [1/5]: JS SDK — context patch, startReactNativeSdk, Metro and Vite helpers v0 [1/5]: JS SDK — context patch, startReactNativeSdk, Metro helper Nov 25, 2026
… the Metro helper

Carries the active OTel context across promises and timers (§6.1): a global patch of `Promise.prototype.then`,
setTimeout, setImmediate, queueMicrotask and requestAnimationFrame, installed once by `setup.ts`, with
`setInterval` ticks at ROOT (§6.2). A startup probe checks that context survives `await` and otherwise flags the
SDK's tracers as degraded. `withOtel` from `/metro` runs setup before any app module. Unit tests for each.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@adhorodyski adhorodyski changed the title v0 [1/5]: JS SDK — context patch, startReactNativeSdk, Metro helper v0 [1/7]: context propagation — runtime patch, startup probe, Metro helper Nov 25, 2026
@adhorodyski
adhorodyski marked this pull request as ready for review November 25, 2026 16:43
@adhorodyski
adhorodyski merged commit 4192168 into v0 Nov 25, 2026
@adhorodyski
adhorodyski deleted the stack/1-js-sdk branch November 25, 2026 16:43
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.

1 participant