This topic documents how to get started with the LaunchDarkly observability plugins for the React Web SDK.
The React Web SDK supports the following observability plugins:
LaunchDarkly’s SDKs are open source. In addition to this reference guide, we provide source, API reference documentation, and a sample application:
These observability and session replay plugins are for the LaunchDarkly client-side JavaScript-based SDKs.
To learn more about LaunchDarkly’s different SDK types, read Choosing an SDK type.
This reference guide assumes that you are somewhat familiar with the LaunchDarkly React Web SDK.
The observability plugin is compatible with the React Web SDK, version 3.7.0 and later.
LaunchDarkly does not offer SDKs for all languages or frameworks. If you’re using another framework, such as Angular, Remix, or Svelte, you may be able to use the JavaScript SDK instead. Install the observability plugins and initialize them when you initialize the client for the JavaScript SDK.
To request support for a specific language or framework, start a Support ticket.
Follow these steps to get started:
LaunchDarkly uses plugins to the React Web SDK to provide observability. Most customers use both the observability and session replay plugins. However, there is no dependency between them, and you can use only one or the other if you like.
The first step is to make both the SDK and the observability plugins available as dependencies.
Here’s how:
Then, import the plugin into your code:
Next, initialize the SDK and the plugins.
To initialize, you need your LaunchDarkly environment’s client-side ID. This authorizes your application to connect to a particular environment within LaunchDarkly. To learn more, read Initialize the client in the React Web SDK reference guide.
The React Web observability SDK requires a client-side ID. Client-side IDs are specific to each project and environment. They are not secret, and you can include them in client-side code. Do not embed a server-side SDK key in a client-side application.
You can find client-side IDs and project keys on the SDK keys page under Settings. To learn more about key types, read Keys.
You can initialize the observability plugins either at the same time you initialize the SDK, or afterwards.
Here’s how to initialize the SDK and plugins:
You can initialize the observability and session replay plugins manually, after the SDK client is initialized.
This approach supports feature-flagged rollouts or dynamic initialization after end user consent. Both plugins use a manualStart option combined with .start() calls.
First, configure the plugins with manualStart: true:
Then, start the plugins when appropriate, such as after receiving end user consent or when a feature flag enables observability.
Here’s an example starting the observability plugin:
Here’s an example with the session replay plugin:
This approach allows you to:
You can configure options for the observability plugins when you initialize the SDK. The plugin constructors take an optional object with the configuration details.
By default, session replays use the strict privacy setting, which obscures some data. Use none to turn off session replay obfuscation. This enables more detail on session replays, but may expose more of your customer data than your privacy or data retention policies allow. To learn more, read Session replay config.
Here is an example:
Set tracingOrigins correctly for your use case
In most cases, you should set tracingOrigins to the URI of the backend API of your application. To learn more, read Fullstack mapping.
For more information on plugin options, read Configuration for client-side observability and Configuration for session replay.
If your application runs in an environment that enforces content security policies, you must set the Content-Security-Policy (CSP) in your application to tell the browser how your page can interact with third-party scripts.
Here are the policies you need to set to use the observability plugin:
connect-src: https://pub.observability.app.launchdarkly.com https://otel.observability.app.launchdarkly.com: This policy allows connecting with LaunchDarkly servers to send recorded observability data.worker-src: data: blob:: This policy allows creating an inline web worker initialized by the npm package for this plugin.Your CSP definition may look something like this:
Alternatively, you can set the CSP in the HTML document response header Content-Security-Policy. Check your initial app HTML document load for the header to make sure you are setting it to the desired value.
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 plugins, your application automatically starts sending observability data back to LaunchDarkly in the form of custom events. You can review this information in the LaunchDarkly user interface. To learn how, read Observability.
Specifically, the observability data includes events that LaunchDarkly uses to automatically create the following metrics:
To learn more, read Observability autogenerated metrics.