OpenTelemetry
Read time: 7 minutes
Last edited: Nov 05, 2024
Overview
This topic explains how to enable OpenTelemetry in server-side SDKs. OpenTelemetry (OTel) is an open source observability framework.
LaunchDarkly's SDKs support instrumentation for OpenTelemetry traces. Traces provide an overview of how your application handles requests. For example, traces may show that a particular feature flag was evaluated for a particular context as part of a given HTTP request.
To add flag evaluation information to OpenTelemetry spans, create a new tracing hook and reference it in the configuration options when you initialize the SDK client. When this configuration is set, the SDK adds span events to your active span.
We recommend enabling OpenTelemetry in the SDK if you use LaunchDarkly's Experimentation or Guarded rollouts features to monitor metrics on flag releases, or if you use third-party observability tools that support the OpenTelemetry framework.
To learn how to send these traces back to LaunchDarkly, read Sending OpenTelemetry traces to LaunchDarkly.
Details about each SDK's configuration are available in the SDK-specific sections below.
Server-side SDKs
This feature is available in the following SDKs:
.NET (server-side)
Expand .NET (server-side) code sample
To add flag evaluation information to OpenTelemetry spans, first add the Telemetry package from NuGet:
Next, import the LaunchDarkly.Sdk.Server.Hooks
and LaunchDarkly.Sdk.Server.Telemetry
namespaces. Then you can create a new tracing hook and reference it in the configuration options when you initialize the SDK client.
Here's how:
When this configuration is set, the SDK adds span events for each call to a *Variation*
method to your active span. The span event information contains details of each flag evaluation, including the flag key and the context key. You can collect this information in Guarded rollouts or other observability tools. To learn how, read Sending OpenTelemetry traces to LaunchDarkly.
Optionally, you can configure the tracing hook to:
- create new spans that contain span events with flag evaluation information, rather than adding the events to the active span. The new spans are nested in the current active span, and are not active.
- include the flag's evaluated flag value in the span event.
Here's how:
In the .NET (server-side) SDK, the tracing hook is implemented using Microsoft's System.Diagnostics APIs. Therefore, some of the terminology it uses differs from the OpenTelemetry standard. For example, the tracing hook in the .NET (server-side) SDK uses the method CreateActivities()
, rather than CreateSpans()
, to enable child spans.
To learn more, read TracingHookBuilder
and ConfigurationBuilder
.
Go
Expand Go code sample
To add flag evaluation information to OpenTelemetry spans, import the ldhooks
package. Then, create a new tracing hook and reference it in the configuration options when you initialize the SDK client.
Here's how:
When this configuration is set, the SDK adds span events for each call to a *Variation*Ctx
method to your active span.
The span event information contains details of each flag evaluation, including the flag key and the context key. You can collect this information in Guarded rollouts or other observability tools. To learn how, read Sending OpenTelemetry traces to LaunchDarkly.
The *Variation*Ctx
methods are the same as the *Variation*
methods, except that they also require a Go context. For example, BoolVariationCtx
and BoolVariationDetailCtx
are the same as the BoolVariation
and BoolVariationDetail
methods, except that they also require a Go context. This Go context is used in the hook implementation. If you are using hooks, you must update your variation calls to use the Ctx
methods.
Optionally, you can configure the tracing hook to:
- create new spans that contain span events with flag evaluation information, rather than adding the events to the active span. The new spans are nested in the current active span, and are not active.
- include the flag's evaluated flag value in the span event.
Here's how:
To learn more, read Config
.
Java
Expand Java code sample
To add flag evaluation information to OpenTelemetry spans, import the LaunchDarkly Java Otel Hook package. Then, create a new tracing hook and reference it in the configuration options when you initialize the SDK client.
Here's how:
When this configuration is set, the SDK adds span events for each call to a *Variation*
method to your active span. The span event information contains details of each flag evaluation, including the flag key and the context key. You can collect this information in Guarded rollouts or other observability tools. To learn how, read Sending OpenTelemetry traces to LaunchDarkly.
Optionally, you can configure the tracing hook to:
- create new spans that contain span events with flag evaluation information, rather than adding the events to the active span. The new spans are nested in the current active span, and are not active.
- include the flag's evaluated flag value in the span event.
Here's how:
To learn more, read LDConfig.Builder
.
Node.js (server-side)
Expand Node.js (server-side) code sample
To add flag evaluation information to OpenTelemetry spans, import the TracingHook
package. Then, create a new tracing hook and reference it in the configuration options when you initialize the SDK client.
Here's how:
When this configuration is set, the SDK adds span events for each call to a *Variation*
method to your active span. The span event information contains details of each flag evaluation, including the flag key and the context key. You can collect this information in Guarded rollouts or other observability tools. To learn how, read Sending OpenTelemetry traces to LaunchDarkly.
Optionally, you can configure the tracing hook to:
- create new spans that contain span events with flag evaluation information, rather than adding the events to the active span. The new spans are nested in the current active span, and are not active.
- include the flag's evaluated flag value in the span event.
Here's how:
To learn more, read LDOptions
.
Python
Expand Python code sample
To add flag evaluation information to OpenTelemetry spans, create a new tracing hook and reference it in the configuration options when you initialize the SDK client.
Here's how:
When this configuration is set, the SDK adds span events for each call to a *variation*
method to your active span. The span event information contains details of each flag evaluation, including the flag key and the context key. You can collect this information in Guarded rollouts or other observability tools. To learn how, read Sending OpenTelemetry traces to LaunchDarkly.
Optionally, you can configure the tracing hook to:
- create new spans. The new spans are nested in the current active span, and are not active. The span events with flag evaluation information are still added to the parent span.
- include the flag's evaluated flag value in the span event.
Here's how:
To learn more, read Config
.
Ruby
Expand Ruby code sample
To add flag evaluation information to OpenTelemetry spans, create a new tracing hook and reference it in the configuration options when you initialize the SDK client.
Here's how:
When this configuration is set, the SDK adds span events for each call to a *Variation*
method to your active span. The span event information contains details of each flag evaluation, including the flag key and the context key. You can collect this information in Guarded rollouts or other observability tools. To learn how, read Sending OpenTelemetry traces to LaunchDarkly.
Optionally, you can configure the tracing hook to:
- create new spans. The new spans are nested in the current active span, and are not active. The span events with flag evaluation information are still added to the parent span.
- include the flag's evaluated flag value in the span event.
Here's how:
To learn more, read Config
.