Logging and Observability
Explore how to trace and log data flow within production LLM pipelines to debug issues without storing raw data. Understand structured logging for metadata, implement tracing spans for retrieval and model calls, and differentiate between in-app and proxy observability. Learn to monitor key signals such as latency, error rates, and cache hits to detect silent failures and maintain pipeline reliability.
Users report a symptom that does not crash anything. The FastAPI endpoint returns 200, but the answer sometimes contains stale facts, and no one can reproduce it locally because local traffic, indexes, and caches differ from production.
This lesson covers the evidence that lets you replay what happened to a single request after the fact, without storing raw user text or secrets.
Trace one request as data flow
With a nondeterministic model call and a changing retrieval index, the only stable debugging unit is a single request moving through the full pipeline. Start at the HTTP boundary, then follow the data through auth and context attachment, retrieval or tool steps, the provider call, post-processing, and the response.
At each boundary, emit evidence that lets you correlate behavior later.
At ingress, emit
request_id,route, anduser_id_hash.At prompt assembly, emit
prompt_versionplus a stableinput_hashfor the user text.At retrieval, emit the
retrieval_queryplustop_kandretrieval_hit_ids.At the provider call, emit
provider,model, generation parameters, andprovider_latency_ms.At post-processing, emit
output_schema_okand any guardrail flags.At egress, emit
status_code,latency_ms, and, if available,tokens_inandtokens_out. ...