|
| 1 | +--- |
| 2 | +title: "Datadog" |
| 3 | +id: integrations-datadog |
| 4 | +description: "Datadog integration for Haystack" |
| 5 | +slug: "/integrations-datadog" |
| 6 | +--- |
| 7 | + |
| 8 | + |
| 9 | +## haystack_integrations.components.connectors.datadog.datadog_connector |
| 10 | + |
| 11 | +### DatadogConnector |
| 12 | + |
| 13 | +DatadogConnector connects Haystack to [Datadog](https://www.datadoghq.com/) in order to enable the tracing of |
| 14 | + |
| 15 | +operations and data flow within the components of a pipeline. |
| 16 | + |
| 17 | +To use the DatadogConnector, add it to your pipeline without connecting it to any other component. It will |
| 18 | +automatically trace all pipeline operations when tracing is enabled. |
| 19 | + |
| 20 | +**Environment Configuration:** |
| 21 | + |
| 22 | +- `HAYSTACK_CONTENT_TRACING_ENABLED`: Must be set to `"true"` to trace the content (inputs and outputs) of the |
| 23 | + pipeline components. |
| 24 | +- Datadog is configured through the standard `ddtrace` mechanisms, e.g. the `DD_SERVICE`, `DD_ENV` and |
| 25 | + `DD_VERSION` environment variables or by running your application with the `ddtrace-run` command. See the |
| 26 | + [ddtrace documentation](https://ddtrace.readthedocs.io/en/stable/) for more details. |
| 27 | + |
| 28 | +Here is an example of how to use the DatadogConnector in a pipeline: |
| 29 | + |
| 30 | +```python |
| 31 | +import os |
| 32 | + |
| 33 | +os.environ["HAYSTACK_CONTENT_TRACING_ENABLED"] = "true" |
| 34 | + |
| 35 | +from haystack import Pipeline |
| 36 | +from haystack.components.builders import ChatPromptBuilder |
| 37 | +from haystack.components.generators.chat import OpenAIChatGenerator |
| 38 | +from haystack.dataclasses import ChatMessage |
| 39 | +from haystack_integrations.components.connectors.datadog import DatadogConnector |
| 40 | + |
| 41 | +pipe = Pipeline() |
| 42 | +pipe.add_component("tracer", DatadogConnector("Chat example")) |
| 43 | +pipe.add_component("prompt_builder", ChatPromptBuilder()) |
| 44 | +pipe.add_component("llm", OpenAIChatGenerator(model="gpt-4o-mini")) |
| 45 | + |
| 46 | +pipe.connect("prompt_builder.prompt", "llm.messages") |
| 47 | + |
| 48 | +messages = [ |
| 49 | + ChatMessage.from_system("Always respond in German even if some input data is in other languages."), |
| 50 | + ChatMessage.from_user("Tell me about {{location}}"), |
| 51 | +] |
| 52 | + |
| 53 | +response = pipe.run( |
| 54 | + data={"prompt_builder": {"template_variables": {"location": "Berlin"}, "template": messages}} |
| 55 | +) |
| 56 | +print(response["llm"]["replies"][0]) |
| 57 | +``` |
| 58 | + |
| 59 | +#### __init__ |
| 60 | + |
| 61 | +```python |
| 62 | +__init__(name: str = 'datadog') -> None |
| 63 | +``` |
| 64 | + |
| 65 | +Initialize the DatadogConnector component. |
| 66 | + |
| 67 | +**Parameters:** |
| 68 | + |
| 69 | +- **name** (<code>str</code>) – The name used to identify this tracing component. It is returned by the `run` method and can be |
| 70 | + used to mark traces produced by this connector. |
| 71 | + |
| 72 | +#### run |
| 73 | + |
| 74 | +```python |
| 75 | +run() -> dict[str, str] |
| 76 | +``` |
| 77 | + |
| 78 | +Runs the DatadogConnector component. |
| 79 | + |
| 80 | +**Returns:** |
| 81 | + |
| 82 | +- <code>dict\[str, str\]</code> – A dictionary with the following keys: |
| 83 | +- `name`: The name of the tracing component. |
| 84 | + |
| 85 | +#### to_dict |
| 86 | + |
| 87 | +```python |
| 88 | +to_dict() -> dict[str, Any] |
| 89 | +``` |
| 90 | + |
| 91 | +Serialize this component to a dictionary. |
| 92 | + |
| 93 | +**Returns:** |
| 94 | + |
| 95 | +- <code>dict\[str, Any\]</code> – The serialized component as a dictionary. |
| 96 | + |
| 97 | +#### from_dict |
| 98 | + |
| 99 | +```python |
| 100 | +from_dict(data: dict[str, Any]) -> DatadogConnector |
| 101 | +``` |
| 102 | + |
| 103 | +Deserialize this component from a dictionary. |
| 104 | + |
| 105 | +**Parameters:** |
| 106 | + |
| 107 | +- **data** (<code>dict\[str, Any\]</code>) – The dictionary representation of this component. |
| 108 | + |
| 109 | +**Returns:** |
| 110 | + |
| 111 | +- <code>DatadogConnector</code> – The deserialized component instance. |
| 112 | + |
| 113 | +## haystack_integrations.tracing.datadog.tracer |
| 114 | + |
| 115 | +### DatadogSpan |
| 116 | + |
| 117 | +Bases: <code>Span</code> |
| 118 | + |
| 119 | +#### __init__ |
| 120 | + |
| 121 | +```python |
| 122 | +__init__(span: ddSpan) -> None |
| 123 | +``` |
| 124 | + |
| 125 | +Creates an instance of DatadogSpan. |
| 126 | + |
| 127 | +#### set_tag |
| 128 | + |
| 129 | +```python |
| 130 | +set_tag(key: str, value: Any) -> None |
| 131 | +``` |
| 132 | + |
| 133 | +Set a single tag on the span. |
| 134 | + |
| 135 | +**Parameters:** |
| 136 | + |
| 137 | +- **key** (<code>str</code>) – the name of the tag. |
| 138 | +- **value** (<code>Any</code>) – the value of the tag. |
| 139 | + |
| 140 | +#### raw_span |
| 141 | + |
| 142 | +```python |
| 143 | +raw_span() -> Any |
| 144 | +``` |
| 145 | + |
| 146 | +Provides access to the underlying span object of the tracer. |
| 147 | + |
| 148 | +**Returns:** |
| 149 | + |
| 150 | +- <code>Any</code> – The underlying span object. |
| 151 | + |
| 152 | +#### get_correlation_data_for_logs |
| 153 | + |
| 154 | +```python |
| 155 | +get_correlation_data_for_logs() -> dict[str, Any] |
| 156 | +``` |
| 157 | + |
| 158 | +Return a dictionary with correlation data for logs. |
| 159 | + |
| 160 | +### DatadogTracer |
| 161 | + |
| 162 | +Bases: <code>Tracer</code> |
| 163 | + |
| 164 | +#### __init__ |
| 165 | + |
| 166 | +```python |
| 167 | +__init__(tracer: ddTracer) -> None |
| 168 | +``` |
| 169 | + |
| 170 | +Creates an instance of DatadogTracer. |
| 171 | + |
| 172 | +#### trace |
| 173 | + |
| 174 | +```python |
| 175 | +trace( |
| 176 | + operation_name: str, |
| 177 | + tags: dict[str, Any] | None = None, |
| 178 | + parent_span: Span | None = None, |
| 179 | +) -> Iterator[Span] |
| 180 | +``` |
| 181 | + |
| 182 | +Activate and return a new span that inherits from the current active span. |
| 183 | + |
| 184 | +#### current_span |
| 185 | + |
| 186 | +```python |
| 187 | +current_span() -> Span | None |
| 188 | +``` |
| 189 | + |
| 190 | +Return the current active span |
0 commit comments