JavaScript APIclaude-agent-sdk

Core

Instrumentation

Integrations

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-sdk

Usage

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(): boolean

Check 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);

Properties

NameType
tracerTracer

new ClaudeAgentSDKInstrumentation

constructorSource ↗
new ClaudeAgentSDKInstrumentation(
  options?: {
    instrumentationConfig?: InstrumentationConfig;
    traceConfig?: TraceConfigOptions;
    tracerProvider?: TracerProvider;
  },
): ClaudeAgentSDKInstrumentation

manuallyInstrument

methodSource ↗
manuallyInstrument<TModule extends ClaudeAgentSDKModule>(
  module: TModule,
): TModule

Manually instruments the Claude Agent SDK module. Returns a patched copy when the supplied module is a native ESM namespace.

setTracerProvider

methodSource ↗
setTracerProvider(tracerProvider: TracerProvider): void

Sets TraceProvider to this plugin