Integrations / Haystack
To trace Haystack with Tracify, wrap the function that calls pipeline.run with trace_agent and open a step for the part you want to inspect. The run shows timing, inputs and outputs for each step.
Your code
Haystack
Tracify
One run.
Setup
Haystack and the Tracify SDK.
pip install tracify-sdk haystack-aiCreate a project in Tracify, copy its API key and put it in the environment where your code runs. The SDK reads it from there, so nothing is hard-coded.
export TRACIFY_API_KEY="tracify_sk_live_..."One function, one run. The step shows the whole pipeline as a single timed block with its input and the reply.
import tracify
@tracify.trace_agent(name="haystack-rag")
def answer(question: str) -> str:
with tracify.span("pipeline", type="agent", input=question) as step:
result = pipeline.run({
"retriever": {"query": question},
"prompt_builder": {"question": question},
})
reply = result["llm"]["replies"][0]
step.set_output(reply)
return replyTo see retrieval separately from generation, run the retriever on its own inside its own step.
@tracify.trace_agent(name="haystack-split")
def answer(question: str) -> str:
with tracify.span("retrieve", type="retrieval", input=question) as step:
docs = retriever.run(query=question)["documents"]
step.set_output([d.content[:200] for d in docs])
with tracify.span("generate", type="llm", input=question) as step:
out = generator.run(prompt=build_prompt(question, docs))
step.set_output(out["replies"][0])
return out["replies"][0]Run your code one time, then open the Tracing page of your project. Your pipeline shows up as a run with its steps in order, plus the tokens, time and any error for each call.
Good to know
The SDK does not hook into every Haystack component by itself. You decide which parts are worth a step, and each step you add shows up in the run.
Full details in the documentation. All integrations are listed on the integrations page.
