|
| 1 | +--- |
| 2 | +layout: integration |
| 3 | +name: Datadog |
| 4 | +description: Monitor and trace your Haystack pipelines with Datadog. |
| 5 | + |
| 6 | +authors: |
| 7 | + - name: deepset |
| 8 | + socials: |
| 9 | + github: deepset-ai |
| 10 | + twitter: haystack_ai |
| 11 | + linkedin: https://www.linkedin.com/company/deepset-ai/ |
| 12 | +pypi: https://pypi.org/project/datadog-haystack/ |
| 13 | +repo: https://github.com/deepset-ai/haystack-core-integrations/tree/main/integrations/datadog |
| 14 | +type: Monitoring Tool |
| 15 | +report_issue: https://github.com/deepset-ai/haystack-core-integrations/issues |
| 16 | +logo: /logos/datadog.png |
| 17 | +version: Haystack 2.0 |
| 18 | +toc: true |
| 19 | +--- |
| 20 | +### **Table of Contents** |
| 21 | +- [Overview](#overview) |
| 22 | +- [Installation](#installation) |
| 23 | +- [Usage](#usage) |
| 24 | +- [License](#license) |
| 25 | + |
| 26 | +## Overview |
| 27 | + |
| 28 | +This integration lets you use [Datadog](https://www.datadoghq.com/) to trace and monitor your Haystack |
| 29 | +pipelines and agents. It relies on [Datadog's tracing library `ddtrace`](https://ddtrace.readthedocs.io/en/stable/) |
| 30 | +and provides a `DatadogConnector` component that, once added to your pipeline, sends Haystack traces to Datadog. |
| 31 | + |
| 32 | +## Installation |
| 33 | + |
| 34 | +```bash |
| 35 | +pip install datadog-haystack |
| 36 | +``` |
| 37 | + |
| 38 | +## Usage |
| 39 | + |
| 40 | +Add the `DatadogConnector` to your pipeline without connecting it to any other component. It enables Datadog |
| 41 | +tracing for all pipeline operations. |
| 42 | + |
| 43 | +You also need to set the `HAYSTACK_CONTENT_TRACING_ENABLED` environment variable to `true` to trace the content |
| 44 | +(inputs and outputs) of the pipeline components. |
| 45 | + |
| 46 | +Datadog itself is configured through the standard `ddtrace` mechanisms, for example the `DD_SERVICE`, `DD_ENV` and |
| 47 | +`DD_VERSION` environment variables, or by running your application with the `ddtrace-run` command. See the |
| 48 | +[ddtrace documentation](https://ddtrace.readthedocs.io/en/stable/) for more details. |
| 49 | + |
| 50 | +```python |
| 51 | +import os |
| 52 | + |
| 53 | +os.environ["HAYSTACK_CONTENT_TRACING_ENABLED"] = "true" |
| 54 | + |
| 55 | +from haystack import Pipeline |
| 56 | +from haystack.components.builders import ChatPromptBuilder |
| 57 | +from haystack.components.generators.chat import OpenAIChatGenerator |
| 58 | +from haystack.dataclasses import ChatMessage |
| 59 | + |
| 60 | +from haystack_integrations.components.connectors.datadog import DatadogConnector |
| 61 | + |
| 62 | +pipe = Pipeline() |
| 63 | +pipe.add_component("tracer", DatadogConnector("Chat example")) |
| 64 | +pipe.add_component("prompt_builder", ChatPromptBuilder()) |
| 65 | +pipe.add_component("llm", OpenAIChatGenerator(model="gpt-4o-mini")) |
| 66 | + |
| 67 | +pipe.connect("prompt_builder.prompt", "llm.messages") |
| 68 | + |
| 69 | +messages = [ |
| 70 | + ChatMessage.from_system("Always respond in German even if some input data is in other languages."), |
| 71 | + ChatMessage.from_user("Tell me about {{location}}"), |
| 72 | +] |
| 73 | + |
| 74 | +response = pipe.run( |
| 75 | + data={"prompt_builder": {"template_variables": {"location": "Berlin"}, "template": messages}} |
| 76 | +) |
| 77 | +print(response["llm"]["replies"][0]) |
| 78 | +``` |
| 79 | + |
| 80 | +Your traces will then be available in your Datadog dashboard under the configured service. |
| 81 | + |
| 82 | +If you prefer not to use the connector, you can also enable the tracer manually: |
| 83 | + |
| 84 | +```python |
| 85 | +import ddtrace |
| 86 | +from haystack import tracing |
| 87 | +from haystack_integrations.tracing.datadog import DatadogTracer |
| 88 | + |
| 89 | +tracing.enable_tracing(DatadogTracer(ddtrace.tracer)) |
| 90 | +``` |
| 91 | + |
| 92 | +## License |
| 93 | + |
| 94 | +`datadog-haystack` is distributed under the terms of the [Apache-2.0](https://spdx.org/licenses/Apache-2.0.html) license. |
0 commit comments