-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
feat(anthropic) add docs for anthropic integration #14581
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
constantinius
wants to merge
1
commit into
master
Choose a base branch
from
constantinius/feat/anthropic/add-docs
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
--- | ||
title: Anthropic | ||
description: "Learn about using Sentry for Anthropic." | ||
--- | ||
|
||
This integration connects Sentry with the [Anthropic Python SDK](https://github.com/anthropics/anthropic-sdk-python). | ||
|
||
Once you've installed this SDK, you can use Sentry AI Agents Monitoring, a Sentry dashboard that helps you understand what's going on with your AI requests. | ||
|
||
Sentry AI Monitoring will automatically collect information about prompts, tools, tokens, and models. Learn more about the [AI Agents Dashboard](/product/insights/ai/agents). | ||
|
||
## Install | ||
|
||
Install `sentry-sdk` from PyPI with the `anthropic` extra: | ||
|
||
```bash {tabTitle:pip} | ||
pip install "sentry-sdk[anthropic]" | ||
``` | ||
|
||
```bash {tabTitle:uv} | ||
uv add "sentry-sdk[anthropic]" | ||
``` | ||
|
||
## Configure | ||
|
||
If you have the `anthropic` package in your dependencies, the Anthropic integration will be enabled automatically when you initialize the Sentry SDK. | ||
|
||
<PlatformContent includePath="getting-started-config" /> | ||
|
||
## Verify | ||
|
||
Verify that the integration works by making a chat request to Anthropic. | ||
|
||
```python | ||
import sentry_sdk | ||
from anthropic import Anthropic | ||
|
||
sentry_sdk.init(...) # same as above | ||
|
||
client = Anthropic(api_key="(your Anthropic key)") | ||
|
||
def my_llm_stuff(): | ||
with sentry_sdk.start_transaction(name="The result of the AI inference"): | ||
print( | ||
client.messages.create( | ||
model="claude-3-5-sonnet-20240620", | ||
max_tokens=1024, | ||
messages=[{"role": "user", "content": "say hello"}] | ||
) | ||
.content[0] | ||
.text | ||
) | ||
``` | ||
|
||
After running this script, the resulting data should show up in the `"AI Spans"` tab on the `"Explore" > "Traces" > "Trace"` page on Sentry.io. | ||
|
||
If you manually created an <PlatformLink to="/tracing/instrumentation/custom-instrumentation/ai-agents-module/#invoke-agent-span">Invoke Agent Span</PlatformLink> (not done in the example above) the data will also show up in the [AI Agents Dashboard](/product/insights/ai/agents). | ||
|
||
It may take a couple of moments for the data to appear in [sentry.io](https://sentry.io). | ||
|
||
## Behavior | ||
|
||
- The Anthropic integration will connect Sentry with the supported Anthropic methods automatically. | ||
|
||
- The supported function is currently `messages.create` (both sync and async). | ||
|
||
- Sentry considers LLM inputs/outputs as PII (Personally identifiable information) and doesn't include PII data by default. If you want to include the data, set `send_default_pii=True` in the `sentry_sdk.init()` call. To explicitly exclude prompts and outputs despite `send_default_pii=True`, configure the integration with `include_prompts=False` as shown in the [Options section](#options) below. | ||
|
||
## Options | ||
|
||
By adding `AnthropicIntegration` to your `sentry_sdk.init()` call explicitly, you can set options for `AnthropicIntegration` to change its behavior: | ||
|
||
```python | ||
import sentry_sdk | ||
from sentry_sdk.integrations.anthropic import AnthropicIntegration | ||
|
||
sentry_sdk.init( | ||
# ... | ||
# Add data like inputs and responses; | ||
# see https://docs.sentry.io/platforms/python/data-management/data-collected/ for more info | ||
send_default_pii=True, | ||
integrations=[ | ||
AnthropicIntegration( | ||
include_prompts=False, # LLM inputs/outputs will be not sent to Sentry, despite send_default_pii=True | ||
), | ||
], | ||
) | ||
``` | ||
|
||
You can pass the following keyword arguments to `AnthropicIntegration()`: | ||
|
||
- `include_prompts`: | ||
|
||
Whether LLM inputs and outputs should be sent to Sentry. Sentry considers this data personal identifiable data (PII) by default. If you want to include the data, set `send_default_pii=True` in the `sentry_sdk.init()` call. To explicitly exclude prompts and outputs despite `send_default_pii=True`, configure the integration with `include_prompts=False`. | ||
|
||
The default is `True`. | ||
|
||
## Supported Versions | ||
|
||
- Anthropic: 0.16.0+ | ||
- Python: 3.8+ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.