haystack
39 строк · 1.8 Кб
1---
2features:
3- |
4Added out-of-the-box support for the OpenTelemetry Tracer. This allows you to instrument pipeline and component
5runs using OpenTelemetry and send traces to your preferred backend.
6
7To use the OpenTelemetry Tracer you need to have the `opentelemetry-sdk` package installed in your environment.
8To instruct Haystack to use the OpenTelemetry Tracer, you have multiple options:
9
10* Run your Haystack application using the `opentelemetry-instrument` command line tool as described in the
11[OpenTelemetry documentation](https://opentelemetry.io/docs/languages/python/automatic/#configuring-the-agent).
12This behavior can be disabled by setting the `HAYSTACK_AUTO_TRACE_ENABLED_ENV_VAR` environment variable to `false`.
13* Configure the tracer manually in your code using the `opentelemetry` package:
14```python
15from opentelemetry import trace
16from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter
17from opentelemetry.sdk.trace import TracerProvider
18from opentelemetry.sdk.trace.export import BatchSpanProcessor
19
20# Service name is required for most backends
21resource = Resource(attributes={
22SERVICE_NAME: "haystack"
23})
24
25traceProvider = TracerProvider(resource=resource)
26processor = BatchSpanProcessor(OTLPSpanExporter(endpoint="http://localhost:4318/v1/traces"))
27traceProvider.add_span_processor(processor)
28trace.set_tracer_provider(traceProvider)
29
30# Auto-configuration
31import haystack.tracing
32haystack.tracing.auto_enable_tracing()
33
34# Or explicitly
35from haystack.tracing import OpenTelemetryTracer
36
37tracer = traceProvider.get_tracer("my_application")
38tracing.enable_tracing(OpenTelemetryTracer(tracer))
39```
40