Trace Anthropic’s Claude Agent SDK applications in TypeScript/Node.js
This module provides OpenInference instrumentation for Anthropic’s Claude Agent SDK, automatically capturing AGENT and TOOL spans that follow OpenInference semantic conventions.
To instrument your Claude Agent SDK application, use the register function from @arizeai/phoenix-otel and set up the Claude Agent SDK instrumentation.Create the instrumentation.ts file:
Copy
Ask AI
import { register } from "@arizeai/phoenix-otel";import { ClaudeAgentSDKInstrumentation } from "@arizeai/openinference-instrumentation-claude-agent-sdk";import * as ClaudeAgentSDK from "@anthropic-ai/claude-agent-sdk";// Initialize Phoenix tracingconst tracerProvider = register({ projectName: "claude-agent-sdk-app", // If using Phoenix Cloud: // url: "https://app.phoenix.arize.com/s/your-space-name", // apiKey: process.env.PHOENIX_API_KEY, // If using self-hosted Phoenix: // url: "http://localhost:6006",});// Set up Claude Agent SDK instrumentationconst instrumentation = new ClaudeAgentSDKInstrumentation();instrumentation.manuallyInstrument(ClaudeAgentSDK);console.log("Claude Agent SDK instrumentation registered");
The Claude Agent SDK is ESM-only, so manuallyInstrument() is used instead of enable() to ensure compatibility. You must import the SDK namespace and pass it to manuallyInstrument().
import "./instrumentation.js";import { query } from "@anthropic-ai/claude-agent-sdk";async function main() { for await (const message of query({ prompt: "What is the weather in San Francisco?", options: { model: "claude-sonnet-4-5-20250514", }, })) { if (message.type === "assistant") { console.log(message.content); } }}main();