|
# Datadog Tracing |
|
|
|
>[ddtrace](https: |
|
|
|
Key features of the ddtrace integration for LangChain: |
|
- Traces: Capture LangChain requests, parameters, prompt-completions, and |
|
- Metrics: Capture /cost usage (for OpenAI LLMs and chat models). |
|
- Logs: Store prompt completion data for each LangChain operation. |
|
- Dashboard: Combine metrics, logs, and trace data into a single plane to monitor LangChain requests. |
|
- Monitors: Provide alerts in response to spikes in LangChain request latency or error rate. |
|
|
|
Note: The ddtrace LangChain integration currently provides tracing for LLMs, chat models, Text Embedding Models, Chains, and Vectorstores. |
|
|
|
## Installation and Setup |
|
|
|
1. Enable APM and StatsD in your Datadog Agent, along with a Datadog API key. For example, in Docker: |
|
|
|
``` |
|
docker run -d --cgroupns host \ |
|
--pid host \ |
|
-v //run//var//docker.sock:ro \ |
|
-v //://proc/ |
|
-v /sys//cgroup//host//fs/ |
|
-e |
|
-p /tcp \ |
|
-p 127.0.0.1:8125:8125/ |
|
-e |
|
-e |
|
gcr.io/datadoghq/agent:latest |
|
``` |
|
|
|
2. Install |
|
|
|
``` |
|
pip |
|
``` |
|
|
|
|
|
3. The `` |
|
|
|
``` |
|
DD_SERVICE="my-service" DD_ENV="staging" DD_API_KEY=<DATADOG_API_KEY> ddtrace-run |
|
``` |
|
|
|
|
|
|
|
Additionally, the `` `` `` |
|
|
|
Note `` `` `` `` `` |
|
|
|
```python |
|
from |
|
|
|
# Note: be ```` |
|
# e.g. config.langchain["logs_enabled"] = True |
|
|
|
patch(langchain=True) |
|
|
|
# to |
|
# patch(langchain=True, requests=True) |
|
|
|
# to |
|
# patch(langchain=True, aiohttp=True) |
|
|
|
# to |
|
# patch(langchain=True, openai=True)patch_all |
|
``` |
|
|
|
See ///en//installation_quickstart.html) for more advanced usage. |
|
|
|
|
|
## Configuration |
|
|
|
See the [APM Python library documentation](https: |
|
|
|
|
|
### Log Prompt & Completion Sampling |
|
|
|
To enable log prompt and completion sampling, set the `DD_LANGCHAIN_LOGS_ENABLED=1` environment variable. By default, 10% of traced requests will emit logs containing the prompts and completions. |
|
|
|
To adjust the log sample rate, see the [APM library documentation](https: |
|
|
|
**Note**: Logs submission requires `DD_API_KEY` to be specified when running `ddtrace-run`. |
|
|
|
|
|
## Troubleshooting |
|
|
|
Need help? Create an issue on [ddtrace](https: |
|
|