JavaScript · Instrumentation
@arizeai/openinference-instrumentation-anthropic
OpenInference instrumentation for Anthropic
- Version
- 1.0.4
- Instruments
@anthropic-ai/sdk
Install
npm install @arizeai/openinference-instrumentation-anthropicUsage
Register the instrumentation once, at startup, before the library is imported. The AnthropicInstrumentation reference below lists its options.
import { registerInstrumentations } from "@opentelemetry/instrumentation";
import { NodeTracerProvider } from "@opentelemetry/sdk-trace-node";
import { AnthropicInstrumentation } from "@arizeai/openinference-instrumentation-anthropic";
const provider = new NodeTracerProvider({
// ...a span processor that exports to Phoenix or any OTLP backend.
});
provider.register();
registerInstrumentations({
instrumentations: [new AnthropicInstrumentation()],
});If the library is imported first (as ES modules often are), patch it directly with manuallyInstrument().
@arizeai/openinference-instrumentation-anthropic
isPatched
functionSource ↗function isPatched(): booleanfunction to check if instrumentation is enabled / disabled
AnthropicInstrumentation
classSource ↗class AnthropicInstrumentation extends InstrumentationBase<typeof Anthropic>An auto instrumentation class for Anthropic that creates OpenInference Compliant spans for the Anthropic API
new AnthropicInstrumentation
constructorSource ↗new AnthropicInstrumentation(
options?: {
instrumentationConfig?: InstrumentationConfig;
traceConfig?: TraceConfigOptions;
tracerProvider?: TracerProvider;
},
): AnthropicInstrumentationParameters
| Name | Type | Description |
|---|---|---|
instrumentationConfig? | InstrumentationConfig | The config for the instrumentation |
traceConfig? | TraceConfigOptions | The OpenInference trace configuration. Can be used to mask or redact sensitive information on spans. |
tracerProvider? | TracerProvider | An optional custom trace provider to be used for tracing. If not provided, a tracer will be created using the global tracer provider. This is useful if you want to use a non-global tracer provider. |
manuallyInstrument
methodSource ↗manuallyInstrument(module: typeof Anthropic): voidManually instruments the Anthropic module. This is needed when the module is not loaded via require (commonjs)
disable
methodSource ↗disable(): voidsetTracerProvider
methodSource ↗setTracerProvider(tracerProvider: TracerProvider): voidSets TraceProvider to this plugin