Skip to content

Commit 7a65d77

Browse files
feat: Document Anthropic AI Integration (#14847)
<!-- Use this checklist to make sure your PR is ready for merge. You may delete any sections you don't need. --> ## DESCRIBE YOUR PR Document Anthropic AI integration ## IS YOUR CHANGE URGENT? Help us prioritize incoming PRs by letting us know when the change needs to go live. - [ ] Urgent deadline (GA date, etc.): <!-- ENTER DATE HERE --> - [ ] Other deadline: <!-- ENTER DATE HERE --> - [x] None: Not urgent, can wait up to 1 week+ ## SLA - Teamwork makes the dream work, so please add a reviewer to your PRs. - Please give the docs team up to 1 week to review your PR unless you've added an urgent due date to it. Thanks in advance for your help! ## PRE-MERGE CHECKLIST *Make sure you've checked the following before merging your changes:* - [ ] Checked Vercel preview for correctness, including links - [ ] PR was reviewed and approved by any necessary SMEs (subject matter experts) - [ ] PR was reviewed and approved by a member of the [Sentry docs team](https://github.com/orgs/getsentry/teams/docs) ## LEGAL BOILERPLATE <!-- Sentry employees and contractors can delete or ignore this section. --> Look, I get it. The entity doing business as "Sentry" was incorporated in the State of Delaware in 2015 as Functional Software, Inc. and is gonna need some rights from me in order to utilize my contributions in this here PR. So here's the deal: I retain all rights, title and interest in and to my contributions, and by keeping this boilerplate intact I confirm that Sentry can use, modify, copy, and redistribute my contributions, under Sentry's choice of terms. ## EXTRA RESOURCES - [Sentry Docs contributor guide](https://docs.sentry.io/contributing/) --------- Co-authored-by: Simon Hellmayr <[email protected]>
1 parent 977f4bb commit 7a65d77

16 files changed

+173
-6
lines changed
Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
---
2+
title: Anthropic
3+
description: "Adds instrumentation for Anthropic API."
4+
supported:
5+
- javascript.node
6+
- javascript.aws-lambda
7+
- javascript.azure-functions
8+
- javascript.connect
9+
- javascript.express
10+
- javascript.fastify
11+
- javascript.gcp-functions
12+
- javascript.hapi
13+
- javascript.hono
14+
- javascript.koa
15+
- javascript.nestjs
16+
- javascript.electron
17+
- javascript.nextjs
18+
- javascript.nuxt
19+
- javascript.solidstart
20+
- javascript.sveltekit
21+
- javascript.react-router
22+
- javascript.remix
23+
- javascript.astro
24+
- javascript.bun
25+
- javascript.tanstackstart-react
26+
- javascript.cloudflare
27+
---
28+
29+
<Alert>
30+
31+
This integration works in the Node.js, Cloudflare Workers, and Vercel Edge Functions runtimes. It requires SDK version `10.12.0` or higher.
32+
33+
</Alert>
34+
35+
_Import name: `Sentry.anthropicAIIntegration`_
36+
37+
The `anthropicAIIntegration` adds instrumentation for the `@anthropic-ai/sdk` to capture spans by automatically wrapping Anthropic client calls and recording LLM interactions with configurable input/output recording.
38+
39+
<PlatformSection notSupported={["javascript.cloudflare", "javascript.nextjs"]}>
40+
It is enabled by default and will automatically capture spans for Anthropic API method calls. You can opt-in to capture inputs and outputs by setting `recordInputs` and `recordOutputs` in the integration config:
41+
42+
```javascript
43+
Sentry.init({
44+
dsn: "____PUBLIC_DSN____",
45+
tracesSampleRate: 1.0,
46+
integrations: [
47+
Sentry.anthropicAIIntegration({
48+
recordInputs: true,
49+
recordOutputs: true,
50+
}),
51+
],
52+
});
53+
```
54+
55+
</PlatformSection>
56+
57+
<PlatformSection supported={["javascript.cloudflare"]}>
58+
For Cloudflare Workers, you need to manually instrument the Anthropic client using the `instrumentAnthropicClient` helper:
59+
60+
```javascript
61+
import * as Sentry from "@sentry/cloudflare";
62+
import Anthropic from "@anthropic-ai/sdk";
63+
64+
const anthropic = new Anthropic();
65+
const client = Sentry.instrumentAnthropicClient(anthropic, {
66+
recordInputs: true,
67+
recordOutputs: true,
68+
});
69+
70+
// Use the wrapped client instead of the original anthropic instance
71+
const response = await client.messages.create({
72+
model: "claude-3-5-sonnet-20241022",
73+
max_tokens: 1024,
74+
messages: [{ role: "user", content: "Hello!" }],
75+
});
76+
```
77+
78+
</PlatformSection>
79+
80+
<PlatformSection supported={['javascript.nextjs']}>
81+
82+
This integration is automatically instrumented in the Node.js runtime. For Next.js applications using the Edge runtime, you need to manually instrument the Anthropic client:
83+
84+
```javascript
85+
import * as Sentry from "@sentry/nextjs";
86+
import Anthropic from "@anthropic-ai/sdk";
87+
88+
const anthropic = new Anthropic();
89+
const client = Sentry.instrumentAnthropicClient(anthropic, {
90+
recordInputs: true,
91+
recordOutputs: true,
92+
});
93+
94+
// Use the wrapped client instead of the original anthropic instance
95+
const response = await client.messages.create({
96+
model: "claude-3-5-sonnet-20241022",
97+
max_tokens: 1024,
98+
messages: [{ role: "user", content: "Hello!" }],
99+
});
100+
```
101+
102+
</PlatformSection>
103+
104+
## Options
105+
106+
### `recordInputs`
107+
108+
_Type: `boolean`_
109+
110+
Records inputs to Anthropic API method calls (such as prompts and messages).
111+
112+
Defaults to `true` if `sendDefaultPii` is `true`.
113+
114+
```javascript
115+
Sentry.init({
116+
integrations: [Sentry.anthropicAIIntegration({ recordInputs: true })],
117+
});
118+
```
119+
120+
### `recordOutputs`
121+
122+
_Type: `boolean`_
123+
124+
Records outputs from Anthropic API method calls (such as generated text and responses).
125+
126+
Defaults to `true` if `sendDefaultPii` is `true`.
127+
128+
```javascript
129+
Sentry.init({
130+
integrations: [Sentry.anthropicAIIntegration({ recordOutputs: true })],
131+
});
132+
```
133+
134+
## Configuration
135+
136+
By default this integration adds tracing support to Anthropic API method calls including:
137+
138+
- `messages.create()` - Create messages with Claude models
139+
- `messages.stream()` - Stream messages with Claude models
140+
- `messages.countTokens()` - Count tokens for messages
141+
- `models.get()` - Get model information
142+
- `completions.create()` - Create completions (legacy)
143+
- `models.retrieve()` - Retrieve model details
144+
- `beta.messages.create()` - Beta messages API
145+
146+
The integration will automatically detect streaming vs non-streaming requests and handle them appropriately.
147+
148+
## Supported Versions
149+
150+
- `@anthropic-ai/sdk`: `>=0.19.2 <1.0.0`

docs/platforms/javascript/common/tracing/instrumentation/ai-agents-module.mdx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,11 @@ As a prerequisite to setting up AI Agent Monitoring with JavaScript, you'll need
3434

3535
The JavaScript SDK supports automatic instrumentation for some AI libraries. We recommend adding their integrations to your Sentry configuration to automatically capture spans for AI agents.
3636

37-
- <PlatformLink to="/configuration/integrations/vercelai/">Vercel AI SDK</PlatformLink>
37+
- <PlatformLink to="/configuration/integrations/vercelai/">
38+
Vercel AI SDK
39+
</PlatformLink>
3840
- <PlatformLink to="/configuration/integrations/openai/">OpenAI</PlatformLink>
41+
- <PlatformLink to="/configuration/integrations/anthropic/">Anthropic</PlatformLink>
3942

4043
## Manual Instrumentation
4144

platform-includes/configuration/integrations/javascript.astro.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,4 +82,5 @@ Depending on whether an integration enhances the functionality of a particular r
8282
| [`nodeProfilingIntegration`](./nodeprofiling) | | || |
8383
| [`trpcMiddleware`](./trpc) | ||||
8484
| [`openAIIntegration`](./openai) || || |
85+
| [`anthropicAIIntegration`](./anthropic) |||| |
8586
| [`zodErrorsIntegration`](./zodErrors) | | | ||

platform-includes/configuration/integrations/javascript.aws-lambda.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
| [`childProcessIntegration`](./childProcess) || | ||
2020
| [`vercelAiIntegration`](./vercelai) || || |
2121
| [`openAIIntegration`](./openai) || || |
22+
| [`anthropicAIIntegration`](./anthropic) |||| |
2223
| [`amqplibIntegration`](./amqplib) | | || |
2324
| [`anrIntegration`](./anr) | || | |
2425
| [`captureConsoleIntegration`](./captureconsole) | | | ||

platform-includes/configuration/integrations/javascript.bun.mdx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
### Integrations
22

33
| | **Auto Enabled** | **Errors** | **Tracing** | **Additional Context** |
4-
| --------------------------------------------------------- | :--------------: | :--------: | :---------: | :--------------------: | --- |
4+
| --------------------------------------------------------- | :--------------: | :--------: | :---------: | :--------------------: |
55
| [`amqplibIntegration`](./amqplib) || || |
66
| [`bunServerIntegration`](./bunserver) |||| |
77
| [`consoleIntegration`](./console) || | ||
@@ -31,11 +31,12 @@
3131
| [`prismaIntegration`](./prisma) || || |
3232
| [`vercelAiIntegration`](./vercelai) || || |
3333
| [`openAIIntegration`](./openai) || || |
34+
| [`anthropicAIIntegration`](./anthropic) |||| |
3435
| [`captureConsoleIntegration`](./captureconsole) | | | ||
3536
| [`dataloaderIntegration`](./dataloader) | | || |
3637
| [`extraErrorDataIntegration`](./extraerrordata) | | | ||
3738
| [`knexIntegration`](./knex) | | || |
3839
| [`rewriteFramesIntegration`](./rewriteframes) | || | |
39-
| [`supabaseIntegration`](./supabase) | ||| | |
40+
| [`supabaseIntegration`](./supabase) | ||| |
4041
| [`trpcMiddleware`](./trpc) | ||||
4142
| [`zodErrorsIntegration`](./zodErrors) | | | ||

platform-includes/configuration/integrations/javascript.connect.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
| [`rewriteFramesIntegration`](./rewriteframes) ||| | |
3333
| [`vercelAiIntegration`](./vercelai) || || |
3434
| [`openAIIntegration`](./openai) || || |
35+
| [`anthropicAIIntegration`](./anthropic) |||| |
3536
| [`anrIntegration`](./anr) | || | |
3637
| [`captureConsoleIntegration`](./captureconsole) | | | ||
3738
| [`eventLoopBlockIntegration`](./event-loop-block) | || | |

platform-includes/configuration/integrations/javascript.fastify.mdx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
### Integrations
22

33
| | **Auto Enabled** | **Errors** | **Tracing** | **Additional Context** |
4-
| --------------------------------------------------------- | :--------------: | :--------: | :---------: | :--------------------: | --- |
4+
| --------------------------------------------------------- | :--------------: | :--------: | :---------: | :--------------------: |
55
| [`amqplibIntegration`](./amqplib) || || |
66
| [`consoleIntegration`](./console) || | ||
77
| [`contextLinesIntegration`](./contextlines) ||| | |
@@ -32,6 +32,7 @@
3232
| [`prismaIntegration`](./prisma) || || |
3333
| [`vercelAiIntegration`](./vercelai) || || |
3434
| [`openAIIntegration`](./openai) || || |
35+
| [`anthropicAIIntegration`](./anthropic) |||| |
3536
| [`anrIntegration`](./anr) | || | |
3637
| [`captureConsoleIntegration`](./captureconsole) | | | ||
3738
| [`eventLoopBlockIntegration`](./event-loop-block) | || | |

platform-includes/configuration/integrations/javascript.gcp-functions.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
| [`childProcessIntegration`](./childProcess) || | ||
2020
| [`vercelAiIntegration`](./vercelai) || || |
2121
| [`openAIIntegration`](./openai) || || |
22+
| [`anthropicAIIntegration`](./anthropic) |||| |
2223
| [`amqplibIntegration`](./amqplib) | | || |
2324
| [`anrIntegration`](./anr) | || | |
2425
| [`captureConsoleIntegration`](./captureconsole) | | | ||

platform-includes/configuration/integrations/javascript.hapi.mdx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
### Integrations
22

33
| | **Auto Enabled** | **Errors** | **Tracing** | **Additional Context** |
4-
| --------------------------------------------------------- | :--------------: | :--------: | :---------: | :--------------------: | --- |
4+
| --------------------------------------------------------- | :--------------: | :--------: | :---------: | :--------------------: |
55
| [`amqplibIntegration`](./amqplib) || || |
66
| [`consoleIntegration`](./console) || | ||
77
| [`contextLinesIntegration`](./contextlines) ||| | |
@@ -32,6 +32,7 @@
3232
| [`prismaIntegration`](./prisma) || || |
3333
| [`vercelAiIntegration`](./vercelai) || || |
3434
| [`openAIIntegration`](./openai) || || |
35+
| [`anthropicAIIntegration`](./anthropic) |||| |
3536
| [`anrIntegration`](./anr) | || | |
3637
| [`captureConsoleIntegration`](./captureconsole) | | | ||
3738
| [`eventLoopBlockIntegration`](./event-loop-block) | || | |
@@ -42,6 +43,6 @@
4243
| [`localVariablesIntegration`](./localvariables) | || | |
4344
| [`nodeProfilingIntegration`](./nodeprofiling) | | || |
4445
| [`rewriteFramesIntegration`](./rewriteframes) | || | |
45-
| [`supabaseIntegration`](./supabase) | ||| | |
46+
| [`supabaseIntegration`](./supabase) | ||| |
4647
| [`trpcMiddleware`](./trpc) | ||||
4748
| [`zodErrorsIntegration`](./zodErrors) | | | ||

platform-includes/configuration/integrations/javascript.nestjs.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,5 @@
4545
| [`trpcMiddleware`](./trpc) | ||||
4646
| [`unleashIntegration`](./unleash) | | | ||
4747
| [`openAIIntegration`](./openai) || || |
48+
| [`anthropicAIIntegration`](./anthropic) |||| |
4849
| [`zodErrorsIntegration`](./zodErrors) | | | ||

0 commit comments

Comments
 (0)