---
title: Configuring the Python Tracing Library
description: Datadog, the leading service for cloud-scale monitoring.
breadcrumbs: >-
  Docs > APM > Application Instrumentation > Configure the Datadog Tracing
  Library > Configuring the Python Tracing Library
---

# Configuring the Python Tracing Library

After you set up the tracing library with your code and configure the Agent to collect APM data, optionally configure the tracing library as desired, including setting up [Unified Service Tagging](https://docs.datadoghq.com/getting_started/tagging/unified_service_tagging).
To verify your runtime configuration and confirm settings, view the current configuration of your service in Datadog. Navigate to the **APM Service Page**, click **Service Config**, and select the **SDK Configuration** tab.
When using **ddtrace-run**, the following [environment variable options](https://ddtrace.readthedocs.io/en/stable/advanced_usage.html#ddtracerun) can be used:

## Unified service tagging{% #unified-service-tagging %}

It is recommended to use `DD_ENV`, `DD_SERVICE`, and `DD_VERSION` to set `env`, `service`, and `version` for your services. Refer to the [Unified Service Tagging](https://docs.datadoghq.com/getting_started/tagging/unified_service_tagging) documentation for recommendations on how to configure these environment variables.

{% dl %}

{% dt %}
`DD_ENV`
{% /dt %}

{% dd %}
Set the application's environment, for example: `prod`, `pre-prod`, `staging`. Learn more about [how to setup your environment](https://docs.datadoghq.com/tracing/guide/setting_primary_tags_to_scope/). Available in version 0.38+.
{% /dd %}

{% dt %}
`DD_SERVICE`
{% /dt %}

{% dd %}
The service name to be used for this application. The value is passed through when setting up middleware for web framework integrations like Pylons, Flask, or Django. For tracing without a web integration, it is recommended that you set the service name in code ([for example, see these Django docs](https://ddtrace.readthedocs.io/en/stable/integrations.html#django)). Available in version 0.38+.
{% /dd %}

{% dt %}
`DD_VERSION`
{% /dt %}

{% dd %}
Set the application's version, for example: `1.2.3`, `6c44da20`, `2020.02.13`. Available in version 0.38+.
{% /dd %}

{% /dl %}

## Traces{% #traces %}

{% dl %}

{% dt %}
`DD_TRACE_ENABLED`
{% /dt %}

{% dd %}
**Default**: `true`Enable web framework and library instrumentation. When `false`, the application code doesn't generate any traces.See also [DD_APM_TRACING_ENABLED](https://docs.datadoghq.com/tracing/trace_collection/library_config/#traces).
{% /dd %}

{% dt %}
`DD_TRACE_DEBUG`
{% /dt %}

{% dd %}
**Default**: `false`Enable debug logging in the tracer.
{% /dd %}

{% dt %}
`DD_SERVICE_MAPPING`
{% /dt %}

{% dd %}
Define service name mappings to allow renaming services in traces, for example: `postgres:postgresql,defaultdb:postgresql`. Available in version 0.47+.
{% /dd %}

{% dt %}
`DD_TRACE_RATE_LIMIT`
{% /dt %}

{% dd %}
Maximum number of spans to sample per-second, per-Python process. Defaults to `100` when `DD_TRACE_SAMPLE_RATE` is set. Otherwise, delegates rate limiting to the Datadog Agent.
{% /dd %}

{% dt %}
`DD_TRACE_HEADER_TAGS`
{% /dt %}

{% dd %}
**Default**: `null`Comma-separated list of header names that are reported on the root span as tags. For example, `DD_TRACE_HEADER_TAGS="User-Agent:http.user_agent,Referer:http.referer,Content-Type:http.content_type,Etag:http.etag"`.
{% /dd %}

{% dt %}
`DD_TRACE_AGENT_URL`
{% /dt %}

{% dd %}
The URL of the Trace Agent that the tracer submits to. If set, this takes priority over hostname and port. Supports Unix Domain Sockets (UDS) in combination with the `apm_config.receiver_socket` configuration in your `datadog.yaml` file or the `DD_APM_RECEIVER_SOCKET` environment variable set on the Datadog Agent. For example, `DD_TRACE_AGENT_URL=http://localhost:8126` for HTTP URL and `DD_TRACE_AGENT_URL=unix:///var/run/datadog/apm.socket` for UDS. If the [Agent configuration](https://docs.datadoghq.com/agent/configuration/network/#configure-ports) sets `receiver_port` or `DD_APM_RECEIVER_PORT` to something other than the default `8126`, then `DD_AGENT_PORT` or `DD_TRACE_AGENT_URL` must match it.
{% /dd %}

{% /dl %}

## Agent{% #agent %}

{% dl %}

{% dt %}
`DD_PATCH_MODULES`
{% /dt %}

{% dd %}
Override the modules patched for this application execution. Follow the format: `DD_PATCH_MODULES=module:patch,module:patch...`
{% /dd %}

{% dt %}
`DD_TAGS`
{% /dt %}

{% dd %}
A list of default tags to be added to every span and profile, for example: `layer:api,team:intake,key:value`. Available in version 0.38+.
{% /dd %}

{% dt %}
`DD_AGENT_HOST`
{% /dt %}

{% dd %}
**Default**: `localhost`Override the address of the trace Agent host that the default tracer attempts to submit traces to.
{% /dd %}

{% dt %}
`DD_AGENT_PORT`
{% /dt %}

{% dd %}
**Default**: `8126`Overrides the port that the default tracer submit traces to. If the [Agent configuration](https://docs.datadoghq.com/agent/configuration/network/#configure-ports) sets `receiver_port` or `DD_APM_RECEIVER_PORT` to something other than the default `8126`, then `DD_AGENT_PORT` or `DD_TRACE_AGENT_URL` must match it.
{% /dd %}

{% dt %}
`DD_DOGSTATSD_URL`
{% /dt %}

{% dd %}
The URL used to connect to the Datadog Agent for DogStatsD metrics. If set, this takes priority over hostname and port. Supports Unix Domain Sockets (UDS) in combination with the `dogstatsd_socket` configuration in your `datadog.yaml` file or the `DD_DOGSTATSD_SOCKET` environment variable set on the Datadog Agent. For example, `DD_DOGSTATSD_URL=udp://localhost:8126` for UDP URL and `DD_DOGSTATSD_URL=unix:///var/run/datadog/dsd.socket` for UDS. If the [Agent configuration](https://docs.datadoghq.com/agent/configuration/network/#configure-ports) sets `dogstatsd_port` or `DD_DOGSTATSD_PORT` to something other than the default `8125`, then this tracing library `DD_DOGSTATSD_URL` or `DD_DOGSTATSD_PORT` must match it.
{% /dd %}

{% dt %}
`DD_DOGSTATSD_HOST`
{% /dt %}

{% dd %}
**Default**: `localhost`Override the address of the trace Agent host that the default tracer attempts to submit DogStatsD metrics to. Use `DD_AGENT_HOST` to override `DD_DOGSTATSD_HOST`.
{% /dd %}

{% dt %}
`DD_DOGSTATSD_PORT`
{% /dt %}

{% dd %}
**Default**: `8125`Override the port that the default tracer submits DogStatsD metrics to. If the [Agent configuration](https://docs.datadoghq.com/agent/configuration/network/#configure-ports) sets `dogstatsd_port` or `DD_DOGSTATSD_PORT` to something other than the default `8125`, then this tracing library `DD_DOGSTATSD_PORT` or `DD_DOGSTATSD_URL` must match it.
{% /dd %}

{% /dl %}

## Logs{% #logs %}

{% dl %}

{% dt %}
`DD_LOGS_INJECTION`
{% /dt %}

{% dd %}
**Default**: `true`Enable [connecting logs and trace injection](https://docs.datadoghq.com/tracing/other_telemetry/connect_logs_and_traces/python/).
{% /dd %}

{% /dl %}

## Trace context propagation{% #trace-context-propagation %}

{% dl %}

{% dt %}
`DD_TRACE_PROPAGATION_STYLE_INJECT`
{% /dt %}

{% dd %}
**Default**: `tracecontext,Datadog,baggage`Propagation styles to use when injecting tracing headers. For example, use `DD_TRACE_PROPAGATION_STYLE_INJECT=Datadog,B3` to inject both Datadog and B3 format headers.
{% /dd %}

{% dt %}
`DD_TRACE_PROPAGATION_STYLE_EXTRACT`
{% /dt %}

{% dd %}
**Default**: Value of `DD_TRACE_PROPAGATION_STYLE_INJECT` (`tracecontext,Datadog,baggage`)Propagation styles to use when extracting tracing headers. When multiple values are given, it uses the first header match found. The order of matching is based on the order of values given. For example, `DD_TRACE_PROPAGATION_STYLE_EXTRACT=B3,Datadog` looks for `B3` headers first, and only uses `Datadog` headers if those are not available.
{% /dd %}

{% /dl %}

## Further Reading{% #further-reading %}

- [Source code](https://github.com/DataDog/dd-trace-py)
- [API Docs](https://ddtrace.readthedocs.io/en/stable/)
- [Propagating trace context](https://docs.datadoghq.com/tracing/trace_collection/trace_context_propagation/)
- [Explore your services, resources and traces](https://docs.datadoghq.com/tracing/glossary/)
- [Advanced Usage](https://docs.datadoghq.com/tracing/)
- [OpenTelemetry Environment Variable Configurations](https://docs.datadoghq.com/opentelemetry/interoperability/environment_variable_support)
