OpenTelemetry-based instrumentation for the Claude Agent SDK (@anthropic-ai/claude-agent-sdk). Produces AGENT and TOOL spans following OpenInference semantic conventions.
npm install @arizeai/openinference-instrumentation-claude-agent-sdk
import { NodeTracerProvider } from "@opentelemetry/sdk-trace-node";
import { ClaudeAgentSDKInstrumentation } from "@arizeai/openinference-instrumentation-claude-agent-sdk";
const provider = new NodeTracerProvider();
provider.register();
const instrumentation = new ClaudeAgentSDKInstrumentation();
instrumentation.setTracerProvider(provider);
import * as ClaudeAgentSDK from "@anthropic-ai/claude-agent-sdk";
import { ClaudeAgentSDKInstrumentation } from "@arizeai/openinference-instrumentation-claude-agent-sdk";
const instrumentation = new ClaudeAgentSDKInstrumentation({
tracerProvider: provider,
});
instrumentation.manuallyInstrument(ClaudeAgentSDK);
const instrumentation = new ClaudeAgentSDKInstrumentation({
tracerProvider: provider,
traceConfig: {
hideInputs: true,
hideOutputs: true,
},
});
query()The query() function is wrapped to produce:
unstable_v2_prompt(), unstable_v2_createSession(), unstable_v2_resumeSession()unstable_v2_prompt() produces an AGENT span| Attribute | Description |
|---|---|
openinference.span.kind |
"AGENT" |
input.value |
Prompt text |
output.value |
Result text |
session.id |
SDK session identifier |
llm.model_name |
Model used |
llm.token_count.prompt |
Input token count |
llm.token_count.completion |
Output token count |
llm.token_count.total |
Total token count |
llm.cost.total |
Total cost in USD |
| Attribute | Description |
|---|---|
openinference.span.kind |
"TOOL" |
tool.name |
Tool name |
tool.parameters |
Tool input (JSON) |
input.value |
Tool input (JSON) |
output.value |
Tool response (JSON) |