JavaScript · Instrumentation
@arizeai/openinference-instrumentation-claude-agent-sdk
OpenInference instrumentation for Claude Agent SDK
- Version
- 0.3.9
- Instruments
@anthropic-ai/claude-agent-sdk >=0.2.0
Install
npm install @arizeai/openinference-instrumentation-claude-agent-sdkUsage
Register the instrumentation once, at startup, before the library is imported. The ClaudeAgentSDKInstrumentation reference below lists its options.
import { registerInstrumentations } from "@opentelemetry/instrumentation";
import { NodeTracerProvider } from "@opentelemetry/sdk-trace-node";
import { ClaudeAgentSDKInstrumentation } from "@arizeai/openinference-instrumentation-claude-agent-sdk";
const provider = new NodeTracerProvider({
// ...a span processor that exports to Phoenix or any OTLP backend.
});
provider.register();
registerInstrumentations({
instrumentations: [new ClaudeAgentSDKInstrumentation()],
});If the library is imported first (as ES modules often are), patch it directly with manuallyInstrument().
@arizeai/openinference-instrumentation-claude-agent-sdk
isPatched
functionSource ↗function isPatched(): booleanCheck if instrumentation is enabled / disabled.
ClaudeAgentSDKInstrumentation
classSource ↗class ClaudeAgentSDKInstrumentation extends InstrumentationBase<ClaudeAgentSDKModule>OpenInference instrumentation for the Claude Agent SDK.
Produces AGENT spans for query()/prompt() invocations and TOOL spans for each tool call via hook injection.
Examples
import { ClaudeAgentSDKInstrumentation } from "@arizeai/openinference-instrumentation-claude-agent-sdk";
const instrumentation = new ClaudeAgentSDKInstrumentation();
instrumentation.setTracerProvider(provider);new ClaudeAgentSDKInstrumentation
constructorSource ↗new ClaudeAgentSDKInstrumentation(
options?: {
instrumentationConfig?: InstrumentationConfig;
traceConfig?: TraceConfigOptions;
tracerProvider?: TracerProvider;
},
): ClaudeAgentSDKInstrumentationmanuallyInstrument
methodSource ↗manuallyInstrument<TModule extends ClaudeAgentSDKModule>(
module: TModule,
): TModuleManually instruments the Claude Agent SDK module. Returns a patched copy when the supplied module is a native ESM namespace.
setTracerProvider
methodSource ↗setTracerProvider(tracerProvider: TracerProvider): voidSets TraceProvider to this plugin