Haystack
Trace Haystack pipelines with cetra from Python: components and model calls.
Install
Section titled “Install”pip install "cetra-sdk[haystack]" haystack-aiSet up
Section titled “Set up”import os
import cetrafrom haystack import Pipelinefrom haystack.components.builders import ChatPromptBuilderfrom haystack.components.generators.chat import OpenAIChatGeneratorfrom haystack.dataclasses import ChatMessagefrom haystack.utils import Secret
cetra.init(instrument=["haystack"])
pipeline = Pipeline()pipeline.add_component( "prompt", ChatPromptBuilder( template=[ChatMessage.from_user("Capital of {{country}}?")], required_variables=["country"], ),)pipeline.add_component( "llm", OpenAIChatGenerator( model="gpt-4o-mini", api_key=Secret.from_token(os.environ["OPENAI_API_KEY"]), ),)pipeline.connect("prompt.prompt", "llm.messages")pipeline.run({"prompt": {"country": "France"}})
cetra.flush()What you get
Section titled “What you get”- The pipeline run is a
chainspan (Pipeline.run), with achainspan per component. - The generator’s call is an
llmspan with the messages, the token counts and the cost, computed from the built-in prices.
Limits
Section titled “Limits”- Do not also enable
openai: the model call would be recorded twice and counted twice. - The
Agentcomponent is not traced as an agent: its model calls appear as separate traces. - Haystack sends its own telemetry unless
HAYSTACK_TELEMETRY_ENABLEDisFalse. - The fixture was captured with haystack-ai 3.5.0 and openinference-instrumentation-haystack 0.1.53.
- If a field is missing, look at the span’s Attributes tab and compare it with Span attributes.
- Traces: read the trace as a tree and a timeline.
- Cost and tokens: how cost is computed from the token counts.
- Online rules: score these traces automatically.