Skip to content

spec: metrics hand off from JS to native, as spans do - #34

Merged
adhorodyski merged 2 commits into
v0from
design/metrics
Nov 30, 2026
Merged

adhorodyski merged 2 commits into
v0from
design/metrics

Conversation

@adhorodyski

@adhorodyski adhorodyski commented Nov 26, 2026 •

Copy link
Copy Markdown
Collaborator

Design only; nothing is implemented. Metrics are built separately after v0 and don't block 0.3.0.

What changes in the spec

  • §4.4 config: exportConfig.url is replaced by one URL per signal: exportConfig: { headers, traces: { url, headers }, metrics: { url, headers } }.
    • A signal is on when its URL is set.
    • Headers set for a signal are merged over the shared ones and win on the same key.
    • This is the only breaking change, so it should land in 0.3.0 even if metrics ship later.
    • Metrics are cumulative only; there's no temporality option yet.
  • §4.6 metrics (new):
    • JS aggregates, native exports, as for spans. JS uses stock sdk-metrics. On mobile our HandOffMetricExporter passes the points to native through a new exportMetrics(SeamMetric[]) call, once per export interval (60 s) or flush. Web keeps the stock OTLPMetricExporter.
    • Native metrics: a stock MeterProvider with PeriodicMetricReader in each native core, used through RNOtel.meter. One OtlpHttpMetricExporter exports both JS and native metrics, with native's resource, URL and headers.
    • SeamInitResult is unchanged. JS never holds the resource, URL or headers.
    • Turning JS points into native metric data:
      • Android: JsMetricData, built like JsSpanData, with otel-java's public point and data factories.
      • iOS: the SDK's own constructors, from our fork of opentelemetry-swift-core 2.6.0. The fork only makes 14 lines public; they're internal upstream.
    • Proven end to end on the pinned versions: JS hand-off, then the conversion on both cores, then the stock exporter, then a fake collector decoding everything under the native resource.
    • Build check: the fork and upstream core resolve to the same SwiftPM package name. This has to be verified in the bare and Expo apps under CocoaPods first.
    • No per-measurement seam calls. JS and native never share an instrument.
    • No requests when idle: all three readers skip empty exports.
    • Best effort: the JS background flush, and up to 60 s of JS points lost on a reload. Spans are unaffected.
    • Rejected, with reasons:
      • JS exporting metrics itself on mobile (the first draft of this PR).
      • Native as the only writer behind a JS shim.
      • Building iOS metric data through the public Codable decoder.
      • Raw OTLP bytes from JS.
      • A temporality option.
      • 0.2's model.
  • §9.6 verification (new):
    • a /v1/metrics route on the fake collector
    • one <name>.metrics.otlp.json expected file per scenario; a scenario without one must export no metrics
    • data-point times stripped by the normalizer
    • scenarios: metrics-js, metrics-native, metrics-headers, metrics-off, and background-flush extended to native metrics
  • §2, §10: status and backlog updated, including the temporality option and dropping the fork later.

Open questions (§4.6.9)

  1. Should native add service.instance.id per process start for fleet identity, or should we only document it?
  2. Expose the export interval now, or wait for a request?

🤖 Generated with Claude Code

JS metrics use stock sdk-metrics and export from JS on every platform; native
metrics use the native SDK and RNOtel.meter. Both read exportConfig.metrics,
and native hands JS its resource and merged metrics config through the
initialize result. Nothing crosses the seam per measurement.

Also replaces exportConfig.url with one URL per signal (traces, metrics) and
shared plus per-signal headers.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@adhorodyski adhorodyski mentioned this pull request Nov 26, 2026
@adhorodyski adhorodyski added this to the Alpha milestone Nov 26, 2026
JS aggregates with stock sdk-metrics and hands its points to native through
exportMetrics; native exports JS and native metrics with one
OtlpHttpMetricExporter under its own resource, URL and headers. JS no longer
needs the resource or metrics config, so SeamInitResult is unchanged.

Android builds MetricData from otel-java's public factories. iOS uses a fork of
opentelemetry-swift-core 2.6.0 that makes the metric data constructors public
(access levels only). Metrics are cumulative only; temporalityPreference is
dropped until asked.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@adhorodyski adhorodyski changed the title spec: metrics as two independent pipelines from one config spec: metrics hand off from JS to native, as spans do Nov 30, 2026
@adhorodyski
adhorodyski merged commit 7da98df into v0 Nov 30, 2026
6 checks passed
@adhorodyski
adhorodyski deleted the design/metrics branch November 30, 2026 16:56
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