Skip to main content
The Sentry integration is available to customers on select plansThe Sentry integration is only available to customers on select plans. To learn more, read about our pricing. To upgrade your plan, contact Sales.
This topic explains how to use the LaunchDarkly Sentry integration. Sentry is an application performance monitoring and error tracking tool. You can connect Sentry error events to LaunchDarkly to use with LaunchDarkly metrics. You can also use your Sentry monitors as the source for adaptive triggers, which switch a flag to a different variation when a monitor breaches.
An installed Sentry integration.

An installed Sentry integration.

The Sentry integration works with custom conversion binary and custom conversion count metrics. To learn more, read Metrics. Sentry only sends error events to integrations from organizations on its Business plan or higher. If your Sentry organization is on a lower plan, the integration installs but LaunchDarkly receives no error events. To learn more, read Sentry’s pricing.
You can also forward Sentry errors from your own codeIf this integration is not available on your plan or in your LaunchDarkly instance, or if you want control over the data attached to each error event, you can forward errors to LaunchDarkly yourself from Sentry’s beforeSend hook. To learn how, read Sending error events from observability tools.
Sentry sends error events to LaunchDarkly only for Sentry organizations on the Business plan or higher. To learn more, read Sentry pricing. To use the Sentry integration, you must complete the following steps:
  1. Install Sentry
  2. Configure the integration
  3. Create a LaunchDarkly metric
  4. Attach LaunchDarkly contexts to Sentry error events
To use Sentry monitors with adaptive triggers, you need to install the integration and map environments. You don’t need a metric or the launchdarklyContext custom context. To learn more, read Use Sentry monitors with adaptive triggers.

Install Sentry

To install the Sentry integration:
  1. In LaunchDarkly, navigate to the Integrations page and find “Sentry.”
  2. Open the Sentry integration panel and click Install in Sentry. Sentry opens the LaunchDarkly app.
  3. In Sentry, click Install within 15 minutes.
You are redirected to the Sentry integration panel in LaunchDarkly. You must start the installation from LaunchDarkly. If you install the LaunchDarkly app from the integrations directory in Sentry instead, the installation fails. The LaunchDarkly app in Sentry requests read access to alerts and receives Sentry issue webhooks. LaunchDarkly uses these permissions to list your Sentry monitors and to learn when a monitor breaches. If you installed the integration before LaunchDarkly added these permissions, your installation gets them automatically. You do not need to reinstall. If the Source section of a trigger reports “The Sentry integration can’t read monitors,” reinstall the LaunchDarkly app in Sentry.

Configure the integration

There are two pieces of configuration required for the Sentry integration to work:
  • setting the event key, and
  • mapping the environments.

Set the event key

Sentry uses the event key to aggregate events. We recommend using a Metric event key of sentry-errors or similar, but you can use any event key you like.
The "Metric event key" section of the integration panel.

The "Metric event key" section of the integration panel.

A LaunchDarkly metric must exist with the designated event key for the integration to work in a given project. If there is not an existing custom metric with the chosen event key, create a custom metric with that event key. To learn how, read Create a LaunchDarkly metric. When you set a metric event key, a green check mark appears in the integration panel.
Event keys and metric keys are differentSending custom events to LaunchDarkly requires a unique event key. Set the event key to anything you want. Adding this event key to your codebase lets your SDK track actions customers take in your app as events. To learn more, read Tracking custom events.LaunchDarkly also automatically generates a metric key when you create a metric. You only use the metric key to identify the metric in API calls. To learn more, read Creating and managing metrics.

Map environments

Events are specific to one LaunchDarkly environment. The Sentry integration requires you to map Sentry environments to LaunchDarkly environments. This lets you send Sentry errors to different LaunchDarkly environments. For example, you can send errors from your production Sentry environment to your production LaunchDarkly environment, and errors from your staging Sentry environment to your staging LaunchDarkly environment. To map Sentry environments to LaunchDarkly environments:
  1. Navigate to the Integrations page in LaunchDarkly.
  2. Open the Sentry integration panel.
  3. In the “Environment mappings” section, choose a LaunchDarkly project and environment from the Project - Environment menu.
  4. Choose a Sentry project and environment from the Sentry Project - Environment menu.
  5. Click Create.
The sets of projects and environments are now mapped to each other.
Sentry environment mappings.

Sentry environment mappings.

If you have not set a metric event key, a warning under the Metric event key field reads “Until you set a metric event key, no events will be received from Sentry.” If the LaunchDarkly project for an environment mapping has no metric with the selected event key, the mapping shows the warning “No metric with selected event key in this project.” You can map any number of Sentry project environments to a LaunchDarkly environment. However, you cannot map multiple LaunchDarkly environments to a single Sentry environment.

Create a LaunchDarkly metric

To create a LaunchDarkly metric, follow the procedure at Custom conversion binary metrics or Custom conversion count metrics, depending on your needs. Here are two example metrics we recommend.

Percentage of end users that experienced an error

To track the percentage of end users that experienced an error, create a custom conversion binary metric by selecting the following options:
  • Event kind: Custom
  • Event key: sentry-errors
  • Metric definition: Occurrence (Percent) of User units that sent the event where lower is better
Here is what the metric setup looks like:
The metric creation dialog.

The metric creation dialog.

Average number of errors per request

To track the average number of errors per request, create a custom conversion count metric by selecting the following options:
  • Event kind: Custom
  • Event key: sentry-errors
  • Metric definition: Count events per Request, then compute the Average of those values where lower is better
Here is what the metric setup looks like:
The metric creation dialog.

The metric creation dialog.

After you create your metrics, return to the Sentry integration configuration panel and set the Sentry integration event key if you have not already done so.

Filter Sentry errors by event property

Each event that LaunchDarkly creates from a Sentry error includes details from the error in its data object. You can use these properties in metric filters to build narrower metrics from the same event key, instead of counting every error in the environment. To learn how, read Filtering metric events. Here are the properties LaunchDarkly copies from each Sentry error. LaunchDarkly omits a property when Sentry does not send it.
PropertyDescription
sentryProjectIdThe numeric ID of the Sentry project the error belongs to.
levelThe error’s level, such as fatal, error, or warning.
releaseThe release, or version, of your application that reported the error.
environmentThe Sentry environment that reported the error.
transactionThe transaction that caused the error, such as the route in a web application. Sentry sends this only when your Sentry SDK sets it.
culpritThe code location that Sentry reports as the source of the error.
locationThe file or code location where the error occurred.
titleThe title of the error, as it appears in Sentry.
issue_idThe ID of the Sentry issue the error belongs to.
platformThe platform that reported the error, such as javascript or python.
tagAn object that contains the error’s Sentry tags, with one property for each tag. For example, a Sentry tag named handled appears as tag.handled. You cannot use tags in metric filters.
Metric filters match only top-level properties in the data object. The tag object is nested, and LaunchDarkly ignores it when it applies a filter. The tags are still stored with each event. Here are some examples of filters you can build on the sentry-errors event key:
  • Fatal errors only: level is fatal.
  • Errors from one endpoint: transaction is /api/checkout.
  • Errors in one release: release is 2.4.0.
  • Errors from one Sentry project: sentryProjectId is the ID of that project.

Attach LaunchDarkly contexts to Sentry error events

Sentry custom contexts are not the same as LaunchDarkly custom contextsSentry provides functionality called “custom contexts.” These are distinct from LaunchDarkly custom contexts. In this section, “custom contexts” refers to the Sentry functionality.
Sentry provides custom contexts which let you attach arbitrary data to a Sentry event. To use the Sentry integration, you must name the Sentry custom context launchdarklyContext and then attach LaunchDarkly contexts to error events. To learn how, read Sentry’s Context docs.
You must name the Sentry custom context launchdarklyContextIn Sentry, you must name the Sentry custom context launchdarklyContext. If the Sentry custom context is not present or you have named it something else, LaunchDarkly rejects the error event and does not create a metric event.

Supported JSON structures for the custom context

LaunchDarkly reads the launchdarklyContext custom context to find the context kinds and keys that the error belongs to. It accepts the custom context in structures such as the following. In every structure, the value for a context kind is either the context key as a string, or an object with a key property. The kind property is optional. If you omit kind and include a top-level key, LaunchDarkly reads the object as a user context.
The first and third examples match the JSON that LaunchDarkly SDKs use for a context. You can attach the same context object that you pass to the LaunchDarkly SDK. The “keys only” and “kind-to-key map” structures match the output of SDK helper methods that return context keys. LaunchDarkly uses only the context kinds and keys. It ignores other properties inside a context object, such as name or anonymous. In the single-context structures it also ignores other top-level properties. In multi-context and kind-to-key map structures, LaunchDarkly reads every top-level property other than kind as a context kind. Put attributes inside each context object. LaunchDarkly rejects an event if:
  • It finds user attributes such as name or anonymous at the top level of a multi-context or kind-to-key map structure.
  • A context kind contains characters other than letters, numbers, ., _, and -.
  • A context key is empty.
Here is an example that attaches a multi-context in a JavaScript application:
Each context key in the custom context is attached to the metric event that LaunchDarkly creates for the error. If the custom context is missing or does not match one of these structures, LaunchDarkly rejects the error event and does not create a metric event. The rejection response to Sentry states the reason and lists the accepted structures. If your Sentry errors do not appear in your metric, confirm that the custom context matches one of these structures.

Using the integration

After you create the environment mappings, set the metric event key, create metrics for your desired projects, and add LaunchDarkly contexts to the Sentry SDK, you can use the metric in LaunchDarkly the same way as any other metric. When you configure a metric to use Sentry errors, error events will flow from Sentry into that metric.

Use Sentry monitors with adaptive triggers

A Sentry monitor watches a signal in Sentry, such as errors, spans, logs, or metrics, and breaches when that signal crosses a threshold you set in Sentry. You can choose a Sentry monitor as the source of an adaptive trigger. When the monitor breaches, the trigger switches the flag to the variation you choose. You do not need to rebuild the monitor’s threshold in LaunchDarkly. To use Sentry monitors with adaptive triggers, you need:
  • The Sentry integration installed, with read access to alerts. To learn more, read Install Sentry.
  • At least one Sentry project mapped to the LaunchDarkly environment where you create the trigger. To learn how, read Map environments.
  • At least one metric monitor in a mapped Sentry project.
When you choose Sentry monitor as a trigger’s source, LaunchDarkly lists the metric monitors on the Sentry projects that are mapped to the trigger’s environment. A monitor that is turned off in Sentry appears in the list labeled “Disabled in Sentry,” and you cannot choose it. A trigger fires each time Sentry reports that the monitor breached, which is when Sentry opens an issue for the monitor or the issue regresses. LaunchDarkly counts only high-priority breaches. A breach at medium priority, or an issue that someone reopens in Sentry, does not fire the trigger. A monitor evaluates whatever its query in Sentry covers, not only the contexts that receive the flag. If the monitor’s query isn’t scoped to the feature you’re releasing, such as by project, release, or tag, an unrelated breach can switch the flag. To learn how to create the trigger, read Adaptive triggers.