# @arizeai/openinference-instrumentation-anthropic

**JavaScript · Instrumentation**

OpenInference instrumentation for Anthropic

- **Version**: 1.0.4
- **Instruments**: `@anthropic-ai/sdk`

[npm](https://www.npmjs.com/package/@arizeai/openinference-instrumentation-anthropic) · [README](https://github.com/Arize-ai/openinference/blob/main/js/packages/openinference-instrumentation-anthropic/README.md) · [Source](https://github.com/Arize-ai/openinference/tree/main/js/packages/openinference-instrumentation-anthropic)

## Install

```sh
npm install @arizeai/openinference-instrumentation-anthropic
```

## Usage

Register the instrumentation once, at startup, before the library is imported. The [`AnthropicInstrumentation`](https://openinf.dev/js/openinference-instrumentation-anthropic.html.md#AnthropicInstrumentation) reference below lists its options.

```ts
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()`](https://openinf.dev/js/openinference-instrumentation-anthropic.html.md#AnthropicInstrumentation.manuallyInstrument).

## `@arizeai/openinference-instrumentation-anthropic`

### `isPatched`

_function_ · [Source](https://github.com/Arize-ai/openinference/blob/main/js/packages/openinference-instrumentation-anthropic/src/instrumentation.ts#L155)

```typescript
function isPatched(): boolean
```

function to check if instrumentation is enabled / disabled

### `AnthropicInstrumentation`

_class_ · [Source](https://github.com/Arize-ai/openinference/blob/main/js/packages/openinference-instrumentation-anthropic/src/instrumentation.ts#L180)

```typescript
class AnthropicInstrumentation extends InstrumentationBase<typeof Anthropic>
```

An auto instrumentation class for Anthropic that creates [OpenInference](https://github.com/Arize-ai/openinference/blob/main/spec/attributes/semantic-conventions.md) Compliant spans for the Anthropic API

> **See also**
>
> - `InstrumentationConfig`
> - [`TraceConfigOptions`](https://openinf.dev/js/openinference-core.html.md#TraceConfigOptions)

**Properties**

| Name | Type |
| - | - |
| [`tracer`](https://openinf.dev/js/openinference-instrumentation-anthropic.html.md#AnthropicInstrumentation.tracer) | `Tracer` |

#### `new AnthropicInstrumentation`

_constructor_ · [Source](https://github.com/Arize-ai/openinference/blob/main/js/packages/openinference-instrumentation-anthropic/src/instrumentation.ts#L191)

```typescript
new AnthropicInstrumentation(
  options?: {
    instrumentationConfig?: InstrumentationConfig;
    traceConfig?: TraceConfigOptions;
    tracerProvider?: TracerProvider;
  },
): AnthropicInstrumentation
```

**Parameters**

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

_method_ · [Source](https://github.com/Arize-ai/openinference/blob/main/js/packages/openinference-instrumentation-anthropic/src/instrumentation.ts#L238)

```typescript
manuallyInstrument(module: typeof Anthropic): void
```

Manually instruments the Anthropic module. This is needed when the module is not loaded via require (commonjs)

#### `disable`

_method_ · [Source](https://github.com/Arize-ai/openinference/blob/main/js/packages/openinference-instrumentation-anthropic/src/instrumentation.ts#L243)

```typescript
disable(): void
```

#### `setTracerProvider`

_method_ · [Source](https://github.com/Arize-ai/openinference/blob/main/js/packages/openinference-instrumentation-anthropic/src/instrumentation.ts#L257)

```typescript
setTracerProvider(tracerProvider: TracerProvider): void
```

Sets TraceProvider to this plugin
