This topic documents how to get started with the LaunchDarkly observability plugins for the client-side JavaScript SDK.
The JavaScript 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.
We strongly recommend that any customers who are using LaunchDarkly’s browser-telemetry integration now use this observability plugin instead.
As we develop additional telemetry-related functionality, we will only be adding it to this observability plugin.
This reference guide assumes that you are somewhat familiar with the LaunchDarkly JavaScript SDK.
The observability plugin is compatible with the JavaScript 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 JavaScript 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 and, in some versions, the context for which you want to evaluate flags. This authorizes your application to connect to a particular environment within LaunchDarkly. To learn more, read Initialize the client in the JavaScript SDK reference guide.
The JavaScript 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:
For more information on plugin options, read Configuration for client-side observability and Configuration for session replay.
By default, the JavaScript client-side SDK observability plugin automatically records these product analytics events as OpenTelemetry span events:
track() method. The OpenTelemetry span events for track() calls include the URL and metric event key, as well as any optional numeric value provided for a numeric event.All of the above OpenTelemetry span events also include information about the LaunchDarkly context that generated the event.
You can use the generated span events to create custom product analytic charts, such as time series and funnels. You can also view the raw span data directly from the observability Traces view. To learn more, read Traces.
Use the productAnalytics: false setting in plugin options to disable collecting product analytics events, or specify individual event types to exclude.
Here is an example:
The JavaScript client observability plugin generates the product analytics span events by default. You only need to include productAnalytics in your plugin configuration if you want to disable collecting some or all events.
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.