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.
When using ddtrace-run, the following environment variable options can be used:
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 documentation for recommendations on how to configure these environment variables.
- DD_ENV
- Set the application’s environment, for example: prod,pre-prod,staging. Learn more about how to setup your environment. Available in version 0.38+.
- DD_SERVICE
- 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). Available in version 0.38+.
- DD_VERSION
- Set the application’s version, for example: 1.2.3,6c44da20,2020.02.13. Available in version 0.38+.
Traces
- DD_TRACE_ENABLED
- Default: true
 Enable web framework and library instrumentation. Whenfalse, the application code doesn’t generate any traces.
 See also DD_APM_TRACING_ENABLED.
- DD_TRACE_DEBUG
- Default: false
 Enable debug logging in the tracer.
- DD_SERVICE_MAPPING
- Define service name mappings to allow renaming services in traces, for example: postgres:postgresql,defaultdb:postgresql. Available in version 0.47+.
- DD_TRACE_RATE_LIMIT
- Maximum number of spans to sample per-second, per-Python process. Defaults to 100whenDD_TRACE_SAMPLE_RATEis set. Otherwise, delegates rate limiting to the Datadog Agent.
- DD_TRACE_HEADER_TAGS
- 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_TRACE_AGENT_URL
- 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_socketconfiguration in yourdatadog.yamlfile or theDD_APM_RECEIVER_SOCKETenvironment variable set on the Datadog Agent. For example,DD_TRACE_AGENT_URL=http://localhost:8126for HTTP URL andDD_TRACE_AGENT_URL=unix:///var/run/datadog/apm.socketfor UDS. If the Agent configuration setsreceiver_portorDD_APM_RECEIVER_PORTto something other than the default8126, thenDD_AGENT_PORTorDD_TRACE_AGENT_URLmust match it.
Agent
- DD_PATCH_MODULES
- Override the modules patched for this application execution. Follow the format: DD_PATCH_MODULES=module:patch,module:patch...
- DD_TAGS
- 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_AGENT_HOST
- Default: localhost
 Override the address of the trace Agent host that the default tracer attempts to submit traces to.
- DD_AGENT_PORT
- Default: 8126
 Overrides the port that the default tracer submit traces to. If the Agent configuration setsreceiver_portorDD_APM_RECEIVER_PORTto something other than the default8126, thenDD_AGENT_PORTorDD_TRACE_AGENT_URLmust match it.
- DD_DOGSTATSD_URL
- 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_socketconfiguration in yourdatadog.yamlfile or theDD_DOGSTATSD_SOCKETenvironment variable set on the Datadog Agent. For example,DD_DOGSTATSD_URL=udp://localhost:8126for UDP URL andDD_DOGSTATSD_URL=unix:///var/run/datadog/dsd.socketfor UDS. If the Agent configuration setsdogstatsd_portorDD_DOGSTATSD_PORTto something other than the default8125, then this tracing libraryDD_DOGSTATSD_URLorDD_DOGSTATSD_PORTmust match it.
- DD_DOGSTATSD_HOST
- Default: localhost
 Override the address of the trace Agent host that the default tracer attempts to submit DogStatsD metrics to. UseDD_AGENT_HOSTto overrideDD_DOGSTATSD_HOST.
- DD_DOGSTATSD_PORT
- Default: 8125
 Override the port that the default tracer submits DogStatsD metrics to. If the Agent configuration setsdogstatsd_portorDD_DOGSTATSD_PORTto something other than the default8125, then this tracing libraryDD_DOGSTATSD_PORTorDD_DOGSTATSD_URLmust match it.
Logs
- DD_LOGS_INJECTION
- Default: true
 Enable connecting logs and trace injection.
Trace context propagation
- DD_TRACE_PROPAGATION_STYLE_INJECT
- Default: tracecontext,Datadog,baggage
 Propagation styles to use when injecting tracing headers. For example, useDD_TRACE_PROPAGATION_STYLE_INJECT=Datadog,B3to inject both Datadog and B3 format headers.
- DD_TRACE_PROPAGATION_STYLE_EXTRACT
- 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,Datadoglooks forB3headers first, and only usesDatadogheaders if those are not available.
Further Reading
Additional helpful documentation, links, and articles: