Skip to main content
The Claude Agent SDK is Anthropic’s framework for building AI agents that can reason, use tools, and complete multi-step tasks. It includes built-in support for OpenTelemetry tracing, making it easy to capture detailed telemetry from your agent workflows. This quickstart shows how to send traces from your Claude Agent SDK (Python v0.1.18+, TypeScript v0.1.71+) applications to Scorecard for observability, debugging, and evaluation.
Using the standard Anthropic SDK? Check out the general Tracing Quickstart for the proxy method that works with any Anthropic client.

Steps

1

Set up environment variables

Configure the OpenTelemetry exporter to send traces to Scorecard. You’ll need your Scorecard API key from Settings.
export OTEL_EXPORTER_OTLP_HEADERS="Authorization=Bearer <your_scorecard_api_key>"
export ENABLE_BETA_TRACING_DETAILED=1
export BETA_TRACING_ENDPOINT="https://tracing.scorecard.io/otel"
Replace <your_scorecard_api_key> with your actual Scorecard API key (starts with ak_).
Optional: To send traces to a specific project, set the project ID:
export OTEL_RESOURCE_ATTRIBUTES="scorecard.project_id=<your-project-id>"
If not set, traces will default to your oldest project in the organization.
2

Run your agent

With the environment variables configured, run your Claude Agent SDK application. All agent activity is automatically traced.
example.py
import anyio
from claude_agent_sdk import (
    AssistantMessage,
    TextBlock,
    query,
)

async def main():
    async for message in query(prompt="What is 2 + 2?"):
        if isinstance(message, AssistantMessage):
            for block in message.content:
                if isinstance(block, TextBlock):
                    print(f"Claude: {block.text}")

anyio.run(main)
3

View traces in Scorecard

Navigate to the Records page in Scorecard to see your agent traces.
It may take 1-2 minutes for traces to appear on the Records page.
Click on any record to view the full trace. The conversation view shows a chat-like replay of user messages, assistant responses, and tool calls.The timeline view shows a Gantt chart-style breakdown of every span in the trace, so you can see how LLM calls, tool executions, and other steps overlap and how long each takes.For more complex agents with multiple tool calls and nested spans, the trace gives you full visibility into every step of execution.

What Gets Traced

The Claude Agent SDK automatically captures:
Trace DataDescription
LLM CallsEvery messages.create call with full prompt and completion
Tool UseTool invocations, inputs, and outputs as nested spans
Model UsageInput, output, and total token counts per call
Model InfoModel name, parameters, and configuration
ErrorsAny failures with full error context

Span Reference

The SDK emits four span types, stitched into one record by a shared session.id. Each section below lists every field carried on that span.

claude_code.interaction

User turn boundary. Only emitted on tool-less turns — disappears as soon as the agent uses a tool.
FieldDescription
span.type"interaction".
session.idClaude Code session UUID. Used by Scorecard to group spans into a single record.
terminal.typeTerminal where Claude Code is running (iTerm.app, vscode, intellij, etc.).
duration_msWall-clock span duration in milliseconds.
user.idSHA-256 hash of the Anthropic account UUID.
scorecard.auth_idScorecard organization ID (org_…). Injected from your Scorecard API key by the ingestion pipeline.
user_promptRaw user prompt. May appear as <REDACTED> depending on account tier.
user_prompt_lengthCharacter count of the user prompt.
interaction.sequenceNth user turn in the session.
interaction.duration_msTime from user Enter to assistant reply complete.
new_contextPrompt block formatted as [USER PROMPT]\n<prompt>.

claude_code.llm_request

One per model call. The information-dense span — model, latency, tokens, and the delta added to the conversation for this call.
FieldDescription
span.type"llm_request".
session.idClaude Code session UUID.
terminal.typeTerminal where Claude Code is running.
duration_msTotal latency of the LLM call.
user.idSHA-256 hash of the Anthropic account UUID.
scorecard.auth_idScorecard organization ID.
modelExact model string, e.g. claude-sonnet-4-5-20250929.
attemptRetry number. 1 = first attempt.
ttft_msTime to first streamed token.
speedOutput tokens per second.
successWhether the call returned without error.
input_tokensInput tokens billed (excluding cached).
output_tokensOutput tokens generated.
cache_creation_tokensTokens written to Anthropic’s prompt cache.
cache_read_tokensTokens served from the prompt cache.
new_contextDelta added to the conversation for this call only. Blocks separated by \n---\n, each tagged [USER], [ASSISTANT], or [TOOL RESULT: toolu_XXX].
new_context_message_countBlock count in new_context.
llm_request.contextCall categorization (e.g. "standalone").
query_sourceOrigin: sdk, agent:builtin:Explore, agent:builtin:Bash, agent:builtin:Plan, or internal utilities.
system_prompt_previewFirst ~500 characters of the system prompt.
system_prompt_lengthCharacter length of the full system prompt.
system_prompt_hashShort hash of the system prompt (e.g. sp_742d12203d74).
system_remindersReminder strings injected into context.
system_reminders_countCount of injected reminders.
toolsJSON array of {name, hash} for every exposed tool.
tools_countLength of tools.
response.has_tool_calltrue if the response included tool_use blocks.
response.model_outputAssistant text, concatenated. Tool-use and thinking blocks stripped.

claude_code.tool

One per tool call.
FieldDescription
span.type"tool".
session.idClaude Code session UUID.
terminal.typeTerminal where Claude Code is running.
duration_msTotal tool-call duration.
user.idSHA-256 hash of the Anthropic account UUID.
scorecard.auth_idScorecard organization ID.
tool_nameTool invoked, e.g. Bash, Read, Write, Grep, Skill, mcp__planning__make_plan.
tool_inputFull structured tool input, formatted as [TOOL INPUT: <tool_name>]\n<json> — e.g. {"command": "...", "timeout": 3600000} for Bash.
full_commandBash only — the expanded shell command (duplicates tool_input.command).
file_pathRead / Write only — the file path argument (duplicates tool_input.file_path).
new_contextTool result as fed back to the LLM, formatted as [TOOL RESULT: <tool_name>]\n<json>.

claude_code.hook

One per hook invocation (e.g. UserPromptSubmit, PreToolUse, PostToolUse). Covers both built-in and user-defined hooks.
FieldDescription
span.type"hook".
session.idClaude Code session UUID.
terminal.typeTerminal where Claude Code is running.
duration_msTotal time spent running all hooks for this event.
user.idSHA-256 hash of the Anthropic account UUID.
scorecard.auth_idScorecard organization ID.
hook_eventEvent class — UserPromptSubmit, PreToolUse, PostToolUse, Stop, etc.
hook_nameSpecific hook invoked. For tool hooks, suffixed with the tool name (e.g. PreToolUse:Read, PostToolUse:Skill).
hook_definitionsJSON array describing each registered hook (e.g. [{"type":"callback","name":"callback"}]).
num_hooksTotal hooks that fired for this event.
num_successHooks that completed successfully.
num_blockingHooks whose decision blocked the action.
num_cancelledHooks that were cancelled before completion.
num_non_blocking_errorHooks that errored but did not block.

Resource attributes

Set once per process, attached to every span.
FieldDescription
service.nameAlways "claude-code".
service.versionClaude Code CLI version (e.g. 2.1.87).
host.archCPU architecture (e.g. arm64).
os.typeOperating system family.
os.versionOS version.
scorecard.project_idYour Scorecard project ID. Set via OTEL_RESOURCE_ATTRIBUTES to route traces to a specific project.
scorecard.otel_link_idPer-testcase link ID from runAndEvaluate(). Set via OTEL_RESOURCE_ATTRIBUTES to merge traces into a specific record. See SDK + Tracing.

Environment Variables Reference

VariableRequiredDescription
OTEL_EXPORTER_OTLP_HEADERSYesAuthentication header: Authorization=Bearer <scorecard_api_key>
ENABLE_BETA_TRACING_DETAILEDYesSet to 1 to enable detailed tracing
BETA_TRACING_ENDPOINTYesOTLP endpoint URL (use https://tracing.scorecard.io/otel for Scorecard)
OTEL_RESOURCE_ATTRIBUTESNoSet scorecard.project_id=<id> to target a specific project (defaults to oldest project)

Next Steps

Tracing Features

Learn about advanced tracing patterns and trace grouping

Metrics

Create custom metrics to evaluate agent performance