@open-infra/telemetry-mobile
v0.2.0
Published
React Native safe explicit-fetch tracing with OpenInfra lifecycle, consent, privacy, and bounded OTLP export.
Maintainers
Readme
@open-infra/telemetry-mobile
An explicit-fetch tracing runtime for Expo and React Native. It uses OpenInfra's lifecycle, consent controller, privacy policy, and final OTLP export boundary. It does not load browser DOM instrumentation or Node server instrumentation, or register a global provider.
import { createMobileTelemetry } from '@open-infra/telemetry-mobile';
const telemetry = createMobileTelemetry({
serviceName: 'mobile-app',
endpoint: 'https://telemetry.example.com',
allowedOrigins: ['https://api.example.com'],
});
await telemetry.start();
await telemetry.setConsent('granted'); // After the application's consent decision.
telemetry.recordLifecycle('mobile.startup');
await telemetry.fetch('https://api.example.com/orders');
await telemetry.forceFlush();
await telemetry.shutdown();Collection is disabled until consent is granted. Request bodies and query-string values are excluded. Trace headers are sent only to explicitly allowed origins; baggage is never injected. Queues and exporter timeouts are bounded. Credentials in public collector URLs are rejected. Each runtime has a one-shot lifecycle; construct a new instance after shutdown.
Version 0.2 adds opt-in logs and metrics: pass logs: true and/or metrics: true to use the same collector base with /v1/logs and /v1/metrics. Call runtime.logger?.info(...), runtime.telemetryMetrics?.counter(...) or .histogram(...) after startup. Signals share consent/redaction and final export filtering; logs have a 512-record queue, and metrics have bounded instrument/cardinality budgets. Logs/metrics remain off by default for compatibility.
Use instrumentMobileAppState(runtime, AppState) with React Native's AppState to collect deduplicated active/inactive/background changes and flush in the background. Call the returned unsubscribe function during application cleanup. Call runtime.recordScreen('/orders/[id]') from the navigation framework's route-change callback; pass a route template rather than actual user IDs. No React Native runtime dependency is loaded by the SDK.
Native crash collection and device profiling are not implemented. AppState bindings and JavaScript exports do not establish native device qualification.
