Skip to main content

Documentation Index

Fetch the complete documentation index at: https://launchdarkly-preview.mintlify.app/llms.txt

Use this file to discover all available pages before exploring further.

Overview

This topic documents how to get started with the LaunchDarkly observability plugin for the Python SDK. The Python SDK supports the observability plugin for error monitoring, logging, and tracing.
LaunchDarkly’s SDKs are open source. In addition to this reference guide, we provide source, API reference documentation, and a sample application:
ResourceLocation
SDK API documentationObservability plugin API docs
GitHub repository@launchdarkly/observability-python
Sample applicationExample Flask app
Published modulePyPI

Prerequisites and dependencies

This reference guide assumes that you are somewhat familiar with the LaunchDarkly Python SDK. The observability plugin is compatible with the Python SDK, version 9.12.0 and later. Using the observability plugin requires Python 3.10.0 or higher.

Get started

Follow these steps to get started:

Install the plugin

LaunchDarkly uses a plugin to the Python SDK to provide observability. The first step is to make both the SDK and the observability plugin available as dependencies. Here’s how:
    pip install launchdarkly-server-sdk
    pip install launchdarkly-observability
Then, import the plugin into your code:
    import ldclient
    from ldclient.config import Config

    import ldobserve
    from ldobserve import ObservabilityConfig, ObservabilityPlugin, observe

Initialize the client

Next, initialize the SDK and the plugin. To initialize, you need your LaunchDarkly environment’s SDK key. This authorizes your application to connect to a particular environment within LaunchDarkly. To learn more, read Initialize the client in the Python SDK reference guide. Here’s how to initialize the SDK and plugin:
    plugin = ObservabilityPlugin()

    config = Config(
      sdk_key = "YOUR_SDK_KEY",
      plugins = [plugin]
    )
    ldclient.set_config(config)
    client = ldclient.get()

Configure the plugin options

You can configure options for the observability plugin when you initialize the SDK. The plugin constructor takes an optional object with the configuration details. Here is an example:
    observability_config = ObservabilityConfig(
      service_name = "example-service",
      # we recommend setting service_version to the latest deployed git SHA
      service_version = "example-sha"
    )

    plugin = ObservabilityPlugin(observability_config)
For more information on plugin options, as well as how they interact with environment variables and existing OpenTelemetry configuration, read Configuration for server-side observability.

Explore supported features

The observability plugin supports the following features. After the SDK and plugins are initialized, you can access these from within your application:

Review observability data in LaunchDarkly

After you initialize the SDK and observability plugin, your application automatically starts sending observability data back to LaunchDarkly in the form of custom events. You can review this information in the LaunchDarkly user interface. To learn how, read Observability. Specifically, the observability data includes events that LaunchDarkly uses to automatically create the following metrics:
  • User HTTP error rate (OpenTelemetry)
  • User HTTP 5XX response rate (OpenTelemetry)
  • User non-HTTP exception rate (OpenTelemetry)
  • Average, P95, and P99 request latency (OpenTelemetry)
To learn more, read Metrics autogenerated from OpenTelemetry data.