Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/superpowers/plans/2026-11-21-rn-otel-v0.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
- Android native init runs only in the main process.
- Test mode is a **build flag**, never public API: JS `process.env.OTEL_TEST_MODE === '1'` inlined at bundle time; Android Gradle property `otelTestMode=true`; iOS `OTEL_TEST_MODE=1` at `pod install` (adds a Swift compilation condition). When on: JS IDs `0a…`, native IDs `0b…`, resource built from config only (no `telemetry.*`). Scenarios use explicit whole-µs timestamps from base **1767225600000000000 ns** (2026-01-01T00:00:00Z).
- Expected files: `verify/expected/<scenario>.shape.json` (hand-written, one per scenario) and `verify/expected/<scenario>.<platform>.otlp.json` (drafted with `--update`), platform ∈ `js | android | ios | web`, OTLP/JSON with hex IDs. `verify/` is behind `CODEOWNERS`. Any new or changed expected file needs the author's review before the task is done.
> Superseded during review: one `verify/expected/<scenario>.otlp.json` per scenario for every platform; no shape files. iOS's known opentelemetry-swift gaps (time rounding, unwritten flags/traceState/schemaUrl) are accepted in the compare step only.
- Fixture JSON encodes `NaN`, `Infinity`, `-Infinity`, `-0` as `{"$num": "<name>"}`.
- `e2e` pinned to `0.24.0`; CI sets `E2E_TELEMETRY_DISABLED=1`.

Expand Down
35 changes: 17 additions & 18 deletions docs/superpowers/specs/2026-11-10-rn-otel-design.md
Original file line number Diff line number Diff line change
Expand Up @@ -585,11 +585,12 @@ tests: they don't care about internals, so internals can be rewritten freely.

### 9.1 Scenarios and expected files are the spec
- **One scenario per guarantee, named after it.** `verify/scenarios/nest-after-await.ts`
pairs with `verify/expected/nest-after-await.<platform>.otlp.json`. The file name is the
pairs with `verify/expected/nest-after-await.otlp.json`. The file name is the
guarantee's ID; no separate registry or coverage check.
- Expected files are the exact **OTLP/JSON** payload (OTLP's JSON encoding: hex trace/span
IDs, not the generic protobuf JSON base64 mapping). Plain equality; valid OTLP that can be
POSTed to a collector or viewed in Jaeger as-is. Per-platform files are accepted.
POSTed to a collector or viewed in Jaeger as-is. **One file per scenario for every platform**
(JS, web, Android, iOS): OTLP is standardized and every platform must report the same.
Prior art: Collector goldens, upstream test hooks (§14 P17–P19).
- **Spec first:** the expected file is written (agent drafts, human reviews) before the code
that makes it pass. With explicit timestamps and sequential IDs, exact values are
Expand All @@ -600,8 +601,8 @@ tests: they don't care about internals, so internals can be rewritten freely.
flag for the bare and Expo apps; no test fields in the public API or the seam config:
- **explicit timestamps**: v0 scenarios create all spans themselves, so they pass
`startTime` / `end(t)` explicitly (JS and native), in whole microseconds. iOS cannot
represent them exactly: opentelemetry-swift exports `Date`, a ~238–256 ns grid, so the `ios`
files record the quantized values (R22, measured floor in verify/VERIFY.md). Clock stubs (Java `setClock`/`TestClock` in test source sets
represent them exactly: opentelemetry-swift exports `Date`, a ~238–256 ns grid, so iOS times
are compared within 256 ns (R22, measured floor in verify/VERIFY.md). Clock stubs (Java `setClock`/`TestClock` in test source sets
only; Swift `with(clock:)`) are only a fallback for implicit reads.
- sequential test ID generators, namespaced per side (JS `0a…01`, native `0b…01`) via
upstream hooks: JS `sdk-trace` `idGenerator`, Java `setIdGenerator`, Swift
Expand All @@ -611,15 +612,13 @@ tests: they don't care about internals, so internals can be rewritten freely.
is random). Reorders, never rewrites.
- concurrency scenarios are serialized deterministically (JS is single-threaded; native
spans in scenarios are started synchronously from JS).
- **Shape files and parity**: each scenario has one hand-written, reviewed
`verify/expected/<scenario>.shape.json` (trace partitions, span names, kinds, parent
links, link targets, status, attribute keys and types; no IDs or times). Every platform's
output is reduced to a shape and must equal it, so all platforms agree with each other by
construction. Shapes are written first; exact per-platform files are then drafted with
`--update` and reviewed (council review: hand-writing 30+ exact OTLP trees puts the bugs
in the expected files). Known v0 gap, accepted: opentelemetry-swift 2.6's OTLP encoder never
writes span/link `flags`, span/link `traceState` or the scope `schemaUrl`, so the `ios` files
lack them (shapes don't cover them; no encoder reimplementation, see verify/VERIFY.md).
- **Parity by construction**: every platform compares against the same file, so they agree
with each other. Files are drafted with `--update` and reviewed (council review:
hand-writing 30+ exact OTLP trees puts the bugs in the expected files). The one exception
is iOS, in a single function of the compare step: opentelemetry-swift 2.6 rounds times
(above) and its OTLP encoder never writes span/link `flags`, span/link `traceState` or the
scope `schemaUrl`, so those are not compared on iOS (no encoder reimplementation, see
verify/VERIFY.md). iOS never writes the shared file.

A scenario and its expected file, roughly:

Expand All @@ -636,7 +635,7 @@ export default scenario('nest-after-await', async ({ tracer, at }) => { // at(
```

```json
// verify/expected/nest-after-await.android.otlp.json (excerpt)
// verify/expected/nest-after-await.otlp.json (excerpt)
{ "resourceSpans": [{
"resource": { "attributes": [{ "key": "service.name", "value": { "stringValue": "verify" } }] },
"scopeSpans": [{
Expand All @@ -656,7 +655,7 @@ A failure, as an agent sees it:
```
✗ nest-after-await [android] span 0a00000000000002 "after_await"
parentSpanId expected 0a00000000000001 got (none)
expected: verify/expected/nest-after-await.android.otlp.json
expected: verify/expected/nest-after-await.otlp.json
actual: verify/artifacts/nest-after-await.android.otlp.json
scenario: verify/scenarios/nest-after-await.ts
```
Expand Down Expand Up @@ -697,14 +696,14 @@ flowchart LR
sc --> e2e["e2e: iOS / Android / web<br/>(every PR)"]
js --> fc
e2e --> fc
fc[("Fake collector<br/>OTLP → OTLP/JSON")] --> cmp{"exact compare<br/>+ parity shape"}
fc[("Fake collector<br/>OTLP → OTLP/JSON")] --> cmp{"exact compare<br/>(one file, all platforms)"}
exp[("verify/expected<br/>(CODEOWNERS)")] --> cmp
cmp --> out["structured diff<br/>+ verify/artifacts"]
```

- **Native cores are proven on devices:** the Kotlin and Swift cores have no host-side test
runs. The device e2e runs every scenario through the real seam and native core and compares
against the same `*.android` / `*.ios` expected files.
against the same expected file as JS and web.
- **Fake collector**: a small Node OTLP/HTTP receiver decoding protobuf with the official
`opentelemetry-proto` definitions and producing OTLP/JSON (GitHub macOS runners can't run
Docker, so no Collector image).
Expand Down Expand Up @@ -868,7 +867,7 @@ Left out until needed:
13. Trace-model rules: links for multi-cause renders, marked heuristic attribution (5).
14. Sequencing, with the real-RN-app context milestone first (8).
15. Test mode as a build flag; explicit whole-µs timestamps in scenarios; attribute/event
sorting; parity shape (9.1).
sorting; one expected file for all platforms (9.1).
16. Native cores proven by device e2e against the same expected files (9.2).
17. One endpoint meaning on every platform (the traces endpoint, used as given); returned handle `{ tracerProvider, forceFlush, shutdown }` (4.4).
18. No performance or compliance jobs in CI: the upstream OTLP exporters own the wire format; `example/collector/` runs the official Collector by hand (9.4).
Expand Down
50 changes: 24 additions & 26 deletions verify/VERIFY.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,18 @@ cd ../ios && OTEL_TEST_MODE=1 pod install && OTEL_TEST_MODE=1 xcodebuild -worksp
```

The Kotlin and Swift cores have no host-side test runs: the `e2e` stage runs every scenario on Android and iOS
through the real seam and native core and compares against `<name>.android.otlp.json` / `<name>.ios.otlp.json`.

**iOS time floor (R22).** opentelemetry-swift 2.6 keeps times as `Date` and exports
`UInt64(timeIntervalSince1970 * 1e9)`, so whole-µs seam times come back on a ~238–256 ns grid, truncated
(measured once over `at(0…10_000)` and `at(1_000_000_000)`: max |error| 240 ns, 314 of 10 002 exact).
`*.ios.otlp.json` record these quantized values as emitted (deterministic); shapes ignore times.

**iOS vs Android/JS goldens.** Apart from times, the `ios` files differ only by what the opentelemetry-swift 2.6 OTLP
encoder (`SpanAdapter`) never writes: span `flags` (257), span `traceState`, link `flags`, link `traceState`, and the
scope `schemaUrl` on `ScopeSpans`. The core passes them all into `SpanData`; the exporter drops them. Accepted for v0
(no encoder reimplementation); `rich-span` exercises span flags, link flags/traceState and the scope `schemaUrl`.
through the real seam and native core and compares against the scenario's one `<name>.otlp.json`.

**One expected file per scenario.** JS, web, Android and iOS report the same OTLP, so each scenario has one
`verify/expected/<name>.otlp.json`. iOS differs only by two opentelemetry-swift 2.6 gaps, which the compare step
(`iosView` in `harness/compare.ts`) accepts on `ios` and nowhere else:
- **Times (R22):** opentelemetry-swift keeps times as `Date` and exports `UInt64(timeIntervalSince1970 * 1e9)`, so
whole-µs seam times come back rounded to a ~238–256 ns grid, either way (measured once over `at(0…10_000)` and
`at(1_000_000_000)`: max |error| 240 ns, 314 of 10 002 exact). iOS times may be off by up to 256 ns.
- **Fields its OTLP encoder (`SpanAdapter`) never writes:** span `flags` (257), span `traceState`, link `flags`, link
`traceState`, and the scope `schemaUrl` on `ScopeSpans`. The core passes them all into `SpanData`; the exporter drops
them. Accepted for v0 (no encoder reimplementation); `rich-span` exercises all of them.
iOS never writes the shared file (`VERIFY_UPDATE`, draft): its rounded times are not the reference.

**iOS `TRACEPARENT` (upstream caveat).** opentelemetry-swift reads a `TRACEPARENT` environment variable at provider
construction and makes it the parent of every root span, even with `setNoParent()`. Apps only see it when launched with
Expand All @@ -49,11 +50,11 @@ it (Xcode scheme, `SIMCTL_CHILD_TRACEPARENT`).
except the scenarios with their own e2e file. Each test cold-starts the app (R5). e2e is compare-only;
On web, `forceFlush` latency follows the OTLP exporter's own retries (about 10 s worst case), not a native flush timeout; `collector-down` allows 10 s there.

`VERIFY_E2E_DRAFT=1` writes a **missing** `<name>.<platform>.otlp.json` from the device run and still fails the test
`VERIFY_E2E_DRAFT=1` writes a **missing** `<name>.otlp.json` from the run (never from iOS) and still fails the test
("drafted …, review it"); existing files are never overwritten. Draft runs have no retries, so a drafting run always ends red.
Each target compares to its platform's files (`android-*` → `android`, `ios-*` → `ios`, `web` → `web`): the bare app inits native
Every target compares to the same file: the bare app inits native
first (`RNOtel.start` in `MainApplication` / `AppDelegate`), the Expo app inits from JS (below), and ScenariosScreen
exports through `startReactNativeSdk` and the Kotlin or Swift core. One set of files for both apps is the proof that
exports through `startReactNativeSdk` and the Kotlin or Swift core. One file for both apps is the proof that
the two init paths are equivalent. A scenario that only one app can run names targets (`android-bare`) instead of
platforms in `targets`.

Expand Down Expand Up @@ -135,9 +136,8 @@ HybridObjects: no native `testMode` line, scenarios get no `native`).
- **Probe:** `babel-preset-expo` keeps native `async` on web; `example-expo/babel.config.js` adds the two async
plugins for the web platform, so the bundle has no native `async`/`for await`; no `com.callstack.context.degraded`
scope attribute in any web file.
- **Files:** every `*.web.otlp.json` is byte-identical to the scenario's `.js` file (`collector-down`, `handoff-basic`,
`odd-attributes` and `export-headers`, which have no `.js`, equal their `.android` file). The proto exporter and the web resource (`service.name` only in test mode)
change nothing visible.
- **Files:** web compares against the same `<name>.otlp.json` as every other platform, with no exceptions. The proto
exporter and the web resource (`service.name` only in test mode) change nothing visible.
- **collector-down:** the OTel JS exporter retries a 503 inside the export (backoff 1 s ×1.5, ±20 %), so the first
`flush` resolves after the three refusals (~4.7 s; up to 5.7 s): the web flush timeout is 10 s.
- **nest-timers-microtasks:** browsers have no `setImmediate`; there the `immediate` step is one more `setTimeout(0)`,
Expand Down Expand Up @@ -225,12 +225,12 @@ check before Task 27; fix the T3 host's Java (or run the check through an e2e te

## Scenarios

One file per guarantee in `verify/scenarios/`, named after it, with a hand-written `verify/expected/<name>.shape.json`
(the cross-platform parity contract). Exact `<name>.<platform>.otlp.json` files are drafted by the owning task with
`VERIFY_UPDATE=1` and reviewed by the author. `pending` scenarios report as `todo`; the owning task flips `pending` off.
One file per guarantee in `verify/scenarios/`, named after it, with one exact `verify/expected/<name>.otlp.json` that
every platform compares against. It is drafted with `VERIFY_UPDATE=1` (or `VERIFY_E2E_DRAFT=1` for e2e-only scenarios,
from Android or web) and reviewed by the author. `pending` scenarios report as `todo`; the owning task flips `pending` off.

Shapes use the JS runner's resource, `["service.name"]`. Native test mode builds the resource from config only and
the example inits with no `serviceVersion` (R2), so native-first device runs match the same shapes.
Every file uses the JS runner's resource, `service.name` only. Native test mode builds the resource from config only and
the example inits with no `serviceVersion` (R2), so native-first device runs match the same files.

e2e targets are android, ios and web unless the Runners column names them.

Expand Down Expand Up @@ -268,7 +268,5 @@ e2e targets are android, ios and web unless the Runners column names them.
Explicit `at(µs)` start/end times on every span; parents through `context.active()` (`startActiveSpan`), not
explicit parent contexts. `opts.runners` defaults to `['jest', 'e2e']`, `opts.targets` to
`['android', 'ios', 'web']` (platforms or target names like `android-bare`; the e2e harness skips other targets); `pending: true` until it passes.
2. Hand-write `verify/expected/<guarantee-id>.shape.json` in exactly `shapeOf()`'s format (traces ordered by first
span start, spans sorted by name, `kind` 1 = INTERNAL) and get it reviewed.
3. `bun verify` regenerates `verify/scenarios/index.ts`. Un-pend, draft the exact files with `VERIFY_UPDATE=1 bun verify`
(the shape must already match), have the author review them, then `bun verify` must be green.
2. `bun verify` regenerates `verify/scenarios/index.ts`. Un-pend, draft `<guarantee-id>.otlp.json` with
`VERIFY_UPDATE=1 bun verify`, have the author review it, then `bun verify` must be green.
74 changes: 0 additions & 74 deletions verify/expected/async-generator.ios.otlp.json

This file was deleted.

79 changes: 0 additions & 79 deletions verify/expected/async-generator.js.otlp.json

This file was deleted.

Loading
Loading