Integrations / Haystack
To trace Haystack with Uncoil, 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
Uncoil
One run.
Setup
Haystack and the Uncoil SDK.
pip install uncoil-sdk haystack-aiCreate a project in Uncoil, 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 UNCOIL_API_KEY="uncoil_sk_live_..."One function, one run. The step shows the whole pipeline as a single timed block with its input and the reply.
import uncoil
@uncoil.trace_agent(name="haystack-rag")
def answer(question: str) -> str:
with uncoil.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.
@uncoil.trace_agent(name="haystack-split")
def answer(question: str) -> str:
with uncoil.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 uncoil.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.
