Musterby Elitery
Integrations

Haystack

Trace deepset Haystack pipelines and agents in Muster via the OpenInference instrumentation.

Haystack is an open-source Python framework by deepset for building production-ready LLM applications with modular pipelines. Muster captures Haystack pipeline and agent runs through the OpenInference instrumentation.

Setup

1. Install dependencies

%pip install haystack-ai langfuse openinference-instrumentation-haystack

2. Configure credentials

import os

os.environ["LANGFUSE_PUBLIC_KEY"] = "pk-lf-..."
os.environ["LANGFUSE_SECRET_KEY"] = "sk-lf-..."
os.environ["LANGFUSE_BASE_URL"] = "https://app.getmuster.io"
os.environ["OPENAI_API_KEY"] = "sk-proj-..."
os.environ["SERPERDEV_API_KEY"] = "..."
from langfuse import get_client

langfuse = get_client()

if langfuse.auth_check():
    print("Muster client is authenticated and ready!")

3. Initialize instrumentation

from openinference.instrumentation.haystack import HaystackInstrumentor

HaystackInstrumentor().instrument()

4. Build and run a pipeline

from haystack.components.agents import Agent
from haystack.components.generators.chat import OpenAIChatGenerator
from haystack.dataclasses import ChatMessage
from haystack.tools import ComponentTool
from haystack.components.websearch import SerperDevWebSearch

search_tool = ComponentTool(component=SerperDevWebSearch())

basic_agent = Agent(
    chat_generator=OpenAIChatGenerator(model="gpt-4o-mini"),
    system_prompt="You are a helpful web agent.",
    tools=[search_tool],
)

result = basic_agent.run(
    messages=[ChatMessage.from_user("When was the first version of Haystack released?")]
)

print(result["last_message"].text)

langfuse.flush()

View results

Open Muster to explore traces with metrics including token counts, latencies, and execution paths.

Haystack trace example

Add user/session attributes

from langfuse import propagate_attributes

with propagate_attributes(user_id="user_123", session_id="sess_abc", tags=["haystack"]):
    basic_agent.run(...)

Troubleshooting

  • Enable debug logging: export LANGFUSE_DEBUG="True".
  • Call langfuse.flush() at application end.
  • Verify API keys and base URL.

See also