Datadog
Learn how to trace your Haystack pipelines with Datadog.
| Tracer class | DatadogTracer |
| How to enable | Enable the tracer with tracing.enable_tracing(DatadogTracer(ddtrace.tracer)), or add the DatadogConnector component to your pipeline |
| Content tracing | Set HAYSTACK_CONTENT_TRACING_ENABLED to true to trace component inputs and outputs |
| Package | datadog-haystack |
| API reference | datadog |
| GitHub link | https://github.com/deepset-ai/haystack-core-integrations/tree/main/integrations/datadog |
Overview
Trace your Haystack pipelines with Datadog through Datadog's tracing library ddtrace. Haystack captures detailed information about pipeline runs, like API calls, context data, and prompts, so you can see the complete trace of your pipeline execution in Datadog.
Installation
Install the datadog-haystack package:
Prerequisites
- A way to receive traces, such as a running Datadog Agent.
ddtracesends traces to the Datadog Agent atlocalhost:8126by default. - Configure
ddtracethrough the standard mechanisms, for example theDD_SERVICE,DD_ENV, andDD_VERSIONenvironment variables, or by running your application with theddtrace-runcommand. See the ddtrace documentation for more details.
Usage
Enable the DatadogTracer directly to trace any Haystack pipeline, without adding a component to it. Make sure to set the HAYSTACK_CONTENT_TRACING_ENABLED environment variable before importing any Haystack components.
import os
os.environ["HAYSTACK_CONTENT_TRACING_ENABLED"] = "true"
import ddtrace
from haystack import Pipeline, tracing
from haystack.components.builders import ChatPromptBuilder
from haystack.components.generators.chat import OpenAIChatGenerator
from haystack.dataclasses import ChatMessage
from haystack_integrations.tracing.datadog import DatadogTracer
# Enable the Datadog tracer
tracing.enable_tracing(DatadogTracer(ddtrace.tracer))
pipe = Pipeline()
pipe.add_component("prompt_builder", ChatPromptBuilder())
pipe.add_component("llm", OpenAIChatGenerator())
pipe.connect("prompt_builder.prompt", "llm.messages")
messages = [
ChatMessage.from_system(
"Always respond in German even if some input data is in other languages.",
),
ChatMessage.from_user("Tell me about {{location}}"),
]
response = pipe.run(
data={
"prompt_builder": {
"template_variables": {"location": "Berlin"},
"template": messages,
},
},
)
print(response["llm"]["replies"][0])
Each pipeline run produces a trace that includes the entire execution context, including prompts, completions, and metadata. You can then view the traces in your Datadog dashboard.
Alternative: the DatadogConnector component
If you prefer to manage tracing as part of your pipeline definition (for example, so it serializes to YAML), you can add the DatadogConnector component instead. It enables the same Datadog tracing as soon as it is initialized.
See the DatadogConnector documentation page for full usage examples, or check out the integration page.