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:- LaunchDarkly observability enabled for your project.
- A Python application running Python 3.10 or higher.
- The New Relic Python agent, version 14.0.0 or later, configured with your New Relic license key.
- The LaunchDarkly Python SDK, version 9.12.0 or later.
- The LaunchDarkly Python SDK observability plugin.
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.
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 aretrue.
You can set them with environment variables:
newrelic.ini configuration file:
Initialize the SDK and the observability plugin
The New Relic agent must start before your application importsldclient, 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:
newrelic.agent.initialize() call and run your application like this:
Review feature flag attributes
The New Relic hook adds the following attributes to the active span for each flag evaluation:| Attribute | Description |
|---|---|
feature_flag.key | The key of the evaluated flag. |
feature_flag.provider.name | Set to LaunchDarkly. |
feature_flag.context.id | The key of the LaunchDarkly context used in the evaluation. |
feature_flag.result.value | The evaluation result. The hook omits this attribute when the result is a falsy value, such as False or an empty string. |
feature_flag.result.variationIndex | The index of the variation served, when available. |
feature_flag.result.reason.kind | The kind of evaluation reason, such as FALLTHROUGH or RULE_MATCH. |
feature_flag.result.reason.inExperiment | Set to true when the evaluation is part of an experiment. |
feature_flag.set.id | The LaunchDarkly environment ID, when the SDK provides it. |
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:- Open the Telemetry section and navigate to the Traces list.
- Search for traces from the service name you set in
ObservabilityConfig. - Open a trace from a request that evaluated a flag, and confirm that a span includes the
feature_flag.keyattribute.
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.