Haystack by deepset Integration
Updated on Aug 14, 2026
Use this integration when your Haystack application is implemented in Python.
Setup
- Install SDK
bash
pip install progress-observability
- Instrument your app
python
Observability.instrument(
app_name=os.getenv("OBSERVABILITY_APP_NAME"),
api_key=os.getenv("OBSERVABILITY_API_KEY")
)
- Complete example
Note: Haystack doesn't emit OpenTelemetry spans natively. Calling
tracing.enable_tracing(OpenTelemetryTracer(...))afterObservability.instrument()connects Haystack's internal tracer to the OTel pipeline, giving you a structured trace tree with LLM calls and tool invocations under the same trace.
python
import os
from dotenv import load_dotenv
load_dotenv()
os.environ["HAYSTACK_CONTENT_TRACING_ENABLED"] = "true"
from haystack.components.agents import Agent
from haystack.tools import Tool
from haystack.components.generators.chat import OpenAIChatGenerator
from haystack.utils import Secret
from haystack.dataclasses import ChatMessage
from haystack import tracing
from haystack_integrations.tracing.opentelemetry import OpenTelemetryTracer
from opentelemetry import trace as otel_trace
from progress.observability import Observability
# Instrument: sets up the exporter and patches the OpenAI client for LLM spans.
Observability.instrument(
app_name=os.getenv("OBSERVABILITY_APP_NAME"),
api_key=os.getenv("OBSERVABILITY_API_KEY"),
)
# Enable Haystack's OTel tracer so agent and tool spans are part of the same trace.
tracing.enable_tracing(OpenTelemetryTracer(otel_trace.get_tracer("haystack")))
def get_weather(location: str) -> str:
"""Get the weather for a given location."""
return f"The weather in {location} is cloudy with a high of 15°C."
weather_tool = Tool(
name="get_weather",
description="Get the weather for a given location.",
parameters={
"type": "object",
"properties": {"location": {"type": "string", "description": "City or location name"}},
"required": ["location"],
},
function=get_weather,
)
model = os.getenv("OPENAI_MODEL", "gpt-4o-mini")
agent = Agent(
chat_generator=OpenAIChatGenerator(
api_key=Secret.from_token(os.getenv("OPENAI_API_KEY", "")),
model=model,
),
tools=[weather_tool],
system_prompt="You are a helpful AI assistant.",
tool_concurrency_limit=1,
)
result = agent.run(messages=[ChatMessage.from_user("What's the weather in Paris?")])
Observability.shutdown()