Skip to content

Commit 7f1b49d

Browse files
authored
feat(ai-insights): google gen ai sdk docs (#15197)
1 parent 9f80969 commit 7f1b49d

File tree

4 files changed

+127
-11
lines changed

4 files changed

+127
-11
lines changed
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
---
2+
title: Google Gen AI
3+
description: "Learn about using Sentry for Google Gen AI."
4+
---
5+
6+
This integration connects Sentry with the [Google Gen AI Python SDK](https://github.com/googleapis/python-genai).
7+
8+
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.
9+
10+
Sentry AI Monitoring will automatically collect information about prompts, tools, tokens, and models. Learn more about the [AI Agents Dashboard](/product/insights/ai/agents).
11+
12+
## Install
13+
14+
Install `sentry-sdk` from PyPI with the `google-genai` extra:
15+
16+
```bash {tabTitle:pip}
17+
pip install "sentry-sdk[google-genai]"
18+
```
19+
20+
```bash {tabTitle:uv}
21+
uv add "sentry-sdk[google-genai]"
22+
```
23+
24+
## Configure
25+
26+
Add `GoogleGenAIIntegration()` to your `integrations` list:
27+
28+
```python
29+
import sentry_sdk
30+
from sentry_sdk.integrations.google_genai import GoogleGenAIIntegration
31+
32+
sentry_sdk.init(
33+
dsn="___PUBLIC_DSN___",
34+
# Set traces_sample_rate to 1.0 to capture 100%
35+
# of transactions for tracing.
36+
traces_sample_rate=1.0,
37+
# Add data like inputs and responses;
38+
# see https://docs.sentry.io/platforms/python/data-management/data-collected/ for more info
39+
send_default_pii=True,
40+
integrations=[
41+
GoogleGenAIIntegration(),
42+
],
43+
)
44+
```
45+
46+
## Verify
47+
48+
Verify that the integration works by making a chat request to Google Gen AI.
49+
50+
```python
51+
import sentry_sdk
52+
from sentry_sdk.integrations.google_genai import GoogleGenAIIntegration
53+
from google.genai import Client
54+
55+
sentry_sdk.init(...) # same as above
56+
57+
client = Client(api_key="(your Google API key)")
58+
59+
def my_llm_stuff():
60+
with sentry_sdk.start_transaction(name="The result of the AI inference"):
61+
response = client.models.generate_content(
62+
model="gemini-2.0-flash-exp",
63+
contents="say hello"
64+
)
65+
print(response.text)
66+
```
67+
68+
After running this script, the resulting data should show up in the `"AI Spans"` tab on the `"Explore" > "Traces"` page on Sentry.io.
69+
70+
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).
71+
72+
It may take a couple of moments for the data to appear in [sentry.io](https://sentry.io).
73+
74+
## Behavior
75+
76+
- The Google Gen AI integration will connect Sentry with the supported Google Gen AI methods automatically.
77+
78+
- The supported function is currently `models.generate_content` (both sync and async).
79+
80+
- 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.
81+
82+
## Options
83+
84+
You can set options for `GoogleGenAIIntegration` to change its behavior:
85+
86+
```python
87+
import sentry_sdk
88+
from sentry_sdk.integrations.google_genai import GoogleGenAIIntegration
89+
90+
sentry_sdk.init(
91+
# ...
92+
# Add data like inputs and responses;
93+
# see https://docs.sentry.io/platforms/python/data-management/data-collected/ for more info
94+
send_default_pii=True,
95+
integrations=[
96+
GoogleGenAIIntegration(
97+
include_prompts=False, # LLM inputs/outputs will be not sent to Sentry, despite send_default_pii=True
98+
),
99+
],
100+
)
101+
```
102+
103+
You can pass the following keyword arguments to `GoogleGenAIIntegration()`:
104+
105+
- `include_prompts`:
106+
107+
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`.
108+
109+
The default is `True`.
110+
111+
## Supported Versions
112+
113+
- google-genai: 1.4.0+
114+
- Python: 3.9+

docs/platforms/python/integrations/index.mdx

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,16 @@ The Sentry SDK uses integrations to hook into the functionality of popular libra
3838

3939
### AI
4040

41-
| | **Auto-enabled** |
42-
| ---------------------------------------------------------------------------------------------------------------------------------- | :--------------: |
43-
| <LinkWithPlatformIcon platform="anthropic" label="Anthropic" url="/platforms/python/integrations/anthropic" /> ||
44-
| <LinkWithPlatformIcon platform="huggingface_hub" label="Hugging Face Hub" url="/platforms/python/integrations/huggingface_hub" /> ||
45-
| <LinkWithPlatformIcon platform="openai" label="OpenAI" url="/platforms/python/integrations/openai" /> ||
46-
| <LinkWithPlatformIcon platform="openai-agents" label="OpenAI Agents SDK" url="/platforms/python/integrations/openai-agents" /> | |
47-
| <LinkWithPlatformIcon platform="langchain" label="LangChain" url="/platforms/python/integrations/langchain" /> ||
48-
| <LinkWithPlatformIcon platform="langgraph" label="LangGraph" url="/platforms/python/integrations/langgraph" /> ||
49-
| <LinkWithPlatformIcon platform="litellm" label="LiteLLM" url="/platforms/python/integrations/litellm" /> | |
41+
| | **Auto-enabled** |
42+
| --------------------------------------------------------------------------------------------------------------------------------- | :--------------: |
43+
| <LinkWithPlatformIcon platform="anthropic" label="Anthropic" url="/platforms/python/integrations/anthropic" /> ||
44+
| <LinkWithPlatformIcon platform="google-genai" label="Google Gen AI" url="/platforms/python/integrations/google-genai" /> | |
45+
| <LinkWithPlatformIcon platform="huggingface_hub" label="Hugging Face Hub" url="/platforms/python/integrations/huggingface_hub" /> ||
46+
| <LinkWithPlatformIcon platform="openai" label="OpenAI" url="/platforms/python/integrations/openai" /> ||
47+
| <LinkWithPlatformIcon platform="openai-agents" label="OpenAI Agents SDK" url="/platforms/python/integrations/openai-agents" /> | |
48+
| <LinkWithPlatformIcon platform="langchain" label="LangChain" url="/platforms/python/integrations/langchain" /> ||
49+
| <LinkWithPlatformIcon platform="langgraph" label="LangGraph" url="/platforms/python/integrations/langgraph" /> ||
50+
| <LinkWithPlatformIcon platform="litellm" label="LiteLLM" url="/platforms/python/integrations/litellm" /> | |
5051

5152
### Data Processing
5253

docs/platforms/python/integrations/litellm/index.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,9 @@ response = litellm.completion(
6969
print(response.choices[0].message.content)
7070
```
7171

72-
After running this script, the resulting data should show up in the `AI Spans` tab on the `Explore > Traces > Trace` page on Sentry.io.
72+
After running this script, the resulting data should show up in the `"AI Spans"` tab on the `"Explore" > "Traces"` page on Sentry.io.
7373

74-
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).
74+
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).
7575

7676
It may take a couple of moments for the data to appear in [sentry.io](https://sentry.io).
7777

docs/platforms/python/tracing/instrumentation/custom-instrumentation/ai-agents-module.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ As a prerequisite to setting up AI Agent Monitoring with Python, you'll need to
1313
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.
1414

1515
- <PlatformLink to="/integrations/anthropic/">Anthropic</PlatformLink>
16+
- <PlatformLink to="/integrations/google-genai/">Google Gen AI</PlatformLink>
1617
- <PlatformLink to="/integrations/openai/">OpenAI</PlatformLink>
1718
- <PlatformLink to="/integrations/openai-agents/">OpenAI Agents SDK</PlatformLink>
1819
- <PlatformLink to="/integrations/langchain/">LangChain</PlatformLink>

0 commit comments

Comments
 (0)