Enable Dynamic Instrumentation for Python
This product is not supported for your selected
Datadog site. (
).
Dynamic Instrumentation is a feature of the Datadog tracing library that lets you add instrumentation to your application at runtime without code changes or redeployments. Follow these instructions to set up Dynamic Instrumentation for Python.
Prerequisites
Before you begin, review the Dynamic Instrumentation prerequisites. Python applications also require:
Installation
If you don’t already have APM enabled, in your Agent configuration, set the DD_APM_ENABLED environment variable to true and listening to the port 8126/TCP.
Install ddtrace, which provides both tracing and Dynamic Instrumentation:
Run your service with Dynamic Instrumentation enabled by setting the DD_DYNAMIC_INSTRUMENTATION_ENABLED environment variable to true. Specify DD_SERVICE, DD_ENV, and DD_VERSION Unified Service Tags so you can filter and group your instrumentations and target active clients across these dimensions.
Invoke your service:
export DD_SERVICE=<YOUR_SERVICE>
export DD_ENV=<YOUR_ENV>
export DD_VERSION=<YOUR_VERSION>
export DD_DYNAMIC_INSTRUMENTATION_ENABLED=true
ddtrace-run python -m myapp.py
from ddtrace.debugging import DynamicInstrumentation
DynamicInstrumentation.enable()
After starting your service with Dynamic Instrumentation enabled, you can start using it on the APM > Dynamic Instrumentation page.
Configuration
Configure Dynamic Instrumentation using the following environment variables:
| Environment variable | Type | Description |
|---|
DD_DYNAMIC_INSTRUMENTATION_ENABLED | Boolean | Set to true to enable Dynamic Instrumentation. |
DD_SERVICE | String | The service name, for example, web-backend. |
DD_ENV | String | The environment name, for example, production. |
DD_VERSION | String | The version of your service. |
DD_TAGS | String | Tags to apply to produced data. Must be a list of <key>:<value> separated by commas such as: layer:api, team:intake. |
What to do next
See Dynamic Instrumentation for information about adding instrumentations and browsing and indexing the data.
Further reading
Additional helpful documentation, links, and articles: