Anthropic
Learn about using Sentry for Anthropic.
Beta
The support for Anthropic is in its beta phase.
We are working on supporting different AI libraries (see GitHub discussion).
If you want to try the beta features and are willing to give feedback, please let us know on Discord.
This integration connects Sentry with the Anthropic Python SDK and works with Anthropic versions 0.16.0 and above.
Once you've installed this SDK, you can use Sentry LLM Monitoring, a Sentry dashboard that helps you understand what's going on with your AI pipelines.
Sentry LLM Monitoring will automatically collect information about prompts, tokens, and models from providers like OpenAI. Learn more about it here.
Install sentry-sdk from PyPI with the anthropic extra:
pip install --upgrade 'sentry-sdk[anthropic]'
If you have the anthropic package in your dependencies, the Anthropic integration will be enabled automatically when you initialize the Sentry SDK.
import sentry_sdk
sentry_sdk.init(
dsn="https://examplePublicKey@o0.ingest.sentry.io/0",
# Set traces_sample_rate to 1.0 to capture 100%
# of transactions for tracing.
traces_sample_rate=1.0,
# Set profiles_sample_rate to 1.0 to profile 100%
# of sampled transactions.
# We recommend adjusting this value in production.
profiles_sample_rate=1.0,
)
Verify that the integration works by creating an AI pipeline. The resulting data should show up in your LLM monitoring dashboard.
import sentry_sdk
from sentry_sdk.ai.monitoring import ai_track
from anthropic import Anthropic
sentry_sdk.init(...) # same as above
client = Anthropic(api_key="(your Anthropic API key)")
@ai_track("My AI pipeline")
def my_pipeline():
with sentry_sdk.start_transaction(op="ai-inference", name="The result of the AI inference"):
print(
client.messages.create(
max_tokens=42,
model="some-model",
messages=[{"role": "system", "content": "Hello, Anthropic!"}]
)
)
After running this script, a pipeline will be created in the LLM Monitoring section of the Sentry dashboard.
The pipeline will have an associated Anthropic span for the messages.create operation.
It may take a couple of moments for the data to appear in sentry.io.
The supported modules are currently
chat.messages.createwithstream=Trueandstream=False.All exceptions leading to an
AnthropicErrorare reported.Sentry considers LLM and tokenizer inputs/outputs as PII and doesn't include PII data by default. If you want to include the data, set
send_default_pii=Truein thesentry_sdk.init()call. To explicitly exclude prompts and outputs despitesend_default_pii=True, configure the integration withinclude_prompts=Falseas shown in the Options section below.
The AnthropicIntegration takes an optional include_prompts parameter. If set to False, prompts are excluded from being sent to Sentry, despite send_default_pii=True.
import sentry_sdk
from sentry_sdk.integrations.anthropic import AnthropicIntegration
sentry_sdk.init(
# same options as above
send_default_pii=True,
integrations=[
AnthropicIntegration(
include_prompts=False, # Exclude prompts from being sent to Sentry, despite send_default_pii=True
),
],
)
- Anthropic: 0.16.0+
- Python: 3.7+
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").