Tracing and LLM Observability

Capture every prompt, response, tool call, token count and latency in structured traces so you can debug and monitor real usage.

Intermediate · about 4 hours · difficulty 3/5

Learn first: The Agent Loop

In production you need to answer questions like "why did the bot say that to this user yesterday?" and "which step makes this request slow?". Tracing records each request as a tree of spans: the model calls, retrieval steps, tool calls and their inputs, outputs, tokens, cost and duration.

What to capture

  • Full prompts and completions (subject to your privacy policy), model name and parameters.
  • Token usage, cost estimate, latency and time to first token.
  • Retrieved documents and their scores for RAG requests.
  • Tool calls, arguments, results and errors for agents.
  • User and session ids, prompt version, and any user feedback.

Tools

  • Langfuse: open source, self-hostable tracing, prompt management and evals.
  • LangSmith: tracing and evals from the LangChain team, framework agnostic.
  • OpenTelemetry: the vendor-neutral standard; its GenAI semantic conventions define attribute names for model calls, so traces can flow into any backend.
  • Others such as Arize Phoenix, Braintrust, Helicone and W&B Weave follow similar ideas.

Using traces

Build dashboards for cost per day, latency percentiles and error rates. Sample traces for manual review each week. Turn interesting traces into eval cases with one click. Set alerts on spikes in errors, refusals or cost.

Privacy

Traces contain user data. Redact PII where needed, restrict access, and set retention limits.

Good enough to move on

Your app sends traces for every request to Langfuse, LangSmith or an OpenTelemetry backend, and you can find a specific user's request and see every step with its cost and latency.

Key concepts

  • Traces, spans and sessions
  • Token, cost and latency metrics
  • Langfuse
  • LangSmith
  • OpenTelemetry GenAI conventions
  • Dashboards and alerts
  • Redaction and retention

Mini project

Instrument a RAG or agent app with Langfuse (or an OpenTelemetry backend), then build a dashboard of daily cost, p95 latency and error rate, and turn three bad traces into eval cases.

Check yourself

A user reports a wrong answer from last Tuesday. Walk through how your tracing lets you find the cause.

Free resources