Haystack Instrumentation
Learn how to instrument Haystack pipelines with LangWatch using community OpenTelemetry instrumentors.
LangWatch does not have a built-in auto-tracking integration for Haystack from deepset.ai. However, you can leverage community-provided OpenTelemetry instrumentors to integrate your Haystack pipelines with LangWatch.
Integrating Community Instrumentors with LangWatch
Community-provided OpenTelemetry instrumentors for Haystack allow you to automatically capture detailed trace data from your Haystack pipeline components (Nodes, Pipelines, etc.). LangWatch can seamlessly integrate with these instrumentors.
There are two main ways to integrate these:
1. Via langwatch.setup()
You can pass an instance of the Haystack instrumentor to the instrumentors
list in the langwatch.setup()
call. LangWatch will then manage the lifecycle of this instrumentor.
Ensure you have the respective community instrumentation library installed:
- For OpenInference:
pip install openinference-instrumentation-haystack
- For OpenLLMetry:
pip install opentelemetry-instrumentation-haystack
You’ll also need Haystack:pip install farm-haystack[openai]
(if using OpenAI models). Consult the specific library’s documentation for the exact package name and instrumentor class if the above assumptions are incorrect.
2. Direct Instrumentation
If you have an existing OpenTelemetry TracerProvider
configured in your application (or if LangWatch is configured to use the global provider), you can use the community instrumentor’s instrument()
method directly. LangWatch will automatically pick up the spans generated by these instrumentors as long as its exporter is part of the active TracerProvider
.
Key points for community instrumentors:
- These instrumentors typically patch Haystack at a global level or integrate deeply with its execution flow (e.g., via
BaseComponent
orPipeline
hooks), meaning most Haystack operations should be captured once instrumented. - If using
langwatch.setup(instrumentors=[...])
, LangWatch handles the setup and lifecycle of the instrumentor. - If instrumenting directly (e.g.,
HaystackInstrumentor().instrument()
), ensure that theTracerProvider
used by the instrumentor is the same one LangWatch is exporting from. This usually means LangWatch is configured to use an existing global provider or one you explicitly pass tolangwatch.setup()
. - Always refer to the specific documentation of the community instrumentor (OpenInference or OpenLLMetry) for the most accurate and up-to-date installation and usage instructions, including the correct class names for instrumentors and any specific setup requirements for different Haystack versions or components.
- The examples use a
PromptNode
with an OpenAI model for simplicity. Ensure you have the necessary API keys (e.g.,OPENAI_API_KEY
) set in your environment if you run these examples.