Instrumentation
What a React Native app captures with no code — native crashes, ANRs, network, lifecycle — what initialize adds for JavaScript errors and promise rejections, what each add-on package records, and where Android and iOS differ.
Telemetry from a React Native app comes from three layers. The native SDKs capture what the operating system can see. initialize adds what only JavaScript can see: exceptions and promise rejections. The optional packages add spans for things only your code knows about — screens, Redux actions and custom operations.
At a glance
| Source | What it records | Needs |
|---|---|---|
| Native SDK | Crashes, ANRs, network requests, app startup, sessions, native screens, taps, WebView loads, low power and memory | The native setup only |
initialize | Unhandled JS exceptions, React component stacks, unhandled promise rejections (opt-in), React Native and SDK versions | initialize called once |
| Your calls | Logs, handled errors, breadcrumbs, session properties, user identifier, manually recorded requests | API |
@sophonz/react-native-tracer-provider | Spans you create with the OpenTelemetry API | OpenTelemetry |
@sophonz/react-native-navigation | A ux.view span per screen | Navigation |
@sophonz/react-native-redux | A sys.rn_action span per dispatched action | Redux |
@sophonz/react-native-otlp | Nothing new; sends the same telemetry to another backend | OTLP |
Captured by the native SDKs
These run whether or not JavaScript calls anything, as soon as the SDK is started. The full lists, with the spz.type each one attaches and how to switch it off, are in Android instrumentation and iOS instrumentation.
| Signal | Android | iOS |
|---|---|---|
| Crashes | JVM crashes (sys.android.crash), native crashes including Hermes (sys.android.native_crash), app exit info on Android 11+ | KSCrash-based reporter (sys.ios.crash), MetricKit crash reports |
| Unresponsive app | ANR detection (perf.thread_blockage) | Hang detection is off by default and can only be turned on in native code |
| Network | OkHttp, which React Native's fetch and XMLHttpRequest use, instrumented at build time | URLSession, which React Native's networking uses |
| Startup | App startup trace | sys.startup span |
| Screens | Activities (ux.view) | UIViewControllers (ux.view, perf.ui_load) |
| Taps, WebViews | As for a native app; see the platform page | Screen taps, WebView loads |
| Device state | Power save mode, connectivity changes | Low power mode, memory warnings |
A crash in native code is captured even before JavaScript loads, but only when the SDK was started natively (MainApplication, AppDelegate). Started from initialize, the SDK sees only what happens after the JavaScript bundle runs.
Native screens in a React Native app
Native screen capture records the containers the operating system knows about, not your JavaScript routes. On Android a React Native app is usually a single MainActivity, so the screen timeline shows one screen for the whole session. On iOS it shows whatever view controllers the navigation library creates. To see route names, add @sophonz/react-native-navigation, and consider turning native capture off so the two do not interleave:
- Android:
"view_config": {"enable_automatic_activity_capture": false}insidesdk_config - iOS:
ios.disableAutomaticViewCapture: trueinsdkConfig, or removeViewCaptureServicein native code
Sessions and lifecycle
Sessions belong to the native SDK. A session ends when the app goes to the background and a new one starts when it returns, so a JavaScript app sees the same session boundaries as a native one. getCurrentSessionId() returns the current id and endSession() forces a boundary.
On iOS telemetry is uploaded when a session part ends — backgrounding, or the next launch — not on a timer.
JavaScript errors
initialize wraps React Native's global handler (ErrorUtils.setGlobalHandler). For every uncaught exception it:
- logs the React component stack as a separate ERROR log, if the error carries one
- keeps the first 200 lines of the stack trace
- sends the exception to the native SDK
- calls the previous handler 150 ms later, so React Native's own behaviour — the red box in development, a crash in release for fatal errors — is unchanged
| Android | iOS | |
|---|---|---|
| Recorded as | A typed React Native crash log | An ERROR log |
| Attributes | JS stack trace, exception name, message and type | exception.type, exception.message, exception.id, spz.exception_handling: unhandled, the JS stack in spz.ios.react_native_crash.js_exception |
The iOS form follows from the public API of the Apple SDK, which cannot record a typed crash log from outside the SDK. Filter by client.platform when a dashboard mixes both.
When a fatal error then crashes a release build, the native crash reporter records that crash as well. On iOS the crash report carries the crash info key spz-js with the same value as the log's exception.id, so the two can be matched.
CAUTION — Throw Error objects
Only values that are instanceof Error are handled. For anything else, such as throw "text", the handler prints [Sophonz] error must be of type Error and returns without logging and without calling the previous handler, so React Native's red box or crash does not happen either.
Unhandled promise rejections
Off by default. Turn it on with trackUnhandledRejections:
await initialize({sdkConfig: {trackUnhandledRejections: true}});The tracker attaches to Hermes's own promise implementation when Hermes provides one, and to React Native's promise polyfill otherwise. Each unhandled rejection becomes an ERROR log with the message Unhandled promise rejection: <message> and, when the rejection value is an Error, its stack trace. If the promise is handled later, the log already sent stays.
This option still applies when the SDK was started natively.
Error boundaries
React does not send errors caught by an error boundary to the global handler. Record them yourself. logIfComponentError records the component stack; logHandledError records the JS stack.
import React from "react";
import {logHandledError, logIfComponentError} from "@sophonz/react-native";
class ErrorBoundary extends React.Component<{children: React.ReactNode}, {failed: boolean}> {
state = {failed: false};
static getDerivedStateFromError() {
return {failed: true};
}
componentDidCatch(error: Error, info: React.ErrorInfo) {
logHandledError(error, {boundary: "root"});
logIfComponentError(Object.assign(error, {componentStack: info.componentStack}));
}
render() {
return this.state.failed ? null : this.props.children;
}
}Handled errors and logs
Everything else is explicit: logHandledError for caught exceptions, logInfo, logWarning, logError and logMessage for logs, addBreadcrumb for lightweight timeline events. Warning and error logs carry the JavaScript stack of the call site in spz.stacktrace.rn unless you pass includeStacktrace = false. Details are in the API reference.
Versions and bundle
initialize records the React Native version, the @sophonz/react-native version and, when given, patch. On iOS release builds it also hashes main.jsbundle into a bundle identifier, so you can tell which bundle an error came from after an over-the-air update.
On Android these go to the SDK's React Native interface and are reported as resource attributes. On iOS they are process-lifespan properties named hosted_platform_version, hosted_sdk_version, javascript_patch_number and react_native_bundle_id, so they appear with the session properties instead.
Screen orientation
useOrientationListener adds a breadcrumb with the starting orientation and one each time it changes between portrait and landscape.
import {useOrientationListener, useSophonz} from "@sophonz/react-native";
const {isStarted} = useSophonz(SOPHONZ_CONFIG);
useOrientationListener(isStarted);WebViews
A web page running the Sophonz browser SDK inside a WebView can join the app's session. getCurrentSessionId() returns the id in the exact form it has on the wire, 32 lowercase hex characters, so it can be handed to the page unchanged. How the page reads it is described in WebView integration.
Platform differences
| Behaviour | Android | iOS |
|---|---|---|
| Configuration from JavaScript | None; sophonz-config.json only | sdkConfig.ios |
| Unhandled JS exception | Typed React Native crash log | ERROR log with exception.* |
| Hang or ANR detection | On | Off; native opt-in only |
traceparent on captured requests | Off; opt in with enable_traceparent_injection | On for every host unless disableNetworkSpanForwarding |
| URL exclusion | networking.disabled_url_patterns, regular expressions | disabledUrlPatterns, substrings |
| React Native version, JS patch, bundle id | Resource attributes | Process-lifespan properties |