AI observability: how do you trace and log LLM calls in prod?
219 views
10 of 83
1
The problem
Question presented to candidate:
"Our agent makes two or three model calls and a tool call per user request, and when something is slow or wrong we cannot tell which step it was. How would you add tracing so we can see each LLM call in production, and what standard would you follow so we are not locked into one vendor?"
What a strong answer should cover:
What a trace and a span are: one trace per user request, one span per step (retrieval, each model call, each tool call) with a parent, start time, duration, status and attributes, so the request shows up as a timed tree
OpenTelemetry as the vendor-neutral standard, and its GenAI semantic conventions: span names like chat {model}, attributes such as gen_ai.operation.name, gen_ai.provider.name, gen_ai.request.model, gen_ai.usage.input_tokens and gen_ai.response.finish_reasons, CLIENT span kind for remote model calls; the conventions are still marked as in development, so names can change
Context propagation across services with the W3C traceparent header, so a tool call to another service joins the same trace
Prompt and response content is opt-in (off by default in the OpenTelemetry instrumentations) because of privacy and size; redact before export
Sampling: keep all errors and slow traces with tail-based sampling in a collector, sample the rest; and send the data to any OTLP-compatible backend or LLM observability tool
Code / implementation expected: Optional โ wrapping a model call in a span with GenAI attributes, or enabling an SDK's built-in telemetry.
observability
tracing
2
Try it yourself
Sketch your approach before you read the solution. That is what the interview tests.
Stuck? Get a hint.
A short nudge toward the approach. It will not give the answer away.
3
Solution
Target Audience: Developers who have an LLM feature or agent in production and want to see each model call, tool call and its timing; no prior observability experience assumed.
Difficulty: Easy
Verified with: Node 22.22.0 and Python 3.12.3 (the in-process tracer below, identical output in both). OpenTelemetry convention names, the W3C header format and SDK options were checked with web searches in October 2026; where only secondary sources were found, the text says so.
How to read this doc: Every idea is explained in plain language first, then tagged with ๐ Interview term: so you also learn the words an interviewer expects. All program output shown was produced by actually running the example; the Verified section quotes it in full.
1. Why This Even Matters โ A Story First
You send a parcel across the country. It takes nine days instead of two. If all you k
The solution is hidden so you can try first
15 min read ยท 12 sections
4
Read the code
Minimal tracer: GenAI spans, traceparent across a service hop, tail sampling