Add structured timing logs to stream-query for slow-request diagnosis #51
Reference in New Issue
Block a user
Delete Branch "stream-observability"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Every
stream-querySSE request now emits a JSON summary line to the logger on completion, cancellation, or error.What it logs
total_msthinking_msttft_mstokenstoolsmodelcancelledtruewhen client disconnected mid-streamTool timers use the LangChain
run_idto correctly pair start/end even when the same tool is called multiple times in one turn.Querying
What the fields tell you about slow requests:
thinking_mslarge → reasoning is the bottleneckms→ external API is slow (Tavily, YNAB, etc.)total_ms>>ttft_ms+ tools → long generation (many output tokens)model≠llama→ OpenAI fallback fired74/74 tests pass. No schema changes.
🤖 Generated with Claude Code
Every SSE request emits a JSON summary line on completion, cancellation, or error: {"event":"stream_request","conv":"...","user":"ryan", "total_ms":45210,"thinking_ms":38100,"ttft_ms":38200, "tokens":112,"tools":[{"tool":"web_search","ms":820}], "model":"llama","cancelled":false} Fields: - total_ms end-to-end wall time - thinking_ms time from first LLM call to first content token (reasoning) - ttft_ms time to first content token from request start - tokens approximate content token count (stream deltas) - tools each tool invoked with wall-clock duration - model LLM name from LangChain metadata (catches fallback to OpenAI) - cancelled true when client disconnected mid-stream Tool timers use the LangChain run_id to correctly pair start/end even when the same tool is called multiple times in one turn. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>fc9e11ba69toc071fd12e1