Docs » Instrument back-end applications to send spans to Splunk APM » Instrument Python applications for Splunk Observability Cloud » Instrument your Python application for Splunk Observability Cloud

Instrument your Python application for Splunk Observability Cloud πŸ”—

The Python agent from the Splunk Distribution of OpenTelemetry Python can automatically instrument your Python application by dynamically patching supported libraries.

To get started, use the guided setup or follow the instructions manually.

Generate customized instructions using the guided setup πŸ”—

To generate all the basic installation commands for your environment and application, use the Python guided setup. To access the Python guided setup, follow these steps:

  1. Log in to Splunk Observability Cloud.

  2. Open the Python guided setup . Optionally, you can navigate to the guided setup on your own:

    1. In the navigation menu, select Data Management.

    2. Select Add Integration to open the Integrate Your Data page.

    3. In the integration filter menu, select By Product.

    4. Select the APM product.

    5. Select the Python tile to open the Python guided setup.

Install the Splunk Distribution of OpenTelemetry Python manually πŸ”—

Follow these instructions to install the Splunk Distribution of OpenTelemetry Python:

Install and activate the Python agent πŸ”—

Follow these steps to automatically instrument your application using the Python agent:

  1. Check that you meet the requirements. See Python agent compatibility and requirements.

  2. Install the splunk-opentelemetry[all] package:

    pip install "splunk-opentelemetry[all]"

    If you’re using a requirements.txt or pyproject.toml file, add splunk-opentelemetry[all] to it.

  3. Run the bootstrap script to install instrumentation for every supported package in your environment:


    To print the instrumentation packages to the console instead of installing them, run splunk-py-trace-bootstrap --action=requirements. You can then add the output to your requirements or Pipfile.

  4. Set the OTEL_SERVICE_NAME environment variable:

    export OTEL_SERVICE_NAME=<yourServiceName>
  5. (Optional) Set the endpoint URL if the Splunk Distribution of OpenTelemetry Collector is running on a different host:

    export OTEL_EXPORTER_OTLP_ENDPOINT=<yourCollectorEndpoint>:<yourCollectorPort>
  6. (Optional) Set the deployment environment and service version:

    export OTEL_RESOURCE_ATTRIBUTES='deployment.environment=<envtype>,service.version=<version>'
  7. Activate the Splunk OTel Python agent by editing your Python service command.

    For example, if you open your Python application as follows:

    python3 --port=8000

    prefix the command with splunk-py-trace:

    splunk-py-trace python3 --port=8000
  8. (Optional) Perform these additional steps if you’re using the Django framework:

If no data appears in APM, see Troubleshoot Python instrumentation for Splunk Observability Cloud.

Configure the Python agent πŸ”—

In most cases, the only configuration setting you need to enter is the service name. You can also define other basic settings, like the deployment environment, the service version, and the endpoint, among others.

For advanced configuration of the Python agent, like changing trace propagation formats, correlating traces and logs, or configuring server trace data, see Configure the Python agent for Splunk Observability Cloud.

Deploy the Python agent in Kubernetes πŸ”—

To deploy the Python agent in Kubernetes, configure the Kubernetes Downward API to expose environment variables to Kubernetes resources.

The following example shows how to update a deployment to expose environment variables by adding the agent configuration under the .spec.template.spec.containers.env section:

apiVersion: apps/v1
kind: Deployment
      app: your-application
        - name: myapp
            - name: SPLUNK_OTEL_AGENT
                  fieldPath: status.hostIP
              value: "http://$(SPLUNK_OTEL_AGENT):4317"
            - name: OTEL_SERVICE_NAME
              value: "<serviceName>"
            - name: OTEL_RESOURCE_ATTRIBUTES
              value: "deployment.environment=<environmentName>"

Send data directly to Splunk Observability Cloud πŸ”—

By default, the agent sends all telemetry to the local instance of the Splunk Distribution of OpenTelemetry Collector.

To send data directly to Splunk Observability Cloud, set the following environment variables:

export SPLUNK_ACCESS_TOKEN=<access_token>
export OTEL_TRACES_EXPORTER=jaeger-thrift-splunk
export OTEL_EXPORTER_JAEGER_ENDPOINT=https://ingest.<realm>

To obtain an access token, see Retrieve and manage user API access tokens using Splunk Observability Cloud.

In the ingest endpoint URL, realm is the Splunk Observability Cloud realm, for example, us0. To find the realm name of your account, follow these steps:

  1. Open the navigation menu in Splunk Observability Cloud.

  2. Select Settings.

  3. Select your username.

The realm name appears in the Organizations section.


For more information on the ingest API endpoints, see Send APM traces .

Instrument Lambda functions πŸ”—

You can instrument AWS Lambda functions using the Splunk OpenTelemetry Lambda Layer. See Instrument your AWS Lambda function for Splunk Observability Cloud for more information.