Three pillars primer: logs, metrics, traces

Observability has three complementary signals. Logs answer "what happened". Metrics answer "how much, how often". Traces answer "why did this request take this path and this long". An LLM app needs all three, but traces are where you spend most of your debugging time.

Three pillars and the questions they answer

Matching exercise: Match the question to the signal

Loading practice…

No. Traces are for causal, per-request debugging. Logs are still the right tool for audit events, background job checkpoints, and anything that has to survive even when tracing is disabled for cost reasons. The win is that structured JSON logs can carry the same request ID your trace uses, so you can jump between them.

observability/tracer.py
python
from opentelemetry import trace

# A tracer is a factory for spans scoped to one library or module.
tracer = trace.get_tracer("agent.router")

with tracer.start_as_current_span("route_question") as span:
    span.set_attribute("llm.system", "openai")
    span.set_attribute("llm.model", "gpt-4o-mini")
    # ... call the LLM, record the route
    span.set_attribute("agent.route", "sql")

One span, one unit of work. Attributes describe what that unit did. Later lessons wire this decorator-style so you do not write it by hand.

Quiz: Quiz

Loading practice…