Claude Certification Program · Five exams · Guides updated December 7, 2026

Home › Study guides › CCDV-P › Domain 3 › Lesson 3.1

CCDV-P · Domain 3 · 12% of the exam · Lesson 3.1 · 22 min read New in the December 7, 2026 guide release (v1.0)

Telemetry and instrumentation for Claude agents

Make any Claude agent answer explainable: per-step spans, usage and cache metrics, citation traces, structured events, and content capture under ZDR.

Written against skill 3.1 of the official CCDV-P exam guide (Version 1.0, effective November 2026). An independent resource, not affiliated with Anthropic; the practice questions are written from scratch.

3.1.1 Why nobody could explain the wrong covenant

Pellham Bank's commercial loans come with credit agreements full of financial covenants: promises such as keeping debt below 3.5 times annual earnings. When a borrower's quarterly figures breach one, a relationship manager must answer formally within days. Since spring an agent drafts those answers. It reads the breach alert, calls get_facility, search_agreement and get_financials, and writes a draft that cites the clause in question. It handles about 1,400 covenant cases a month, and a manager reviews every draft before it goes out.

In October a manager caught a draft telling Harrow Freight it had breached its leverage covenant at 3.50x. Harrow's second amendment had raised that limit to 4.00x months earlier, so Harrow was compliant. The draft quoted Section 7.2(a) accurately and confidently. The engineers opened their logs and found one line per run: case id, "draft generated", 41 seconds, HTTP 200. Nothing said which documents the search returned, which passage the model cited, or how many steps the run took.

Their next idea was to ask Anthropic for the transcript. Pellham's API organization has zero data retention (ZDR; Anthropic's docs now call this arrangement Legacy ZDR), under which Anthropic does not store prompts or responses at rest after the API response is returned. There is no transcript to ask for. The only record of what the agent saw and said is the one Pellham chose to keep.

Instrumentation is the code and configuration that make a running system emit a record of what it did: traces of each step, metrics for tokens and cost, structured events and, where policy allows, content. For a bank's agent, that record must explain an answer after the fact without creating a new store of confidential data.

3.1.2 A span for every model call and tool call

What would the engineers have needed to see? Which tool the model asked for, what came back, which call produced the citation, and why each call stopped. A distributed trace records exactly that. A trace is the record of one unit of work; a span is one timed step inside it, with attributes, a status and a parent. For an agent, the natural trace is one run of the loop, from the breach alert to the final draft.

One covenant case as a trace

Root span one run

invoke_agentcase c-81f3
41 s, status OK, 6 model calls

Model-call spans

chatmodel, stop_reason
usageinput, output, cache read, cache write
request idthe handle support asks for

Tool spans

execute_tool search_agreementdoc ids, versions
execute_tool get_financials210 ms, OK
error.typeonly when a tool fails
The root span covers the whole run, and each model call and tool call beneath it is its own span, so a wrong draft can be traced to the step that caused it.

Don't invent attribute names. The OpenTelemetry GenAI semantic conventions are the shared vocabulary that OpenTelemetry, the vendor-neutral standard for traces, metrics and logs, defines for generative AI. The attribute gen_ai.operation.name says what a span is: chat, execute_tool or invoke_agent. The model goes in gen_ai.request.model and gen_ai.response.model, the tokens in the gen_ai.usage.* family, the tool in gen_ai.tool.name and gen_ai.tool.call.id, and the failure class in error.type. Backends that know the conventions draw agent traces without custom parsing. They are still in development, so pin the versions you build on.

You needn't write the model-call spans yourself. The Anthropic SDK's OpenTelemetry tracing, in beta, gives every messages.create call an anthropic.messages.create span with the model, usage and error.type attributes, plus anthropic.message.stop_reason and anthropic.request.id, once you register a tracer provider. Your code adds what only it knows: the root span for the run and a span around each tool it executes. In the loop below, look at the root span and the two gen_ai.tool.* lines.

from opentelemetry import trace
import anthropic

tracer = trace.get_tracer("pellham.covenant-agent")
client = anthropic.Anthropic()  # with a tracer provider registered, the SDK adds a span per model call

def run_case(case_id, messages):
    with tracer.start_as_current_span("invoke_agent covenant_drafter") as run:
        run.set_attribute("gen_ai.operation.name", "invoke_agent")
        run.set_attribute("app.case_id", case_id)  # an opaque id: no borrower name on spans
        for _ in range(MAX_STEPS):
            reply = client.messages.create(model=MODEL, max_tokens=4096, system=SYSTEM,
                                           tools=TOOLS, messages=messages)
            if reply.stop_reason != "tool_use":
                return reply
            messages.append({"role": "assistant", "content": reply.content})
            results = []
            for block in (b for b in reply.content if b.type == "tool_use"):
                with tracer.start_as_current_span(f"execute_tool {block.name}") as span:
                    span.set_attribute("gen_ai.tool.name", block.name)   # bounded: four tools
                    span.set_attribute("gen_ai.tool.call.id", block.id)  # joins to the tool_use block
                    results.append(run_tool(block, span))  # records doc ids; sets error.type on failure
            messages.append({"role": "user", "content": results})
        raise RuntimeError("step limit reached")  # an exception marks the root span as an error

Each attribute answers one question an operator will ask.

Attribute Where it comes from The question it answers
gen_ai.response.model The response Which model answered? It can differ from the one requested when you use an alias or a fallback served the call
anthropic.message.stop_reason The response Did the call end on tool_use, end_turn, max_tokens or refusal?
gen_ai.usage.* The usage block What did this step cost, and did the cache hit?
Duration and status The span itself Which step was slow, and which failed?
gen_ai.tool.name, error.type Your loop Which tool ran, and how did it fail?
anthropic.request.id The request-id header Which exact call should Anthropic support look at?

Record opaque ids, never borrower names, and keep any attribute you will group by to a small, fixed set of values.

3.1.3 Tokens, cost and cache performance from the usage block

Every response carries a usage block, the raw material for cost and cache metrics. What does input_tokens count? Not the whole prompt. With prompt caching, the API splits input three ways: cache_read_input_tokens (read from the cache), cache_creation_input_tokens (written to it on this call) and input_tokens (everything after the last cache breakpoint). Total input is the sum of all three. A dashboard that charts input_tokens alone makes Pellham's 18,000-token cached prefix vanish.

Anthropic's OpenTelemetry spans count differently: their gen_ai.usage.input_tokens already includes cache reads and writes, so adding the cache attributes to it double-counts them. Know which source a number came from before you add it to anything.

Cost follows from the split, because each kind is priced differently. Cache reads cost a fraction of the base input price (0.1x by default, less on some newer models). Five-minute cache writes cost 1.25x and one-hour writes 2x. Output, which includes thinking tokens, is billed at the output price. Pellham computes cost per case by summing its model-call spans, labelled by model and prompt version, never by borrower.

Cache performance needs a metric of its own. A practical one is the read share: cache_read_input_tokens divided by total input. Once instrumented, Pellham saw its read share had fallen from 85% to 4% after a September release, and input spend per case had more than tripled. The usage fields tell you which of four situations you are in.

What usage shows What it usually means What to do
Reads high, writes near zero after the first call The cache is working Nothing
Reads zero, writes high on every call Something in the prefix changes between calls Find the change, with cache diagnostics
Reads and writes both zero Nothing was cached: no breakpoint, or the prompt is below the minimum cacheable length Check cache_control and the prompt length
Reads drop after quiet periods Entries expired (the default lifetime is five minutes) Consider the one-hour lifetime if gaps are normal

To find the change, use cache diagnostics. Include a diagnostics object on every request, with the previous response's id as previous_message_id (or null on the first turn). The response's diagnostics object then carries a cache_miss_reason whose type, such as system_changed, tools_changed, messages_changed or model_changed, names the first point where the two requests diverged, with an estimate of the input tokens lost after it. Pellham's said system_changed: the release had put the alert's received-at timestamp into the system prompt. Moving it into the user message restored the read share. Cache diagnostics is ZDR-eligible in a qualified form: Anthropic keeps only a short-lived fingerprint of hashes and token-count estimates, never the prompt.

3.1.4 Grounding and reasoning traceability

A token count cannot say why Harrow's draft cited a superseded clause. That takes grounding traceability: a record that links each claim in the answer to its source, and the source to the retrieval that supplied it. A wrong citation has three possible causes, each with a different fix: retrieval returned the wrong documents, the model picked the wrong passage, or the passage came from an outdated document.

The Citations feature supplies the second half of the chain. With citations enabled on your document blocks, the response's text blocks carry a citations list. Each entry has a type (char_location, page_location or content_block_location), a document_index into the documents of the request, and a location range. The API extracts the cited text itself, so citations are guaranteed to point at valid locations in the documents you supplied. Notice what that guarantee covers: the pointer is valid, not the document.

Your code supplies the first half. On the search_agreement span, record the ids and versions of the documents returned. When you build the request, record which of your document ids sits at each document_index. A citation then resolves to "CA-2021-HF version 1, Section 7.2(a)" without one sentence of the agreement being copied into telemetry.

The grounding chain, recorded as ids

RETRIEVEdoc ids and versions on the tool span
SUPPLYwhich doc id sits at each document_index
CITEthe citation's index and location
RESOLVEcited clause, document version
Each link is recorded as an id on a span, so any citation can be followed back to the document version and the retrieval call that supplied it.

Instrumented, Harrow's trace told the story in a minute. search_agreement filtered by facility id, and the second amendment was filed under the parent company's id, so it was never returned. The model accurately cited the only leverage clause it had. The fix belonged to retrieval; no model change would have found it.

Reasoning traceability is the second strand. With thinking on, responses carry thinking blocks. On Claude 5 models the display setting defaults to "omitted", which returns those blocks empty; display: "summarized" returns a summary of the reasoning instead. It is written by a different model, it is never the raw chain of thought, and you are billed for the full thinking tokens either way. Treat it as a hint about which evidence the model weighed, not as proof. Don't ask the model to explain its reasoning in the answer text instead: some models refuse that request. Pellham records the thinking token count on every span and keeps summaries only on the runs whose content it captures.

3.1.5 Structured events and Claude Code's telemetry

Some facts fit better as events than spans: a draft approved, a manager's edit, a case flagged for legal review. The old habit is a free-text line, which reads well and works badly: counting edits per clause needs a regular expression, the borrower's name lands in the log store, and nothing ties the line to its trace. A structured log event is a named record with typed fields: an event name, a timestamp, the trace and span ids, and bounded attributes. You can query it like a table and join it to its trace.

The same fact, logged two ways

Free-text line

"Drafted response for Harrow Freight, 7.2(a), 41s"
Parsed with a regular expression
Customer name in the log store

Structured event

event.name: draft.completed
trace_id, case_id, clause_id
duration_ms: 41000, edited: false
A structured event can be counted, filtered and joined to its trace without parsing text or copying customer names into the log store.

Claude Code is a worked example worth copying. Set CLAUDE_CODE_ENABLE_TELEMETRY=1, choose exporters, and it emits all three OpenTelemetry signals. Metrics include claude_code.token.usage, whose type is input, output, cacheRead or cacheCreation, and claude_code.cost.usage. Events include claude_code.api_request (model, cost_usd, duration, token and cache counts, request_id) and claude_code.tool_result (tool name, success, duration), all linked by a prompt.id per prompt.

Traces, in beta, nest claude_code.llm_request and claude_code.tool spans under one claude_code.interaction span. The Agent SDK runs the same CLI, so it emits the same data. Here is a configuration with traces on and every content switch left off:

export CLAUDE_CODE_ENABLE_TELEMETRY=1
export OTEL_METRICS_EXPORTER=otlp               # token and cost counters
export OTEL_LOGS_EXPORTER=otlp                  # structured events
export OTEL_EXPORTER_OTLP_PROTOCOL=grpc
export OTEL_EXPORTER_OTLP_ENDPOINT=http://otel-collector:4317
export CLAUDE_CODE_ENHANCED_TELEMETRY_BETA=1    # traces are in beta
export OTEL_TRACES_EXPORTER=otlp
# Left unset on purpose: OTEL_LOG_USER_PROMPTS, OTEL_LOG_ASSISTANT_RESPONSES,
# OTEL_LOG_TOOL_DETAILS, OTEL_LOG_TOOL_CONTENT, OTEL_LOG_RAW_API_BODIES

Prompt text, responses, tool inputs such as file paths and commands, and tool output stay out of the export until you opt in, one variable at a time. Structure is on by default; content is a decision.

3.1.6 Content capture: off, redacted, sampled

Content is where debuggability and privacy collide. Spans holding the prompt, clauses and draft would have explained Harrow in seconds, and copied every borrower's confidential terms to an observability vendor. Content capture has four sensible positions.

Mode When it wins What it costs
Off (metadata only) The default: ids, timing, tokens and stop reasons on every span Hard cases need a lookup in the systems of record
Redacted Content is needed, but some fields must never leave (names, account numbers) Redaction rules to maintain, applied before export
Sampled Content is needed for a few runs: failures, flagged cases, review samples A keep rule; most runs carry no content
Full Low-risk data, or a short approved debugging window A second copy of everything, under your retention duty

Anthropic's tracing names the two ends: metadata_only, the default, and content, set per destination in the Console or per SDK client with traces.content_mode. Claude Code's OTEL_LOG_* variables are finer switches on the same axis. Redaction and sampling you build yourself, usually in the collector.

Now, what does ZDR change? It is a commitment about Anthropic's storage: no prompts or responses kept at rest after the response is returned, apart from content flagged by its safety systems or held for legal reasons. It says nothing about your logs, your traces or your vendor. Anthropic's tracing docs draw the boundary plainly: with ZDR you can still export full content, the API holds it only in memory until delivery, and from then on it sits with the service you chose, under that service's retention and access rules.

The newer EFS ZDR (Enterprise Frontier Safeguards, in beta) does not change this. Anthropic keeps no prompts or responses, and the Sealed Safety Data written to the customer's own bucket is encrypted so that even the customer's team cannot read it: it is no debugging record. Under either form, ZDR does not make an exporter compliant, and switching on content capture can quietly undo the reason the bank wanted ZDR.

Who keeps what under ZDR

Anthropic side ZDR applies

Prompts and responsesnot stored after the response
Exported spansheld in memory until delivered

Your side your policy applies

Collector, vendor, log indexyour retention, your access
Claude Code exportsyour retention

A run's record exists only where you keep it

ZDR governs Anthropic's side only, so every copy your telemetry makes falls under your own retention and access policy.

Pellham's choice: metadata on every span, including document ids, versions and citation locations, because ids let an authorised reviewer pull the text from the document system the bank already governs. Content is captured only for sampled and flagged runs, redacted at the collector, and stored inside the bank with named readers and 30-day retention. Every draft is now explainable, and the vendor holds no covenant text.

3.1.7 The exam traps

Each trap records too little to explain an answer or copies too much to defend.

  • ✗ "We have ZDR, so Anthropic can show us the transcript", or "so we can't log anything." ✓ ZDR means Anthropic keeps no transcript, so the only record is the one you design, within your own policy.
  • ✗ Writing every prompt and response to the shared log index "so we can debug anything". ✓ Put metadata and ids on every span, and keep redacted or sampled content in a restricted store. Full logs are a second copy of every conversation.
  • ✗ Treating input_tokens as total input. ✓ Add cache reads and cache writes from the usage block, but don't add them again to gen_ai.usage.input_tokens, which already includes them.
  • ✗ Adding a one-hour cache or a different model when the cache read share collapses. ✓ Run cache diagnostics and fix the change it names, such as a timestamp in the system prompt.
  • ✗ Asking the model to explain its sources in the answer text. ✓ Record retrieved document ids and versions and resolve each citation to them; use thinking summaries as hints only.
  • ✗ Free-text log lines that name the customer. ✓ Structured events with bounded fields and the trace id, so they can be counted and joined without exposing anyone.

3.1.8 Put it together: make one run explainable

To own these pieces, instrument a tiny covenant agent, break it twice, and watch the telemetry point at each fault.

These spans and events feed the rest of the domain. Production monitoring (3.2) turns the usage and stop-reason metrics into SLIs, SLOs and alerts. Trace analysis at scale (3.3) studies thousands of these traces at once, through sampling, aggregation and failure cohorts.

Key takeaways

  • ✓ Under ZDR Anthropic keeps no prompts or responses after the response, so the only record of a run is the telemetry you design.
  • ✓ Trace each run with a span per model call and tool call, using the OpenTelemetry GenAI names for model, stop reason, tokens, tool and error class.
  • ✓ Total input is input_tokens plus cache reads and writes, while gen_ai.usage.input_tokens already includes the cache, so know your source before you sum.
  • ✓ Watch the cache read share, and when it collapses let cache diagnostics name the part of the request that changed.
  • ✓ Record retrieved document ids and versions and resolve each citation to them; citations guarantee valid pointers, not correct sources.
  • ✓ Log facts as structured events with bounded fields and the trace id, as Claude Code's telemetry does.
  • ✓ Keep content capture off by default and add redacted or sampled content only in a store you govern.

Check your understanding

4 questions written for this lesson. Every answer option is explained, including the ones you did not pick. Nothing is stored.

CCDV-P practice questions are being written

There is no CCDV-P question bank on this site yet. The practice questions are being written now. Until they are ready, work through the free study guide: every lesson ends with questions that check your understanding, and every answer option is explained.

Back to Domain 3 → The CCDV-P exam guide →

The CCDV-P course will hold the same study guide as a book, for reading in the app.

Sources