This LaunchDarkly observability plugin is currently available in Early Access, and APIs are subject to change until a 1.x version is released.
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.
LaunchDarkly’s SDKs are open source. In addition to this reference guide, we provide source, API reference documentation, and a sample application:
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.
The LaunchDarkly observability and session replay plugins for React Native target the following React Native and Expo versions:
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.
Follow these steps to get started:
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:
Then, import the plugin into your code:
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.
The React Native observability SDK uses a mobile key. Keys are specific to each project and environment. They are available on the SDK keys page under Settings. 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:
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:
For more information on plugin options, read Configuration for client-side observability.
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.
Add the session replay package as a dependency alongside the observability plugin:
After installing, run the iOS pod install step so that CocoaPods pulls in the native LaunchDarklyObservability and LaunchDarklySessionReplay frameworks:
Then, import the plugin into your code:
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.
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.
This approach allows you to:
The session replay plugin provides several privacy controls that decide whether each view is captured. Pass them to createSessionReplayPlugin or configureSessionReplay.
For each view, the SDK evaluates the following rules in order and stops at the first that applies:
<LDMask> or has a testID matched by maskTestIDs. The view is masked.<LDUnmask> or has a testID matched by unmaskTestIDs. The view is unmasked.maskTextInputs, maskLabels, maskImages, maskWebViews) apply.If two rules conflict at the same level, masking takes precedence over unmasking. An ancestor <LDMask> overrides any <LDUnmask> further down the tree.
Each global toggle affects every instance of the corresponding React Native component across your app, on both iOS and Android.
testIDUse maskTestIDs and unmaskTestIDs to target specific views by their testID property. Matches use exact string equality, so 'password' matches <View testID="password" /> but not <View testID="password_field" />. Both options work on iOS and Android.
<LDMask> and <LDUnmask>Use the <LDMask> and <LDUnmask> wrapper components to redact a subtree without giving it a testID. <LDMask> propagates to all descendants. After you wrap a subtree in <LDMask>, nothing inside it can opt out of masking.
The SessionReplayOptions object supports the following parameters:
true. Set to false to start recording manually with startSessionReplay()."sessionreplay-react-native".<TextInput> components. Defaults to true.<WebView> components. When enabled, web views are rendered as blank rectangles in session replays. Defaults to false.<Text> components. Defaults to false.<Image> components. Defaults to false.testID values. Matches use exact string equality. Applied on iOS and Android.testID values from masking. Matches use exact string equality. Applied on iOS and Android.0.02. iOS only.For more information on session replay configuration, read Configuration for session replay.
The observability plugin supports the following features. After the SDK and plugins are initialized, you can access these from within your application:
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.