Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
114 changes: 114 additions & 0 deletions docs/platforms/python/integrations/google-genai/index.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
---
title: Google Gen AI
description: "Learn about using Sentry for Google Gen AI."
---

This integration connects Sentry with the [Google Gen AI Python SDK](https://github.com/googleapis/python-genai).

Once you've installed this SDK, you can use the 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 `google-genai` extra:

```bash {tabTitle:pip}
pip install "sentry-sdk[google-genai]"
```

```bash {tabTitle:uv}
uv add "sentry-sdk[google-genai]"
```

## Configure

Add `GoogleGenAIIntegration()` to your `integrations` list:

```python
import sentry_sdk
from sentry_sdk.integrations.google_genai import GoogleGenAIIntegration

sentry_sdk.init(
dsn="___PUBLIC_DSN___",
# Set traces_sample_rate to 1.0 to capture 100%
# of transactions for tracing.
traces_sample_rate=1.0,
# 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=[
GoogleGenAIIntegration(),
],
)
```

## Verify

Verify that the integration works by making a chat request to Google Gen AI.

```python
import sentry_sdk
from sentry_sdk.integrations.google_genai import GoogleGenAIIntegration
from google.genai import Client

sentry_sdk.init(...) # same as above

client = Client(api_key="(your Google API key)")

def my_llm_stuff():
with sentry_sdk.start_transaction(name="The result of the AI inference"):
response = client.models.generate_content(
model="gemini-2.0-flash-exp",
contents="say hello"
)
print(response.text)
```

After running this script, the resulting data should show up in the `"AI Spans"` tab on the `"Explore" > "Traces"` 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 Google Gen AI integration will connect Sentry with the supported Google Gen AI methods automatically.

- The supported function is currently `models.generate_content` (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

You can set options for `GoogleGenAIIntegration` to change its behavior:

```python
import sentry_sdk
from sentry_sdk.integrations.google_genai import GoogleGenAIIntegration

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=[
GoogleGenAIIntegration(
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 `GoogleGenAIIntegration()`:

- `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

- google-genai: 1.4.0+
- Python: 3.9+
19 changes: 10 additions & 9 deletions docs/platforms/python/integrations/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,16 @@ The Sentry SDK uses integrations to hook into the functionality of popular libra

### AI

| | **Auto-enabled** |
| ---------------------------------------------------------------------------------------------------------------------------------- | :--------------: |
| <LinkWithPlatformIcon platform="anthropic" label="Anthropic" url="/platforms/python/integrations/anthropic" /> | ✓ |
| <LinkWithPlatformIcon platform="huggingface_hub" label="Hugging Face Hub" url="/platforms/python/integrations/huggingface_hub" /> | ✓ |
| <LinkWithPlatformIcon platform="openai" label="OpenAI" url="/platforms/python/integrations/openai" /> | ✓ |
| <LinkWithPlatformIcon platform="openai-agents" label="OpenAI Agents SDK" url="/platforms/python/integrations/openai-agents" /> | |
| <LinkWithPlatformIcon platform="langchain" label="LangChain" url="/platforms/python/integrations/langchain" /> | ✓ |
| <LinkWithPlatformIcon platform="langgraph" label="LangGraph" url="/platforms/python/integrations/langgraph" /> | ✓ |
| <LinkWithPlatformIcon platform="litellm" label="LiteLLM" url="/platforms/python/integrations/litellm" /> | |
| | **Auto-enabled** |
| --------------------------------------------------------------------------------------------------------------------------------- | :--------------: |
| <LinkWithPlatformIcon platform="anthropic" label="Anthropic" url="/platforms/python/integrations/anthropic" /> | ✓ |
| <LinkWithPlatformIcon platform="google-genai" label="Google Gen AI" url="/platforms/python/integrations/google-genai" /> | |
| <LinkWithPlatformIcon platform="huggingface_hub" label="Hugging Face Hub" url="/platforms/python/integrations/huggingface_hub" /> | ✓ |
| <LinkWithPlatformIcon platform="openai" label="OpenAI" url="/platforms/python/integrations/openai" /> | ✓ |
| <LinkWithPlatformIcon platform="openai-agents" label="OpenAI Agents SDK" url="/platforms/python/integrations/openai-agents" /> | |
| <LinkWithPlatformIcon platform="langchain" label="LangChain" url="/platforms/python/integrations/langchain" /> | ✓ |
| <LinkWithPlatformIcon platform="langgraph" label="LangGraph" url="/platforms/python/integrations/langgraph" /> | ✓ |
| <LinkWithPlatformIcon platform="litellm" label="LiteLLM" url="/platforms/python/integrations/litellm" /> | |

### Data Processing

Expand Down
4 changes: 2 additions & 2 deletions docs/platforms/python/integrations/litellm/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ response = litellm.completion(
print(response.choices[0].message.content)
```

After running this script, the resulting data should show up in the `AI Spans` tab on the `Explore > Traces > Trace` page on Sentry.io.
After running this script, the resulting data should show up in the `"AI Spans"` tab on the `"Explore" > "Traces"` 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).
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).

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ As a prerequisite to setting up AI Agent Monitoring with Python, you'll need to
The Python SDK supports automatic instrumentation for some AI libraries. We recommend adding their integrations to your Sentry configuration to automatically capture spans for AI agents.

- <PlatformLink to="/integrations/anthropic/">Anthropic</PlatformLink>
- <PlatformLink to="/integrations/google-genai/">Google Gen AI</PlatformLink>
- <PlatformLink to="/integrations/openai/">OpenAI</PlatformLink>
- <PlatformLink to="/integrations/openai-agents/">OpenAI Agents SDK</PlatformLink>
- <PlatformLink to="/integrations/langchain/">LangChain</PlatformLink>
Expand Down
Loading