Rubric
Contents — domains, guide and mocks

Monitoring with logs and usage data

CCAR-P 4.614 min read · checked 21 September 2026

Task statementMonitor system performance using logging and observability tools

From request to improvement

  1. Log every requestIDs, versions, usage, timing, outcome
  2. Aggregatethe 4.1 scorecard, live
  3. Alert and samplethresholds; graded transcripts
  4. Investigate and fixtrace by request ID

Each confirmed failure becomes an eval case; each fix ships through 4.3

Monitoring isn't the dashboard; it's the loop. Anything that fires an alert or fails a sampled grade ends up as a new eval case.

This lesson is about the practice of monitoring a Claude system so you can evaluate and improve it: what to record, which Anthropic tools report what, and how signals turn into fixes. Designing observability architecture for large, distributed deployments — tracing across services, sampling strategy at scale — is 3.4.

What every log line should carry

Anthropic's engineering team lists production monitoring as the layer that reveals real behaviour at scale and catches what synthetic evals missed — reactive and noisy, and only useful if the system is instrumented. The instrumentation is your application's log. The API gives you most of what you need in each response; your code adds the context the API can't know.

FieldWhere it comes fromWhy you need it
Request IDrequest-id header; _request_id in the Python and TypeScript SDKsTie a complaint to one exact call; quote it to support
Model, prompt version, variantYour codeAttribute a change in any metric to a deploy or an A/B arm
Input, cache and output tokensusage: input_tokens, cache_creation_input_tokens, cache_read_input_tokens, output_tokensCost per request and cache hit rate
stop_reasonResponseSpot truncation (max_tokens), refusals and tool loops
Time to first token, total timeYour timerLatency percentiles as users feel them
Tool calls and errorsYour agent loopFind failing tools and unexpected actions
Outcome signalYour product: resolved, escalated, thumbs-downConnect behaviour to the business metric
One structured log line per callpython
import json, time, logging
log = logging.getLogger("claude")

def call_claude(prompt_version: str, variant: str, **request):
    start = time.monotonic()
    r = client.messages.create(**request)
    u = r.usage
    log.info(json.dumps({
        "request_id": r._request_id,           # also in the request-id header
        "model": request["model"],
        "prompt_version": prompt_version,      # e.g. "support-v14"
        "variant": variant,                    # A/B arm, if any
        "stop_reason": r.stop_reason,
        "input_tokens": u.input_tokens,        # after the last cache breakpoint
        "cache_write": u.cache_creation_input_tokens,
        "cache_read": u.cache_read_input_tokens,
        "output_tokens": u.output_tokens,
        "latency_ms": round((time.monotonic() - start) * 1000),
    }))
    return r

From log lines to the live scorecard

The metrics you defined for release (4.1) are the metrics you watch in production. Aggregate them by model, prompt version and variant, as percentiles where they're times, and as rates where they're events. A few derived signals earn a place on every dashboard:

  • Stop-reason mix. Track stop_reason values: a jump in max_tokens means truncated answers; a jump in refusal means users or a change are hitting safeguards; more tool_use turns per task can mean an agent is looping.
  • Cost per successful task. Spend from usage divided by tasks your outcome signal marks as resolved — not cost per request.
  • Cache hit rate. Cache-read tokens as a share of all input tokens. A sudden fall usually means something now changes at the top of the prompt (4.5).
  • Errors by type. 429 rate limits, 529 overloads and 500s need different responses; the SDKs already retry transient failures twice by default, so count what still fails after retries.
  • p50 and p95 latency, and TTFT for streamed responses.

A weekly health check

  • Passes: p95 latency within target (3.0 s)2.4 s
  • Passes: Cost per resolved ticket within budget
  • Fails: max_tokens stops under 0.5%4.8% since support-v14
  • Check: Cache hit rate above 80%fell to 61% on Tuesday
  • Passes: Sampled transcripts pass the rubric judge200 graded, 94%
  • Missing: Injection attempts reviewedno screen on tool output yet
Most rows come straight from the log line above. The two that don't — sampled quality and injection attempts — need graders running on production traffic.

Watching quality, not just health

Error rates and latency tell you the system is up. They don't tell you it's right. To monitor accuracy and safety in production, sample real transcripts every day or week and run the same graders you use offline — the code checks, and the calibrated model judge from 4.2 — on them. Add a human review queue for flagged and low-scoring cases, and treat explicit user feedback as a signal rather than a census: Anthropic's engineers note it is sparse, self-selected and skewed towards severe problems.

Security needs its own watch. Anthropic's jailbreak guidance recommends continuously analysing outputs for signs of successful injection, and noticing users who repeatedly trigger the same refusals — then adjusting responses, throttling or banning as policy allows. That only works if refusals and screen results are logged with a user or session identifier.

Anthropic's monitoring tools, and what each is for

Where each signal comes from

Monitoring picture
  • Your app logsper request, with request ID
  • Usage & Cost APItokens and USD, organisation-wide
  • Console pagesUsage and Cost views
  • Claude Code telemetryOpenTelemetry metrics, events
  • Online graderssampled transcripts, scored
  • User feedbacksparse but specific
No single tool gives the full picture. The per-request view lives in your own logs; organisation-wide usage and spend come from Anthropic.

Usage & Cost Admin API. Two endpoints give organisation-level history: /v1/organizations/usage_report/messages for tokens (uncached input, cache writes, cache reads, output, and server-tool use), bucketed by 1m, 1h or 1d and filterable or groupable by API key, workspace, model, service tier and more; and /v1/organizations/cost_report for USD costs, daily only, groupable by workspace or description. It needs an Admin API credential, not a normal workspace key. Data typically appears within about five minutes, and polling once a minute is supported for sustained use. Priority Tier costs aren't in the cost endpoint. Similar data appears on the Console's Usage and Cost pages, and Anthropic lists ready-made integrations with platforms such as Datadog, Grafana Cloud and Honeycomb.

Claude Code telemetry. For teams using Claude Code, setting CLAUDE_CODE_ENABLE_TELEMETRY=1 with OpenTelemetry exporters sends metrics such as claude_code.token.usage, claude_code.cost.usage and claude_code.session.count, and events such as claude_code.api_request, claude_code.api_error and claude_code.tool_decision, to any OTLP-compatible backend. Administrators can push the configuration through managed settings so developers can't redirect it. For per-user cost breakdowns, the docs point to the separate Claude Code Analytics API.

Which tool answers this question?

What are you trying to find out?
  • Why did this answer fail?
    Your request logstrace by request ID
  • Spend by team or model?
    Usage & Cost APIAdmin API credential
  • How devs use Claude Code?
    OpenTelemetry exportmetrics and events
  • Is quality slipping?
    Sampled online gradingsame graders as offline

Traps the wrong answers are built from

Tempting but wrongDo this instead
Monitoring only availability and HTTP errorsWatch the full scorecard: accuracy via sampled grading, latency percentiles, cost per task, safety and security signals.
Log lines without model, prompt version or request IDTag every call so a change in any metric can be attributed and traced.
Relying on user complaints to detect quality problemsSample and grade production transcripts; treat feedback as one sparse signal.
Tracking spend only from the monthly invoiceUse the Usage & Cost API or Console for near-real-time, grouped usage and cost, with alerts.
Logging full prompts and responses everywhere by defaultLog metadata broadly; keep content in a restricted, time-limited store.

You should now be able to

  • Specify the fields a per-request log needs, including request ID, versions, usage, stop_reason and timing.
  • Derive production metrics — stop_reason mix, cost per successful task, cache hit rate, latency percentiles — from logs.
  • Set up online evaluation by sampling production transcripts through the same graders used offline.
  • Choose between application logs, the Usage & Cost Admin API, Console pages and Claude Code OpenTelemetry for a monitoring question.
  • Close the loop from alert to diagnosis to a new eval case.

Practice questions

Original questions written for this lesson, in the exam’s style. Answer first, then open the reasoning — every option is explained, including why the wrong ones are tempting.

  1. Question 1

    After a prompt update, some users of a report-writing feature say reports end abruptly. The team logs latency and HTTP status for every call, and nothing looks unusual.

    Which additional logged field would most directly confirm the cause?

    1. AThe stop_reason of each response, grouped by prompt version.
    2. BThe user's browser and operating system.
    3. CThe number of retries the SDK performed.
    4. DThe cache hit rate for the system prompt.
    Show answer and reasoning
    1. ACorrect. Abrupt endings match max_tokens stops; grouping by version ties them to the update.
    2. BIncorrect. Client details don't explain text that stops mid-sentence.
    3. CIncorrect. Retries relate to transient errors, not to how a successful response ended.
    4. DIncorrect. Caching affects cost and speed, not whether output is cut off.
  2. Question 2

    A finance team wants a daily breakdown of Claude API spend by workspace and model, with an alert when any workspace exceeds its budget.

    What is the most appropriate data source?

    1. ASum usage fields from each application's own logs.
    2. BThe token-counting endpoint run on each prompt.
    3. CThe Usage & Cost Admin API.
    4. DClaude Code OpenTelemetry metrics for the organisation.
    Show answer and reasoning
    1. AIncorrect. Possible, but it misses usage outside those apps and duplicates what Anthropic already reports.
    2. BIncorrect. Token counting estimates input before sending; it doesn't report actual usage or cost.
    3. CCorrect. It reports organisation-wide usage and daily USD cost, groupable by workspace and model, suitable for alerts.
    4. DIncorrect. Those cover Claude Code sessions, not all API traffic across workspaces.
  3. Question 3

    A team runs an A/B test of two prompts in production and later needs to explain why one variant's cost per resolved ticket rose.

    Which two fields must each log line carry for this analysis? (Select 2.)

    1. AThe prompt version or variant that served the request.
    2. BThe token counts from usage, including cache reads.
    3. CThe full unredacted customer message, kept indefinitely.
    4. DOnly requests that returned an error.
    5. EThe monthly invoice total.
    Show answer and reasoning
    1. ACorrect. Without it, cost can't be attributed to either arm of the test.
    2. BCorrect. These give per-request cost and show whether caching or output length changed.
    3. CIncorrect. Not needed for a cost analysis, and a privacy risk without controls.
    4. DIncorrect. Cost comes mostly from successful requests; logging errors alone misses it.
    5. EIncorrect. Too coarse to separate two variants running at the same time.
  4. Question 4

    A support assistant's error rate and latency are stable, but the team suspects answer quality has drifted as customer questions changed. What is the best way to monitor this?

    1. AWait for thumbs-down feedback to rise above a threshold.
    2. BRe-run the original offline eval set every night.
    3. CAdd more latency percentiles to the dashboard.
    4. DSample production transcripts and grade them with calibrated graders.
    Show answer and reasoning
    1. AIncorrect. Feedback is sparse, self-selected and skewed to severe cases; drift can go unnoticed for weeks.
    2. BIncorrect. Useful for regressions, but it can't see the new kinds of question production is receiving.
    3. CIncorrect. Latency says nothing about whether answers are correct.
    4. DCorrect. Grading real traffic measures quality on the current distribution and surfaces new failure types for the eval set.

Sources

Drafted with AI assistance and checked against the sources above; expert review is in progress. Spotted an error? Tell us and it gets fixed, dated and listed on how this is written.