From 0b9df1685e748df88b67707147bbae7f118a4c6f Mon Sep 17 00:00:00 2001 From: czyber Date: Sun, 17 Mar 2024 09:25:44 +0100 Subject: [PATCH 1/7] add Anthropic docs The anthropic python sdk integration is documented and added to the integrations list --- .../python/integrations/anthropic/index.mdx | 93 +++++++++++++++++++ docs/platforms/python/integrations/index.mdx | 7 +- 2 files changed, 97 insertions(+), 3 deletions(-) create mode 100644 docs/platforms/python/integrations/anthropic/index.mdx diff --git a/docs/platforms/python/integrations/anthropic/index.mdx b/docs/platforms/python/integrations/anthropic/index.mdx new file mode 100644 index 0000000000000..b5b0190307267 --- /dev/null +++ b/docs/platforms/python/integrations/anthropic/index.mdx @@ -0,0 +1,93 @@ +--- +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). +The integration has been confirmed to work with Anthropic 0.16.0. + +## Install + +Install `sentry-sdk` from PyPI with the `anthropic` extra: + +```bash +pip install --upgrade 'sentry-sdk[anthropic]' +``` + +## Configure + +Add the `AnthropicIntegration` to the `sentry_sdk.init` call: + +```python +from anthropic import Anthropic + +import sentry_sdk + +sentry_sdk.init( + dsn="___PUBLIC_DSN___", + enable_tracing=True, + traces_sample_rate=1.0, + integrations=[AnthropicIntegration()], +) + +client = Anthropic() +``` + +## Verify + +Verify that the integration works by snucking in a bug (e.g. a bad API key), this will cause a new error event to be sent to Sentry: +```python +from anthropic import Anthropic +import sentry_sdk + +sentry_sdk.init(...) # same as above + +client = Anthropic(api_key="invalid-key") +with sentry_sdk.start_transaction(op="ai-inference", name="AI inference"): + response = ( + client.messages.create( + max_tokens=42, + model="some-model", + messages=[{"role": "system", "content": "Hello, Anthropic!"}] + ) + ) + print(response) +``` + +Executing this script initiates a transaction within the Performance section of [sentry.io](https://sentry.io). Furthermore, it triggers the sending of an error event (about the bad API key) to [sentry.io](https://sentry.io), which will be linked to the transaction. + +It takes a couple of moments for the data to appear in [sentry.io](https://sentry.io). + +## Behavior + +- The supported modules are currently `chat.messages.create` with `stream=True` and `stream=False`. + +- All exceptions leading to an `AnthropicError` are reported. + +- Sentry is configured not to consider LLM and tokenizer inputs/outputs as PII. If you want to include them, set `send_default_pii=True` in the `sentry_sdk.init()` call. To explicitly exclude prompts despite `send_default_pii=True`, configure the integration with `include_prompts=False` like in the Options section. + +## Options + +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`. + +```python +import sentry_sdk +from sentry_sdk.integrations.anthropic import AnthropicIntegration + +sentry_sdk.init( + dsn="___PUBLIC_DSN___", + enable_tracing=True, + send_default_pii=True, + traces_sample_rate=1.0, + integrations = [ + AnthropicIntegration( + include_prompts=False, # Exclude prompts from being sent to Sentry, despite send_default_pii=True + ), + ], +) +``` + +## Supported Versions + +- Anthropic: 0.16.0+ +- Python: 3.7+ diff --git a/docs/platforms/python/integrations/index.mdx b/docs/platforms/python/integrations/index.mdx index a0e9ce7bd0565..d1298e97ffef2 100644 --- a/docs/platforms/python/integrations/index.mdx +++ b/docs/platforms/python/integrations/index.mdx @@ -35,9 +35,10 @@ The Sentry SDK uses integrations to hook into the functionality of popular libra ## AI -| | **Auto enabled** | -| ------------------------------------------------------------------------------------------------------------------ | :--------------: | -| | ✓ | +| | **Auto enabled** | +| --------------------------------------------------------------------------------------------------------------------------- | :--------------: | +| | ✓ | +| | | ## Data Processing From 99ffe0aafc433fb8626a61749f54fe657dbc33a5 Mon Sep 17 00:00:00 2001 From: czyber Date: Sun, 17 Mar 2024 09:48:14 +0100 Subject: [PATCH 2/7] reformat code snippet --- docs/platforms/python/integrations/anthropic/index.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/platforms/python/integrations/anthropic/index.mdx b/docs/platforms/python/integrations/anthropic/index.mdx index b5b0190307267..679b0dbdb8624 100644 --- a/docs/platforms/python/integrations/anthropic/index.mdx +++ b/docs/platforms/python/integrations/anthropic/index.mdx @@ -79,7 +79,7 @@ sentry_sdk.init( enable_tracing=True, send_default_pii=True, traces_sample_rate=1.0, - integrations = [ + integrations=[ AnthropicIntegration( include_prompts=False, # Exclude prompts from being sent to Sentry, despite send_default_pii=True ), From 3f6adc33f1187ed5e3703067195255c1c2a84d7f Mon Sep 17 00:00:00 2001 From: Bernhard Czypka <130161325+czyber@users.noreply.github.com> Date: Sun, 24 Mar 2024 14:48:53 +0100 Subject: [PATCH 3/7] Update docs/platforms/python/integrations/anthropic/index.mdx Co-authored-by: vivianyentran <20403606+vivianyentran@users.noreply.github.com> --- docs/platforms/python/integrations/anthropic/index.mdx | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/docs/platforms/python/integrations/anthropic/index.mdx b/docs/platforms/python/integrations/anthropic/index.mdx index 679b0dbdb8624..f4e28120b1b08 100644 --- a/docs/platforms/python/integrations/anthropic/index.mdx +++ b/docs/platforms/python/integrations/anthropic/index.mdx @@ -3,8 +3,7 @@ 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). -The integration has been confirmed to work with Anthropic 0.16.0. +This integration connects Sentry with the [Anthropic Python SDK](https://github.com/anthropics/anthropic-sdk-python) and works with Anthropic versions `0.16.0` and above. ## Install From 984562406f5b5bdf5873257648f5bbc433105fa0 Mon Sep 17 00:00:00 2001 From: Bernhard Czypka <130161325+czyber@users.noreply.github.com> Date: Sun, 24 Mar 2024 14:49:01 +0100 Subject: [PATCH 4/7] Update docs/platforms/python/integrations/anthropic/index.mdx Co-authored-by: vivianyentran <20403606+vivianyentran@users.noreply.github.com> --- docs/platforms/python/integrations/anthropic/index.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/platforms/python/integrations/anthropic/index.mdx b/docs/platforms/python/integrations/anthropic/index.mdx index f4e28120b1b08..e98fdf818f6eb 100644 --- a/docs/platforms/python/integrations/anthropic/index.mdx +++ b/docs/platforms/python/integrations/anthropic/index.mdx @@ -15,7 +15,7 @@ pip install --upgrade 'sentry-sdk[anthropic]' ## Configure -Add the `AnthropicIntegration` to the `sentry_sdk.init` call: +Add `AnthropicIntegration()` to your `integrations` in the `sentry_sdk.init` call: ```python from anthropic import Anthropic From aff79cab6bd2d58c34f22202997b59320cb83a2b Mon Sep 17 00:00:00 2001 From: Bernhard Czypka <130161325+czyber@users.noreply.github.com> Date: Sun, 24 Mar 2024 14:49:07 +0100 Subject: [PATCH 5/7] Update docs/platforms/python/integrations/anthropic/index.mdx Co-authored-by: vivianyentran <20403606+vivianyentran@users.noreply.github.com> --- docs/platforms/python/integrations/anthropic/index.mdx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/platforms/python/integrations/anthropic/index.mdx b/docs/platforms/python/integrations/anthropic/index.mdx index e98fdf818f6eb..5aeac2a5e204c 100644 --- a/docs/platforms/python/integrations/anthropic/index.mdx +++ b/docs/platforms/python/integrations/anthropic/index.mdx @@ -34,7 +34,8 @@ client = Anthropic() ## Verify -Verify that the integration works by snucking in a bug (e.g. a bad API key), this will cause a new error event to be sent to Sentry: +Verify that the integration works by adding in a bug (such as a bad API key) to your code. This will cause a new error event to be sent to Sentry: + ```python from anthropic import Anthropic import sentry_sdk From 85acf352a6f52cded338efeaa5793b07f26040ea Mon Sep 17 00:00:00 2001 From: Bernhard Czypka <130161325+czyber@users.noreply.github.com> Date: Sun, 24 Mar 2024 14:49:13 +0100 Subject: [PATCH 6/7] Update docs/platforms/python/integrations/anthropic/index.mdx Co-authored-by: vivianyentran <20403606+vivianyentran@users.noreply.github.com> --- docs/platforms/python/integrations/anthropic/index.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/platforms/python/integrations/anthropic/index.mdx b/docs/platforms/python/integrations/anthropic/index.mdx index 5aeac2a5e204c..8734ee417ea46 100644 --- a/docs/platforms/python/integrations/anthropic/index.mdx +++ b/docs/platforms/python/integrations/anthropic/index.mdx @@ -54,7 +54,7 @@ with sentry_sdk.start_transaction(op="ai-inference", name="AI inference"): print(response) ``` -Executing this script initiates a transaction within the Performance section of [sentry.io](https://sentry.io). Furthermore, it triggers the sending of an error event (about the bad API key) to [sentry.io](https://sentry.io), which will be linked to the transaction. +Executing this script initiates a transaction, which will show up in the Performance section of [sentry.io](https://sentry.io). Furthermore, it also sends Sentry an error event (about the bad API key), which will be linked to the transaction. It takes a couple of moments for the data to appear in [sentry.io](https://sentry.io). From 46a396fedd6f1f5ee6ba895de0bd681524111331 Mon Sep 17 00:00:00 2001 From: Bernhard Czypka <130161325+czyber@users.noreply.github.com> Date: Sun, 24 Mar 2024 14:49:21 +0100 Subject: [PATCH 7/7] Update docs/platforms/python/integrations/anthropic/index.mdx Co-authored-by: vivianyentran <20403606+vivianyentran@users.noreply.github.com> --- docs/platforms/python/integrations/anthropic/index.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/platforms/python/integrations/anthropic/index.mdx b/docs/platforms/python/integrations/anthropic/index.mdx index 8734ee417ea46..6c6aabc213af6 100644 --- a/docs/platforms/python/integrations/anthropic/index.mdx +++ b/docs/platforms/python/integrations/anthropic/index.mdx @@ -64,7 +64,7 @@ It takes a couple of moments for the data to appear in [sentry.io](https://sentr - All exceptions leading to an `AnthropicError` are reported. -- Sentry is configured not to consider LLM and tokenizer inputs/outputs as PII. If you want to include them, set `send_default_pii=True` in the `sentry_sdk.init()` call. To explicitly exclude prompts despite `send_default_pii=True`, configure the integration with `include_prompts=False` like in the Options section. +- Sentry is configured not to consider LLM and tokenizer inputs/outputs as PII. If you want to include them, set `send_default_pii=True` in the `sentry_sdk.init()` call. To explicitly exclude prompts despite `send_default_pii=True`, configure the integration with `include_prompts=False`, as shown in [Options](#options). ## Options