You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- Separate server-side and browser-side usage sections for clarity
- Document anthropicAIIntegration for Node.js platforms (auto-enabled by
default)
- Document instrumentAnthropicAiClient for browser and edge runtimes
- Add special handling for Cloudflare Workers edge runtime
- Simplify code examples by omitting import statements
- Move configuration and supported versions to shared sections
- Improve platform-specific visibility using PlatformSection components
closes
https://linear.app/getsentry/issue/TET-1738/anthropic-ai-integration-restructure-and-improve-docs
The `anthropicAIIntegration` adds instrumentation for the [`@anthropic-ai/sdk`](https://www.npmjs.com/package/@anthropic-ai/sdk) API to capture spans by wrapping Anthropic SDK calls and recording LLM interactions.
This integration works in the Node.js, Cloudflare Workers, Vercel Edge Functions, and browser runtimes. It requires SDK version `10.12.0` or higher.
50
+
Enabled by default and automatically captures spans for Anthropic SDK calls. Requires Sentry SDK version `10.28.0` or higher.
33
51
34
52
</Alert>
35
53
36
-
_Import name: `Sentry.anthropicAIIntegration`_
54
+
</PlatformSection>
37
55
38
-
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.
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:
58
+
<Alert>
42
59
43
-
```javascript
44
-
Sentry.init({
45
-
dsn:"____PUBLIC_DSN____",
46
-
tracesSampleRate:1.0,
47
-
integrations: [
48
-
Sentry.anthropicAIIntegration({
49
-
recordInputs:true,
50
-
recordOutputs:true,
51
-
}),
52
-
],
53
-
});
54
-
```
60
+
Enabled by default and automatically captures spans for Anthropic SDK calls. Requires Sentry SDK version `10.28.0` or higher.
61
+
62
+
For other runtimes, like the Browser, the instrumentation needs to be manually enabled. See the [setup instructions below](#browser-side-usage).
63
+
64
+
</Alert>
65
+
66
+
</PlatformSection>
67
+
68
+
To customize what data is captured (such as inputs and outputs), see the [Options](#options) in the Configuration section.
For Cloudflare Workers, manual instrumentation is required using `instrumentAnthropicAiClient`.
70
83
71
-
// Use the wrapped client instead of the original anthropic instance
72
-
constresponse=awaitclient.messages.create({
73
-
model:"claude-3-5-sonnet-20241022",
74
-
max_tokens:1024,
75
-
messages: [{ role:"user", content:"Hello!" }],
76
-
});
77
-
```
84
+
</Alert>
78
85
79
86
</PlatformSection>
80
87
81
-
<PlatformSectionsupported={["javascript"]}>
82
-
For browser applications, you need to manually instrument the Anthropic client using the `instrumentAnthropicAiClient` helper:
88
+
The `instrumentAnthropicAiClient` helper adds instrumentation for the [`@anthropic-ai/sdk`](https://www.npmjs.com/package/@anthropic-ai/sdk) API to capture spans by wrapping Anthropic SDK calls and recording LLM interactions with configurable input/output recording. You need to manually wrap your Anthropic client instance with this helper. See example below:
83
89
84
90
```javascript
85
-
import*asSentryfrom"@sentry/browser";
86
91
importAnthropicfrom"@anthropic-ai/sdk";
87
92
88
-
constanthropic=newAnthropic();
93
+
constanthropic=newAnthropic({
94
+
apiKey:"your-api-key", // Warning: API key will be exposed in browser!
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:
0 commit comments