> ## Documentation Index
> Fetch the complete documentation index at: https://launchdarkly.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Python SDK observability reference

<View title="Developer" />

<View title="Federal docs" />

<View title="EU docs" />

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.

<Note>
  **SDK quick links**

  LaunchDarkly's SDKs are open source. In addition to this reference guide, we provide source, API reference documentation, and a sample application:

  <table>
    <thead>
      <tr>
        <th>Resource</th>
        <th>Location</th>
      </tr>
    </thead>

    <tbody>
      <tr>
        <td>SDK API documentation</td>
        <td>[Observability plugin API docs](https://launchdarkly.github.io/observability-sdk/sdk/@launchdarkly/observability-python/)</td>
      </tr>

      <tr>
        <td>GitHub repository</td>
        <td>[@launchdarkly/observability-python](https://github.com/launchdarkly/observability-sdk/tree/main/sdk/%40launchdarkly/observability-python)</td>
      </tr>

      <tr>
        <td>Sample application</td>
        <td>[Example Flask app](https://github.com/launchdarkly/observability-sdk/blob/main/e2e/python-plugin-flask/README.md)</td>
      </tr>

      <tr>
        <td>Published module</td>
        <td>[PyPI](https://pypi.org/project/launchdarkly-observability)</td>
      </tr>
    </tbody>
  </table>
</Note>

## Prerequisites and dependencies

This reference guide assumes that you are somewhat familiar with the LaunchDarkly [Python SDK](/docs/sdk/server-side/python).

The observability plugin is compatible with the [Python SDK](/docs/sdk/server-side/python), 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](#install-the-plugin)
* [Initialize the Python SDK client](#initialize-the-client)
* [Configure the plugin options](#configure-the-plugin-options)
* [Explore supported features](#explore-supported-features)
* [Review observability data in LaunchDarkly](#review-observability-data-in-launchdarkly)

## 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:

<CodeGroup>
  ```bash title="Shell" lines wrap theme={null}
    pip install launchdarkly-server-sdk
    pip install launchdarkly-observability
  ```
</CodeGroup>

Then, import the plugin into your code:

<CodeGroup>
  ```python title="Python" lines wrap theme={null}
  import ldclient
  from ldclient.config import Config

  import ldobserve
  from ldobserve import ObservabilityConfig, ObservabilityPlugin, observe
  ```
</CodeGroup>

## 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](/docs/sdk/server-side/python#initialize-the-client) in the Python SDK reference guide.

Here's how to initialize the SDK and plugin:

<CodeGroup>
  ```python title="Initialize, Python SDK v9.12+" lines wrap theme={null}
  plugin = ObservabilityPlugin()

  config = Config(
    sdk_key = "YOUR_SDK_KEY",
    plugins = [plugin]
  )
  ldclient.set_config(config)
  client = ldclient.get()
  ```
</CodeGroup>

## 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:

<CodeGroup>
  ```python title="Plugin options, Python SDK v9.12+" lines wrap theme={null}
  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)
  ```
</CodeGroup>

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](/docs/sdk/features/observability-config-server-side).

## 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:

* [Configuration for server-side observability](/docs/sdk/features/observability-config-server-side#python)
* [Errors](/docs/sdk/features/observability-errors#python)
* [Logs](/docs/sdk/features/observability-logs#python)
* [Metrics](/docs/sdk/features/observability-metrics#python)
* [Tracing](/docs/sdk/features/observability-traces#python)

## Use the plugin with the New Relic Python agent

If your application uses the New Relic Python agent, version 14.0.0 or later, you can turn on the agent's preview LaunchDarkly integration. The agent adds feature flag evaluation data to its spans and sends them to LaunchDarkly through the observability plugin. To learn how, read [Using the New Relic Python agent with LaunchDarkly](/docs/sdk/observability/python-new-relic).

## 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](/docs/home/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 [OpenTelemetry autogenerated metrics](/docs/home/metrics/autogen/opentelemetry).
