JavaScript SDK observability reference
The LaunchDarkly observability features are available for early access
Observability features in the LaunchDarkly UI are publicly available in early access.
The SDK observability plugins are designed for use with the in-app observability features. They are currently in available in Early Access and APIs are subject to change until a 1.x version is released.
If you are interested participating in the Early Access Program for upcoming observability plugins for additional SDKs, sign up here.
Overview
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:
- An Observability plugin for error monitoring, logging, and tracing.
- A Session replay plugin that provides a way to record and replay end-user sessions from your application.
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:
For use in client applications only
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 Client-side, server-side, and edge SDKs.
The observability plugin replaces the JavaScript telemetry integration
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.
Prerequisites and dependencies
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.
Do you need information about Angular, Remix, Svelte, or other frameworks?
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.
Get started
Follow these steps to get started:
- Install the plugins
- Initialize the JavaScript SDK client
- Configure the plugin options
- Explore supported features
- Review observability data in LaunchDarkly
Install the plugins
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:
Initialize the client
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 JavaScript SDK reference guide.
You can initialize the observability plugins either at the same time you initialize the SDK, or afterwards.
Initialize SDK client and plugins together
Here’s how to initialize the SDK and plugins:
Initialize the plugins after the SDK client
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:
- Feature-flag the rollout of observability to a subset of end users
- Wait for end user consent before starting data collection
- Dynamically enable observability based on runtime conditions
- Maintain compliance with privacy regulations
Configure the plugin options
You can configure options for the observability plugins when you initialize the SDK. The plugin constructors take an optional object with the configuration details.
Here is an example:
For more information on plugin options, read Configuration for client-side observability and Configuration for session replay.
Set Context-Security-Policy (CSP)
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 inlined web worker initialized by thenpm
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.
Explore supported features
The observability plugins supports the following features. After the SDK and plugins are initialized, you can access these from within your application:
- Configuration for client-side observability
- Configuration for session replay
- Errors
- Logs
- Metrics
- Tracing
Review observability data in LaunchDarkly
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:
- Average, P95, and P99 Cumulative Layout Shift (CLS) per context (LaunchDarkly)
- Average, P95, and P99 Document Load Latency per context (LaunchDarkly)
- Percentage of users with errors (LaunchDarkly)
- Average, P95, and P99 First Contentful Paint (FCP) per context (LaunchDarkly)
- Average, P95, and P99 First Input Delay (FID) per context (LaunchDarkly)
- Average, P95, and P99 Interaction to Next Paint (INP) per context (LaunchDarkly)
- Average, P95, and P99 Largest Contentful Paint (LCP) (LaunchDarkly)
- Average, P95, and P99 Time to First Byte (TTFB) per context (LaunchDarkly)
To learn more, read Metrics autogenerated from observability events.