Search⌘ K
AI Features

Instrument a Chat Turn: Correlation, Timings, and Outcomes

Explore how to instrument chat turns using structured JSON events that include correlation IDs, timing measures, and outcome classifications. Understand how to consistently log every phase and reconstruct turn timelines for diagnosing stalls, errors, and cancellations in AI-driven chat features.

A taxonomy gives every failure a name. This lesson is about writing that name down consistently enough, with the right IDs and timings attached, that someone reading the logs later can reconstruct exactly what happened.

Why do users report that it hangs? A console log like console.log("sending") and another like console.log("done") cannot answer that when the tab reloads, the stream disconnects mid-flight, or two turns overlap. The smallest thing that stays useful after the fact is one structured JSON event emitted for every turn, with IDs that let you join related events and one timing number that lets you spot stalls.

A minimal event envelope that already ties into an error taxonomy is a single object with turnId, attemptId, and callId when a tool call is involved, plus phase, elapsedMs, and outcome when relevant. If phase is consistent across the UI, proxy, and server logs, you can reconstruct one turn’s timeline even when generation fails ...