Skip to content

Log the signal the incident will need

Given a production incident nobody could diagnose, identify the missing signal (trace, tool call record, token usage, stop reason, request ID or user identity) and pick the monitoring that would have caught it.

Scenario

A tenant on a property-management platform complains that the maintenance assistant "keeps stopping mid-sentence". The team searches the logs. They find the request: HTTP 200, 2.1 seconds, no error.

Everything they logged says the request succeeded. The one field that would have explained it was never recorded.

Explanation

At scale you can't reread conversations. You find problems in signals, so the question is which signals you record before the incident.

Signal What it answers Example
Trace per request Where did the time or the failure happen? One trace with spans for retrieval, each model request (model, latency, tokens) and each tool call
Tool call records What did the agent do, and did it work? Tool name, success or error, result size; inputs only if your policy allows
Token usage Why did cost or context change? input_tokens, output_tokens, cache_read_input_tokens, cache_creation_input_tokens from each response's usage
Stop reason Did the answer finish? stop_reason of max_tokens means the output was cut off; end_turn means it finished
Request ID Which API call was it? The request-id header on every response (_request_id in the Python and TypeScript SDKs), which Anthropic support asks for
Identity and version Who was affected, under which release? End-user or tenant ID, prompt version, model

Three things to know:

  • Identity isn't automatic. Agent SDK telemetry identifies the credential your service uses, not the end user it acted for. Add the user or tenant as an attribute yourself, or you can't say whose requests failed.
  • Agent SDK telemetry is structural by default. Durations, model and tool names, and token counts are recorded; prompt text, tool inputs and tool output are opt-in. Turn them on only if your observability platform is approved for that data.
  • Alert on rates and distributions, not single events: p95 latency per span, share of max_tokens stops, tool error rate, cache-read share, cost per request per tenant. A healthy average can hide a failing slice.

Worked example

The incident: answers cut off mid-sentence for some tenants.

Before: the app logged HTTP status, total duration and the reply text. All looked normal: a truncated reply is still a successful response.

After: the team records the stop reason and usage on every response and alerts on the share of max_tokens stops:

resp = client.messages.create(**request)
log.info(
    "claude_response",
    request_id=resp._request_id,
    tenant=tenant_id,
    prompt_version=PROMPT_VERSION,
    stop_reason=resp.stop_reason,
    input_tokens=resp.usage.input_tokens,
    output_tokens=resp.usage.output_tokens,
)

Within a day the dashboard shows 6% of responses stopping at max_tokens, all from a prompt version that asks for a step-by-step repair checklist. The cause is visible in one field, and the alert would have fired on release day.