Skip to content

v0 [2/7]: startReactNativeSdk on mobile and web - #26

Merged
adhorodyski merged 3 commits into
v0from
stack/1b-sdk
Nov 25, 2026
Merged

adhorodyski merged 3 commits into
v0from
stack/1b-sdk

Conversation

@adhorodyski

@adhorodyski adhorodyski commented Nov 25, 2026 •

Copy link
Copy Markdown
Collaborator

What

  • startReactNativeSdk(config?) (src/sdk/):
    • Mobile (start.ts): attaches to native, or initializes it from the JS config (§4.4). Spans go to native through NativeHandOffProcessor, and native owns the resource.
    • Web (start.web.ts): builds its own TracerProvider with BatchSpanProcessor and the upstream OTLP/proto exporter (R7). The package's browser export condition selects it.
    • Shared (shared.ts): registers the global provider, stamps every tracer's scope and starts the probe from v0 [1/7]: context propagation — runtime patch, startup probe, Metro helper #21. The first call's handle wins (D10).
    • Failures (noop.ts): any failure logs one error and returns a no-op handle. The SDK never throws into the app.
  • package.json: browser export, typed ./setup. @opentelemetry/exporter-trace-otlp-proto becomes a dependency and replaces @opentelemetry/browser-sdk. jsdom is added as a dev dependency for the web unit test.
  • exportConfig.url is the OTLP/HTTP traces endpoint, used as given; the version for telemetry.distro.version comes from the package's own package.json.
  • Drops the bundle-size check (static stage, its test, baseline and CI step).
  • native/otel.ts no longer swallows HybridObject constructor errors; start reports them. testMode.ts reads plain process.env.OTEL_TEST_MODE, the form Babel inlines.

Verified locally

bun verify static fast-js: 33 + 42 tests green (12 scenario todos until the next PR).

Decisions for you (defaults applied; override with spec: comments)

  1. Web (R7): web builds its own TracerProvider with the OTLP proto exporter instead of using startBrowserSdk. Spec §7 is rewritten, and @opentelemetry/browser-sdk is removed.
  2. Web flush on page hide: there is no test for it.

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

Mobile attaches to native, or initializes it from the JS config (§4.4), and hands spans to native through
NativeHandOffProcessor. Web builds its own TracerProvider with BatchSpanProcessor and the upstream OTLP/proto exporter
(R7), picked by the package's `browser` export condition. The first call's handle wins; any failure logs once and
returns a no-op handle. The native module accessor no longer swallows constructor errors; start reports them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Comment thread src/sdk/config.ts Outdated
return base.endsWith('/v1/traces') ? base : base + '/v1/traces';
}

/** `telemetry.distro.version` on web; a unit test keeps it equal to package.json's version. */

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

q: why can't we read package.json's version directly?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can, and now we do: start.web.ts imports react-native-open-telemetry/package.json (a self-reference through the package's ./package.json export). It resolves in TypeScript, Jest, the built lib/ and Metro's web export (web e2e passes). DISTRO_VERSION and its sync test are gone in d2849ec, and the release script now only keeps the iOS constant (#25). One cost: Metro bundles the whole package.json (a few KB) into the web bundle. iOS still has a hand-kept constant, because Swift has no build-time access to package.json.

Comment thread src/sdk/config.ts Outdated
}

/** One endpoint meaning on every platform (§4.4). Mobile passes the base URL; native applies the same rule. */
export function tracesUrl(url: string): string {

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

feels like we're overcomplicating it, just ask for a specific URL

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. url is now the OTLP/HTTP traces endpoint, used as given (e.g. https://collector:4318/v1/traces), on every platform: tracesUrl is removed here (d2849ec), in the Kotlin core (#22, a98a215) and in the Swift core (#23, 81ec9eb). The example apps (#24) and the spec §4.4, plan, README and MIGRATION (#25) use the full URL.

Comment thread src/sdk/config.ts Resolved
Comment thread verify/static/bundleSize.ts Outdated

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why have any bundle size related code?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No good reason, so it's gone (2e461a6): bundleSize.ts, its test, the baseline, the static step and CI's example install that only existed for it. The spec, plan and VERIFY mentions are removed in #25.

adhorodyski and others added 2 commits November 25, 2026 19:35
It bundled the example app with Metro on every static run against a committed baseline nobody set a budget for.
Removes bundleSize.ts, its test and baseline, the static step, and CI's example install that existed only for it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…istro version from package.json

- No `/v1/traces` appending: `url` is the full OTLP/HTTP traces endpoint (§4.4). Native follows in the Android and
  iOS layers.
- Web reads `telemetry.distro.version` from the package's own `package.json` (self-reference through the
  `./package.json` export), so there is no hand-kept version constant.
- Tests: dropped the ones that only re-checked upstream or a constant (a span's default start time, the URL helper,
  DISTRO_VERSION against package.json); the web URL test is one case now.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@adhorodyski
adhorodyski added this pull request to stack #28 November 25, 2026 18:49
@adhorodyski
adhorodyski merged commit 9b61fb6 into v0 Nov 25, 2026
@adhorodyski
adhorodyski deleted the stack/1b-sdk branch November 25, 2026 18:50
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