ddtrace is the Datadog APM (Application Performance Monitoring) Python library that enables tracing of your applications to monitor performance, latency, and errors in real-time. With ddtrace, you can gain detailed insights into your application's behavior, optimize its performance, and troubleshoot issues quickly.
To install `ddtrace`, you need to install the Python package via `pip`:
pip install ddtrace
Once installed, you can begin instrumenting your application.
After installation, you need to import ddtrace and initialize it. The easiest way to start tracing is by adding this at the entry point of your application:
from ddtrace import tracer # Example: tracing a simple function @tracer.wrap() def my_function(): # Function logic pass
Alternatively, you can use ddtrace to automatically instrument various libraries, such as Flask, Django, Celery, and more, with minimal configuration.
from ddtrace import patch_all patch_all() # This will automatically trace supported libraries
The Datadog tracer can be configured with several options, such as setting the agent host, enabling/disabling certain integrations, and adjusting sampling rates.
Here are some common configuration options:
from ddtrace import tracer tracer.configure(hostname='localhost', port=8126)
ddtrace supports a wide range of libraries and frameworks out of the box. Some popular integrations include:
To enable tracing for these frameworks, simply import the relevant module, and ddtrace will automatically instrument them.