This topic explains how to create LaunchDarkly custom metrics from OpenTelemetry traces.
Creating metrics from trace spans is only available to members of LaunchDarkly’s Early Access Program (EAP). To request access to this feature, contact your LaunchDarkly account manager.
LaunchDarkly lets you create custom metrics from OpenTelemetry traces instrumented in your code, for use with guarded rollouts.
Creating metrics from traces lets you use existing OpenTelemetry instrumentation to measure how application behavior changes during a guarded rollout, without re-instrumenting those behaviors as metric events using the track() method. You define a query that selects the trace spans you want to use to measure your application, and create a metric based on the query result. Each matching span observed during a guarded rollout indicates a metric event.
To create numeric metrics from traces, such as for measuring regressions, you specify the span attribute name that provides the value you want to monitor.
Trace metrics use the same aggregation and analysis methods as LaunchDarkly metrics created from metric events. To learn more, read Components of a metric.
You can create custom metrics from trace spans that include a LaunchDarkly feature flag span event, indicated by the feature_flag.set.id attribute. The LaunchDarkly observability SDK plugins automatically include feature flag span events when you create trace spans.
If your application uses a different OpenTelemetry library or package, you can configure the OpenTelemetry collector or use tracing hooks to add the required feature flag span events. To learn more, read Server-side SDKs.
Trace metrics are compatible with guarded rollouts for managing feature releases. You cannot use trace metrics with LaunchDarkly experiments.
You can create trace metrics using either the LaunchDarkly “Create metric” dialog or the observability “Traces” page. Both methods let you create a span query to select the spans you want to monitor in the metric.
Use the “Create metric” dialog if you are familiar with creating metrics and filtering metric events and you want to use a similar interface to create metrics from spans. Use the “Traces” page if you are familiar with the observability search syntax or you want a real-time preview of your filter query results.
The “Create metric” dialog uses a graphical query builder to help you filter trace spans, while the “Traces” page uses the observability query search specification.
Both interfaces can create equivalent span filters, but they use different syntax for some conditions. The “Create metric” dialog uses the present token to indicate whether an attribute is present in a span. It does not support the EXISTS operator or its negation, NOT EXISTS.
For example, if you use the “Traces” page to create a search that reads service_version EXISTS, the equivalent filter in the “Create metric” dialog is service_version is present.
To use the “Create metric” dialog to create a new trace metric:
Navigate to the Metrics list.
Click Create metric. The “Create metric” dialog appears.
Select Traces from the “Event source” drop-down.
Use the “Filter to spans” field to create a query that selects the trace spans to use for the new metric.

The “Filter to spans” field uses these basic controls:
Span functions (Any span, Any span 2, Any span 3) can only be added to the top level of the filter query, and cannot be nested within parentheses. To learn more, read Span functions for trace search.
(Optional.) Click View traces to view recent spans that match your filter query. This opens a new tab to the Traces page with your filter query applied.
Select a measurement method.
If you are configuring a numeric metric:
0 or Exclude units that generate no events to choose how to handle units that do not generate a matching span during a rollout.Use the “Metric definition” section to configure the metric’s analysis method. To learn more, read Analysis method.
Enter a Metric Name.
(Optional) Add a Description.
(Optional) Add any Tags.
(Optional) Update the Maintainer.
Click Create metric.
To use the “Traces” page to create a new trace metric:
feature_flag.set.id EXISTS to limit results to trace spans that have the required feature flag span event. To learn more, read Search specification.0 or Exclude units that generate no events to choose how to handle units that do not generate a matching span during a rollout.You select trace metrics for use with guarded rollouts in the same way you select other LaunchDarkly metrics. To learn more, read Creating guarded rollouts.