Skip to main content

React Native and Expo

Use @aient/otel-browser/react-native in the JavaScript bootstrap for your iOS and Android app. The SDK sends OTLP traces and logs to Aient using native fetch. It has no native module installation step. The native entry point requires Metro package exports, which React Native enables by default starting with 0.79. Aient tested Expo 57 with React Native 0.86.3 and Hermes.

Install

Configure the app bootstrap

Use the app’s existing build configuration and initialize one sender per JavaScript runtime. In Expo, read the EXPO_PUBLIC_* values with static property access so Metro inlines them. In bare React Native, supply the same options through your existing build configuration.
Import this module from the native entry point before registering app and background tasks. Reuse the same module in headless tasks and await a best-effort forceFlush() before returning from short-lived work. The OS can suspend the runtime before the request finishes. Use shutdown() when disposing of the sender. Use a publishable ingest key for the target Aient environment. Anything under EXPO_PUBLIC_ is visible in the app bundle. Keep upload keys and other credentials in CI. Set the full Git commit of the code in each native build and each OTA update in EXPO_PUBLIC_COMMIT_SHA, along with its branch and environment. Use the Git commit of the OTA bundle when an update replaces the embedded bundle.

Record work and errors

Use the SDK’s scoped tracer and logger in your application code. Pass context explicitly when correlating logs and child spans across asynchronous work.
Bridge your existing logger and JavaScript error-reporting callbacks where appropriate. Call captureException once for each error you want Aient to receive. It emits an error log with the JavaScript stack and marks a supplied span as failed. Existing crash reporters can continue to handle native crashes. The SDK instruments the operations you wire into it and exports their traces and logs. Retain the matching Metro/Hermes source maps for each artifact in your release pipeline. Aient receives the raw JavaScript stack from this SDK.

Verify

Run the app in a simulator or on a device with your preview environment key. Trigger a traced operation and a handled JavaScript exception, then flush. Check Aient for the service, release commit and both records. The exception log and its span should have the same trace ID. Repeat for each app entry point that runs in a separate JavaScript runtime.