Claude Agent SDK
This page explains how to instrument a Claude Agent SDK
Topics
Instrument your agent
You can instrument a Claude Agent SDK agent with the OpenInference instrumentation library (openinference-instrumentation-claude-agent-sdk). This library emits telemetry under the scope name openinference.instrumentation.claude_agent_sdk, which Amazon Bedrock AgentCore Evaluations reads.
When your agent runs with the AWS Distro for OpenTelemetry (ADOT), such as on Amazon Bedrock AgentCore Runtime, you do not need to add explicit instrumentation code. Adding the instrumentation library to your project’s dependencies is enough. ADOT discovers it at startup and activates it automatically.
Add the instrumentation library to your dependencies.
Note
Use version 0.1.3 or later. This is the earliest version tested with the evaluation service.
requirements.txt:
openinference-instrumentation-claude-agent-sdk>=0.1.3
pyproject.toml:
[project] dependencies = [ "openinference-instrumentation-claude-agent-sdk>=0.1.3", ]
Note
Instrumentation is one step in setting up observability. To export telemetry for evaluation, complete the full setup in Set up observability.
How spans are identified
Claude Agent SDK is instrumented with the OpenInference convention, so AgentCore Evaluations classifies spans using the openinference.span.kind attribute.
| Span type | Identifying attribute |
|---|---|
|
Invoke agent |
|
|
Execute tool |
|
The Claude Agent SDK emits only AGENT and TOOL spans; it does not emit separate inference (LLM) spans. The model metadata (model name, token usage) and the agent response are carried on the AGENT span itself.
How evaluation fields are extracted
The Claude Agent SDK produces clean, plain-text agent input and output, so the user prompt and agent response require no special parsing. Tool results, however, arrive as Anthropic content blocks in the form [{"type": "text", "text": "…"}]. AgentCore Evaluations unwraps these blocks and concatenates their text.
The location of this content depends on how telemetry was collected. The identifying attribute (openinference.span.kind) is on the span in both cases. For more information, see Spans, event records, and telemetry signals.
From event records
When telemetry is split, AgentCore Evaluations reads content from the event record correlated to each span:
-
User prompt and agent response: from the invoke agent span’s event record, in
body.inputandbody.output. -
Tool call: the tool name from the
tool.nameattribute and the tool call ID fromtool.idon the execute tool span. The tool arguments and result come from that span’s event record, inbody.inputandbody.output. AgentCore Evaluations unwraps the Anthropic content blocks in the tool result.
For examples, see Example spans with event records.
From span attributes
When telemetry is not split, the same content stays on the span as attributes:
-
User prompt and agent response: from
input.valueandoutput.valueon the invoke agent span. -
Tool call: the tool name from
tool.name, the tool call ID fromtool.id, the arguments frominput.value, and the result fromoutput.value, on the execute tool span. AgentCore Evaluations unwraps the Anthropic content blocks in the tool result.
For examples, see Example spans without event records.
Example spans with event records
When telemetry is split, the span carries the identifying attributes and the content lives in a correlated event record. The following examples are from a Claude Agent SDK travel-planning agent deployed on Amazon Bedrock AgentCore Runtime.
Note
These examples are not complete spans. They show representative data from a real agent interaction, with some fields omitted and long values truncated for readability.
Example
Example spans without event records
When telemetry is not split, the same content stays on the span attributes and no separate event record is produced. The following examples are from a Claude Agent SDK travel-planning agent.
Note
These examples are not complete spans. They show representative data from a real agent interaction, with some fields omitted and long values truncated for readability.