React Native SDK observability reference

This LaunchDarkly observability plugin is available for early access

This LaunchDarkly observability plugin is currently available in Early Access, and APIs are subject to change until a 1.x version is released.

Overview

This topic documents how to get started with the LaunchDarkly observability plugin for the React Native SDK.

The React Native SDK supports the observability plugin for error monitoring, logging, and tracing, and the session replay plugin for capturing screen recordings of user sessions.

SDK quick links

LaunchDarkly’s SDKs are open source. In addition to this reference guide, we provide source, API reference documentation, and a sample application:

ResourceLocation
SDK API documentationObservability plugin API docs
GitHub repository (observability)@launchdarkly/observability-react-native
Published module (observability)npm
GitHub repository (session replay)@launchdarkly/session-replay-react-native
Published module (session replay)npm

Prerequisites and dependencies

This reference guide assumes you are familiar with the LaunchDarkly React Native SDK.

The observability plugin requires React Native SDK version 10.10.0 or later.

The React Native SDK version 10.x is compatible with Expo. Only iOS and Android platforms are supported. Web is not supported.

Supported React Native and Expo versions

The LaunchDarkly observability and session replay plugins for React Native target the following React Native and Expo versions:

FrameworkSupported versions
React Native0.74, 0.76, 0.79, 0.81, 0.83
Expo51, 52, 53, 54

Not all React Native and Expo versions have been explicitly tested with the observability and session replay plugins, as both are in Early Access. New React Native and Expo releases are expected to work; if you run into an issue, please file an issue on GitHub.

Get started

Follow these steps to get started:

Install the plugin

LaunchDarkly uses a plugin to the React Native SDK to provide observability.

The first step is to make both the SDK and the observability plugin available as dependencies.

Here’s how:

$ npm install @launchdarkly/react-native-client-sdk
$ npm install @launchdarkly/observability-react-native

Then, import the plugin into your code:

Import, React Native SDK v10.10+
1import { ReactNativeLDClient } from '@launchdarkly/react-native-client-sdk';
2import { Observability, LDObserve } from '@launchdarkly/observability-react-native';

Initialize the client

Next, initialize the SDK and the plugin.

To initialize, you need your LaunchDarkly environment’s mobile key. This authorizes your application to connect to a particular environment within LaunchDarkly. To learn more, read Initialize the client and identify a context in the React Native SDK reference guide.

React Native observability SDK credentials

The React Native observability SDK uses a mobile key. Keys are specific to each project and environment. They are available from Project settings, on the Environments list. To learn more about key types, read Keys.

Mobile keys are not secret and you can expose them in your client-side code without risk. However, never embed a server-side SDK key into a client-side application.

Here’s how to initialize the SDK and plugin:

Initialize, React Native SDK v10.10+
1const client = new ReactNativeLDClient(
2 'example-mobile-key',
3 AutoEnvAttributes.Enabled,
4 {
5 plugins: [
6 new Observability()
7 ],
8 }
9);

Configure the plugin options

You can configure options for the observability plugin when you initialize the SDK. The plugin constructor takes an optional object with the configuration details.

Here is an example:

Plugin options, React Native SDK v10.10+
1const client = new ReactNativeLDClient(
2 'example-mobile-key',
3 AutoEnvAttributes.Enabled,
4 {
5 plugins: [
6 new Observability({
7 serviceName: 'example-service',
8 // we recommend setting service_version to the latest deployed git SHA
9 serviceVersion: 'example-sha'
10 })
11 ],
12 }
13);

For more information on plugin options, read Configuration for client-side observability.

Configure session replay

Session replay is in Early Access

Session replay for React Native is available in Early Access. APIs are subject to change until a 1.x version is released.

Session replay captures screen recordings of user interactions to help you understand how users interact with your application. Session replay is delivered as a separate plugin, @launchdarkly/session-replay-react-native, that works alongside the observability plugin.

Session replay for React Native is supported on iOS and Android.

Install the session replay plugin

Add the session replay package as a dependency alongside the observability plugin:

$npm install @launchdarkly/session-replay-react-native

After installing, run the iOS pod install step so that CocoaPods pulls in the native LaunchDarklyObservability and LaunchDarklySessionReplay frameworks:

iOS
$cd ios && pod install

Then, import the plugin into your code:

Import
1import { createSessionReplayPlugin } from '@launchdarkly/session-replay-react-native';

Initialize session replay

To enable session replay, create the session replay plugin and add it to the plugins list passed to ReactNativeLDClient. You can use session replay on its own, or alongside the observability plugin.

Initialize with session replay
1import {
2 ReactNativeLDClient,
3 AutoEnvAttributes,
4} from '@launchdarkly/react-native-client-sdk';
5import { Observability } from '@launchdarkly/observability-react-native';
6import { createSessionReplayPlugin } from '@launchdarkly/session-replay-react-native';
7
8const sessionReplay = createSessionReplayPlugin({
9 isEnabled: true,
10 maskTextInputs: true,
11 maskWebViews: true,
12 maskLabels: true,
13 maskImages: true,
14});
15
16const client = new ReactNativeLDClient(
17 'example-mobile-key',
18 AutoEnvAttributes.Enabled,
19 {
20 plugins: [
21 new Observability({ serviceName: 'example-service' }),
22 sessionReplay,
23 ],
24 }
25);

Initialize session replay manually

You can initialize the session replay plugin manually, after the SDK client is initialized. This approach is useful for feature-flagged rollouts, or for deferring data collection until after you have received end user consent.

Set isEnabled to false in the plugin options, then call startSessionReplay() when you are ready to begin recording.

As an alternative to registering session replay as a plugin, you can control it imperatively. You use the lower-level configureSessionReplay() and startSessionReplay() functions without registering a plugin at all.

1import { createSessionReplayPlugin, startSessionReplay, stopSessionReplay } from '@launchdarkly/session-replay-react-native';
2
3const sessionReplay = createSessionReplayPlugin({
4 isEnabled: false, // don't start recording automatically
5 maskTextInputs: true,
6});
7
8const client = new ReactNativeLDClient(
9 'example-mobile-key',
10 AutoEnvAttributes.Enabled,
11 { plugins: [sessionReplay] }
12);
13
14// Later, after user consent or a feature flag check:
15await startSessionReplay();
16
17// To stop recording:
18await stopSessionReplay();

This approach allows you to:

  • Feature-flag the rollout of session replay to a subset of end users
  • Wait for end user consent before starting data collection
  • Dynamically enable session replay based on runtime conditions
  • Maintain compliance with privacy regulations

Configure session replay privacy options

The session replay plugin provides privacy options to control what data is captured. Pass them to createSessionReplayPlugin or configureSessionReplay:

Session replay privacy options
1const sessionReplay = createSessionReplayPlugin({
2 isEnabled: true,
3 serviceName: 'my-react-native-app',
4 maskTextInputs: true,
5 maskWebViews: false,
6 maskLabels: false,
7 maskImages: false,
8 maskAccessibilityIdentifiers: ['email-field', 'password-field'],
9 unmaskAccessibilityIdentifiers: ['public-label'],
10 ignoreAccessibilityIdentifiers: ['debug-view'],
11 minimumAlpha: 0.02,
12});

Session replay configuration options

The SessionReplayOptions object supports the following parameters:

  • isEnabled: Controls whether recording starts automatically when the plugin registers. Defaults to true. Set to false to start recording manually with startSessionReplay().
  • serviceName: The service name used for session replay telemetry. Defaults to "sessionreplay-react-native".
  • maskTextInputs: Masks all text input fields. Defaults to true.
  • maskWebViews: Masks the contents of web views. When enabled, web views are rendered as blank rectangles in session replays. Defaults to false.
  • maskLabels: Masks all text labels. Defaults to false.
  • maskImages: Masks all images. Defaults to false.
  • maskAccessibilityIdentifiers: Array of accessibility identifiers (iOS) or testID values to mask. Use this to mask specific UI elements. iOS only.
  • unmaskAccessibilityIdentifiers: Array of accessibility identifiers to exclude from default masking rules. iOS only.
  • ignoreAccessibilityIdentifiers: Array of accessibility identifiers to ignore entirely so that neither their layout nor their contents are captured. iOS only.
  • minimumAlpha: Minimum alpha value for view visibility in recordings. Views with alpha below this threshold are not captured. Defaults to 0.02. iOS only.
Platform-specific masking

maskAccessibilityIdentifiers, unmaskAccessibilityIdentifiers, ignoreAccessibilityIdentifiers, and minimumAlpha are currently applied on iOS only. On Android, the same options are accepted but have no effect — use maskTextInputs, maskLabels, maskImages, and maskWebViews for cross-platform masking.

In React Native, the testID prop is rendered as the iOS accessibilityIdentifier, so values you pass to maskAccessibilityIdentifiers typically match the testID values on your components.

For more information on session replay configuration, read Configuration for session replay.

Explore supported features

The observability plugin supports the following features. After the SDK and plugins are initialized, you can access these from within your application:

Review observability data in LaunchDarkly

After you initialize the SDK and observability plugin, your application automatically starts sending observability data back to LaunchDarkly, including errors and logs. You can review this information in the LaunchDarkly user interface. To learn how, read Observability.