← govind p lal
AI and ML Bootcamp · Lecture 24 · lecture notes

LLM Observability

In short — Once an agent runs in production, printing outputs is not enough to find what is slow, costly or wrong. This lecture covers why print fails, how traces, spans and attributes give structure, how OpenTelemetry carries the data, and what LLM-specific platforms like Langfuse add. It ends with model routing to cut cost and a short note on fusion-style orchestrators.

Why observability

Building an agent locally, you run it and look at the output. The trouble starts in production, and sometimes in development too. You need to know which stage is bad: the input, the retrieval, the decision, or the LLM call.

!

Observability does not raise performance by itself. It lets you see, so you can take action: fix caching, make a step async, correct inputs.

Why print statements fail

Print loses structure. Therefore fails.

Flat printsStructured log
120k tokens, model, prompt, tool call, prompt, output ... in one line streamAgent -> Step 1 (prompt, model, tokens) -> Tool call 1 -> Step 2 -> sub-steps
Hunt for step 2, then its LLM call, then why it is slowSee step 2, its prompt, model, tokens and slow sub-step at a glance

What we need: structure, parent-child relationships, and the ability to query.

Trace, span, attributes

Example

Medical QA agent (trace): fetch patient history (span) -> LLM call to assess recent problems (span) -> tool call to fetch data (span) -> tool call to check if immediate help is needed (span) -> final LLM call (span).

childTracemedical QA agentSpan: patienthistorySpan: LLM callSpan: tool callSpan: final LLM call
A trace is a tree of spans.

Because of this tree, time order (what happened before and after what) is preserved. Causality -> knowing what happened at which stage and after what.

OpenTelemetry and the export pipeline

Standard for describing what happens inside any running system (backends, infra, LLM agents) -> OpenTelemetry. It does not care about the vendor. Platforms differ only in how they show the data.

spansbatchsendYour codeSDK emits spansSpan processorcollects, batchesExporterOTLP formatBackendLangfuse etc.
Spans are batched locally, then exported to the backend.

Project idea: build a minimal observability tool on raw OpenTelemetry. Additions Langfuse lacks: chat with your traces, suggestions from traces, and a daily summary page of failed tools and LLM calls.

What LLM observability platforms add

OpenTelemetry gives structure and chronological order. But its raw output is JSON full of ids, very hard to read. General APM tools (application performance monitoring) like Datadog or Better Stack show what goes in and out, but not tokens consumed or which prompt ran at which stage.

ToolNote
LangfuseOpen source, self-hostable
LangSmithFits the LangChain / deep agents ecosystem
Helicone and othersSame core idea, different extras

Scores - a number attached to a trace.

from langfuse import observe

@observe()
def agent_step(prompt):
    ...

Cutting cost in production: model routing and fusion

splitTaskTop orchestratorfrontier modelSub-task Acheaper modelSub-task Bfrontier modelSub-task Cmid model
Fusion-style routing: frontier model plans, sub-tasks go to models by complexity.

Loop engineering

adds to earlier · The two required ingredients (task and completion signal), a test-loop example, and context threshold handling in loops. · builds on Lecture 23: Week 23 - AI&ML | Hugging Face End-to-End | 20/06/2026

Glossary

Observability
Logging what happens inside each step of an agent so it can be inspected and debugged.
Trace
The full lifecycle of one agent request, the root of a tree of spans.
Span
One operation inside a trace, such as an LLM call or tool call; spans can nest.
Attributes
Key-value metadata attached to a span, like latency, model, user or cost.
OpenTelemetry
Vendor-neutral industry standard for describing what happens inside a running system.
OTLP
OpenTelemetry Protocol, the format used to export telemetry data.
APM
Application performance monitoring, general tools like Datadog that are not LLM-aware.
Model routing
Sending different steps or tasks to different models to save cost.
Score
A number attached to a trace from an LLM judge, heuristic or human.