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

SourceWhat it recordsNeeds
Native SDKCrashes, ANRs, network requests, app startup, sessions, native screens, taps, WebView loads, low power and memoryThe native setup only
initializeUnhandled JS exceptions, React component stacks, unhandled promise rejections (opt-in), React Native and SDK versionsinitialize called once
Your callsLogs, handled errors, breadcrumbs, session properties, user identifier, manually recorded requestsAPI
@sophonz/react-native-tracer-providerSpans you create with the OpenTelemetry APIOpenTelemetry
@sophonz/react-native-navigationA ux.view span per screenNavigation
@sophonz/react-native-reduxA sys.rn_action span per dispatched actionRedux
@sophonz/react-native-otlpNothing new; sends the same telemetry to another backendOTLP

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.

SignalAndroidiOS
CrashesJVM 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 appANR detection (perf.thread_blockage)Hang detection is off by default and can only be turned on in native code
NetworkOkHttp, which React Native's fetch and XMLHttpRequest use, instrumented at build timeURLSession, which React Native's networking uses
StartupApp startup tracesys.startup span
ScreensActivities (ux.view)UIViewControllers (ux.view, perf.ui_load)
Taps, WebViewsAs for a native app; see the platform pageScreen taps, WebView loads
Device statePower save mode, connectivity changesLow 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} inside sdk_config
  • iOS: ios.disableAutomaticViewCapture: true in sdkConfig, or remove ViewCaptureService in 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:

  1. logs the React component stack as a separate ERROR log, if the error carries one
  2. keeps the first 200 lines of the stack trace
  3. sends the exception to the native SDK
  4. 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
AndroidiOS
Recorded asA typed React Native crash logAn ERROR log
AttributesJS stack trace, exception name, message and typeexception.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

BehaviourAndroidiOS
Configuration from JavaScriptNone; sophonz-config.json onlysdkConfig.ios
Unhandled JS exceptionTyped React Native crash logERROR log with exception.*
Hang or ANR detectionOnOff; native opt-in only
traceparent on captured requestsOff; opt in with enable_traceparent_injectionOn for every host unless disableNetworkSpanForwarding
URL exclusionnetworking.disabled_url_patterns, regular expressionsdisabledUrlPatterns, substrings
React Native version, JS patch, bundle idResource attributesProcess-lifespan properties