Anthropic

Adds instrumentation for the Anthropic SDK.

Import name: Sentry.anthropicAIIntegration

The anthropicAIIntegration adds instrumentation for the @anthropic-ai/sdk API to capture spans by wrapping Anthropic SDK calls and recording LLM interactions.

To customize what data is captured (such as inputs and outputs), see the Options in the Configuration section.

The following options control what data is captured from Anthropic SDK calls:

Type: boolean (optional)

Records inputs to Anthropic SDK calls (such as prompts and messages).

Defaults to true if sendDefaultPii is true.

Type: boolean (optional)

Records outputs from Anthropic SDK calls (such as generated text and responses).

Defaults to true if sendDefaultPii is true.

Usage

Using the anthropicAIIntegration integration:

Copied
Sentry.init({
  dsn: "____PUBLIC_DSN____",
  // Tracing must be enabled for agent monitoring to work
  tracesSampleRate: 1.0,
  integrations: [
    Sentry.anthropicAIIntegration({
      // your options here
    }),
  ],
});

By default, tracing support is added to the following Anthropic SDK calls:

  • messages.create() - Create messages with Claude models
  • messages.stream() - Stream messages with Claude models
  • messages.countTokens() - Count tokens for messages
  • models.get() - Get model information
  • completions.create() - Create completions (legacy)
  • models.retrieve() - Retrieve model details
  • beta.messages.create() - Beta messages API

Streaming and non-streaming requests are automatically detected and handled appropriately.

  • @anthropic-ai/sdk: >=0.19.2 <1.0.0
Was this helpful?
Help improve this content
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) or suggesting an update ("yeah, this would be better").