- Find root causes — Determine if bad answers stem from missing chunks or generation errors.
- Improve accuracy — Identify failing queries and adjust prompts, or the search configuration.
- Track latency — Measure time spent in retrieval vs generation to optimize the right component.
- Collect feedback — Use thumbs up/down signals from users to surface problem areas.
Tracing with Langfuse
Langfuse traces LLM calls through OpenTelemetry. The patterns below reflect the v5 JS/TS SDK and the Python SDK.Initialize tracing
Register the Langfuse span processor once at startup, before your application code runs. Only enable tracing when the keys are set so the SDK is a no-op in environments without credentials.Trace LLM calls
With the AI SDK, setexperimental_telemetry to capture each call as a generation. Use functionId to label the step and metadata to attach context you can filter on later. In Python, the @observe decorator traces the wrapped function; LLM calls are captured automatically through the Langfuse OpenAI wrapper.
Group traces by session and user
For multi-step or agentic flows, set trace-level attributes once so every search and generation in the request lands in the same trace. Setting asessionId groups the turns of one conversation; userId lets you trace activity per user. Call this as early as possible in the request.
Link prompts to traces
If you manage system prompts in Langfuse prompt management, link the prompt version to each generation. This tracks quality and cost per prompt version so you can compare iterations. Pass the prompt object through telemetry metadata aslangfusePrompt.
Log search results
To inspect retrieval quality separately from generation, capture the search as its own observation within the trace. This shows which chunks were retrieved and their scores alongside the answer.Tracing with Helicone
Helicone traces LLM calls through a proxy. Change your OpenAI base URL to route requests through Helicone.Next steps
- Search — Configure search parameters
- Ranking — Improve retrieval quality with reranking
- Data Segregation — Isolate data for multi-tenant applications