Skip to main content
This topic explains how to use the LaunchDarkly Python observability plugin with the New Relic Python agent to send traces with feature flag evaluation data to LaunchDarkly. If your application already uses the New Relic Python agent, you can turn on the LaunchDarkly integration that the agent includes. The integration connects the agent to the LaunchDarkly Python SDK and its observability plugin. The agent continues to send data to New Relic. It also adds feature flag evaluation data to the span that was active when your application evaluated a flag, and sends a copy of each span to LaunchDarkly through the observability plugin. This telemetry is available on the Traces page and in other observability features in the LaunchDarkly UI.
This integration is in previewThe LaunchDarkly integration in the New Relic Python agent is a preview feature, available in newrelic version 14.0.0 and later. It is turned off by default. Its configuration and behavior may change in later agent releases.LaunchDarkly observability features are publicly available in early access. Enable observability in the billing page.

Prerequisites

To complete this procedure, you need:

How the integration works

When you turn on the integration, the New Relic Python agent and the LaunchDarkly SDKs work together in the following ways:
  • When your application creates the LaunchDarkly SDK Config, the agent adds a New Relic hook to it. You do not need to register the hook yourself. To learn more, read Hooks.
  • After each flag evaluation, the hook adds feature flag attributes to the New Relic span that is active at the time of the evaluation.
  • When a New Relic transaction finishes, the agent sends its spans to LaunchDarkly using the tracer from the LaunchDarkly observability plugin. The agent skips spans that came from OpenTelemetry instrumentation, because the observability plugin already exports those spans.
The hook only adds attributes when a flag evaluation happens inside a New Relic transaction, such as a web request or a background task that the agent instruments.

Install the packages

To install the New Relic agent, the LaunchDarkly SDK, and the observability plugin:

Turn on the integration

The integration requires two New Relic agent settings: the LaunchDarkly integration setting and the agent’s OpenTelemetry setting. The agent only sends spans to LaunchDarkly when both settings are true. You can set them with environment variables:
Or you can set them in your newrelic.ini configuration file:
The integration also uses New Relic distributed tracing and span events. Both are turned on by default in the New Relic Python agent. If you have turned either one off, turn it back on.

Initialize the SDK and the observability plugin

The New Relic agent must start before your application imports ldclient, so that the agent can add its hook to the SDK configuration. You can start the agent with the newrelic-admin wrapper script, or by calling newrelic.agent.initialize() at the top of your application’s entry point. Then, initialize the LaunchDarkly SDK with the observability plugin. The plugin must be registered for the integration to work. If the integration is turned on and the plugin is not registered, the agent logs a warning when the SDK client starts. Here is an example Flask application:
If you start the agent with the wrapper script instead, remove the newrelic.agent.initialize() call and run your application like this:
To learn more about plugin options, read Configuration for server-side observability.

Review feature flag attributes

The New Relic hook adds the following attributes to the active span for each flag evaluation:
AttributeDescription
feature_flag.keyThe key of the evaluated flag.
feature_flag.provider.nameSet to LaunchDarkly.
feature_flag.context.idThe key of the LaunchDarkly context used in the evaluation.
feature_flag.result.valueThe evaluation result. The hook omits this attribute when the result is a falsy value, such as False or an empty string.
feature_flag.result.variationIndexThe index of the variation served, when available.
feature_flag.result.reason.kindThe kind of evaluation reason, such as FALLTHROUGH or RULE_MATCH.
feature_flag.result.reason.inExperimentSet to true when the evaluation is part of an experiment.
feature_flag.set.idThe LaunchDarkly environment ID, when the SDK provides it.
The hook adds these attributes as New Relic custom attributes. They also appear on the span in New Relic. LaunchDarkly uses these attributes to connect traces to flag evaluations. After LaunchDarkly receives these traces, you can use them with OpenTelemetry autogenerated metrics and guarded rollouts. To learn more, read Creating guarded rollouts.

Verify that data is being received

After you configure the integration and your application handles traffic, traces begin flowing to LaunchDarkly. It can take a few minutes for data to appear. To verify that traces are being received:
  1. Open the Telemetry section and navigate to the Traces list.
  2. Search for traces from the service name you set in ObservabilityConfig.
  3. Open a trace from a request that evaluated a flag, and confirm that a span includes the feature_flag.key attribute.
If no traces appear, check your application logs for New Relic agent warnings. The agent logs a warning if the observability plugin is not registered with the SDK client.

Limitations

The preview integration has the following limitations:
  • The agent only sends traces to LaunchDarkly. It does not send New Relic metrics or logs. To send logs and errors to LaunchDarkly, use the Python observability plugin directly.
  • The agent only adds the hook when the New Relic agent starts before your application creates the LaunchDarkly SDK Config.
  • Flag evaluations outside a New Relic transaction do not add attributes to any span.