---
title: "Google Gen AI"
description: "Learn about using Sentry for Google Gen AI."
url: https://docs.sentry.io/platforms/python/agent-tracing/google-genai/
---

# Google Gen AI for Python

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 Agents Tracing, a Sentry dashboard that helps you understand what's going on with your AI requests.

Sentry AI Observability will automatically collect information about prompts, tools, tokens, and models. Learn more about the [Agents Dashboard](https://docs.sentry.io/product/agents/dashboards.md).

In SDK `3.x`, and in stream mode in SDK `2.x`, this page's references to "transaction" apply to service spans instead. See [Streamed Spans](https://docs.sentry.io/platforms/python/tracing/streamed-spans.md) for more information.

## [Install](https://docs.sentry.io/platforms/python/agent-tracing/google-genai.md#install)

Install `sentry-sdk` from PyPI:

```bash
pip install sentry-sdk
```

*Other available variations of the above snippet: uv*

## [Configure](https://docs.sentry.io/platforms/python/agent-tracing/google-genai.md#configure)

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

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

sentry_sdk.init(
    dsn="https://<key>@o<orgId>.ingest.sentry.io/<projectId>",
    # Set traces_sample_rate to 1.0 to capture 100%
    # of service spans for tracing.
    traces_sample_rate=1.0,
    # Check https://docs.sentry.io/platforms/python/data-management/data-collected/ to configure what data is collected
    data_collection={
        "gen_ai": {"inputs": True, "outputs": True},
    },
    integrations=[
        GoogleGenAIIntegration(),
    ],
)
```

## [Verify](https://docs.sentry.io/platforms/python/agent-tracing/google-genai.md#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():
    # In SDK 2.x, use sentry_sdk.start_transaction(name="The result of the AI inference") instead
    with sentry_sdk.start_span(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 [Invoke Agent Span](https://docs.sentry.io/platforms/python/agent-tracing/manual-instrumentation.md#invoke-agent-span) (not done in the example above) the data will also show up in the [Agents Dashboard](https://docs.sentry.io/product/agents/dashboards.md).

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

## [Behavior](https://docs.sentry.io/platforms/python/agent-tracing/google-genai.md#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).

* By default, the SDK records LLM inputs and outputs, such as prompts, messages, and responses. Tool definitions and the tool calls returned by the model, including their arguments, are recorded too; setting `inputs` and `outputs` to `False` in the `gen_ai` key removes them. The arguments and return values of Python functions you pass as tools are currently always attached to tool execution spans, regardless of these options. To control this, use the `gen_ai` key of the [`data_collection` option](https://docs.sentry.io/platforms/python/configuration/options.md#data_collection), which lets you control inputs and outputs separately:

  ```python
  sentry_sdk.init(
      # ...
      data_collection={
          # Record LLM inputs, but not outputs
          "gen_ai": {"inputs": True, "outputs": False},
      },
  )
  ```

  In SDK versions prior to `3.0`, Sentry considers LLM inputs and outputs as PII and doesn't include prompts, messages, or responses unless you pass a `data_collection` dictionary or set `send_default_pii=True`. With `send_default_pii=True`, you can exclude them with the integration's `include_prompts=False` option, as shown in the [Options section](https://docs.sentry.io/platforms/python/agent-tracing/google-genai.md#options) below.

## [Options](https://docs.sentry.io/platforms/python/agent-tracing/google-genai.md#options)

Only available in SDK versions prior to `3.0`. In SDK `3.x`, `GoogleGenAIIntegration` doesn't accept any options. Use the `gen_ai` key of the [`data_collection` option](https://docs.sentry.io/platforms/python/configuration/options.md#data_collection) instead.

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. If you use the [`data_collection` option](https://docs.sentry.io/platforms/python/configuration/options.md#data_collection), this option is ignored. Use the `gen_ai` key instead.

  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](https://docs.sentry.io/platforms/python/agent-tracing/google-genai.md#supported-versions)

* google-genai: 1.29.0+
* Python: 3.9+
