⚠ This page is served via a proxy. Original site: https://github.com
This service does not collect credentials or authentication data.
Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -25,63 +25,68 @@ supported:
- javascript.tanstackstart-react
- javascript.cloudflare
- javascript
- javascript.react
- javascript.angular
- javascript.vue
- javascript.svelte
- javascript.solid
- javascript.ember
- javascript.gatsby
---

<PlatformSection notSupported={["javascript", "javascript.react", "javascript.angular", "javascript.vue", "javascript.svelte", "javascript.solid", "javascript.ember", "javascript.gatsby"]}>

## Server-Side Usage

_Import name: `Sentry.googleGenAIIntegration`_

The `googleGenAIIntegration` adds instrumentation for the `@google/genai` SDK to capture spans by wrapping Google Gen AI client calls and recording LLM interactions.

<Alert>

This integration works in the Node.js, Cloudflare Workers, Vercel Edge Functions, and browser runtimes. It requires SDK version `10.14.0` or higher.
This integration is **enabled by default for Node.js-based platforms** and automatically captures spans for Google Gen AI SDK method calls. It requires SDK version `10.14.0` or higher.

</Alert>

_Import name: `Sentry.googleGenAIIntegration`_
To customize what data is captured (such as inputs and outputs), see the [Options](#options) in the Configuration section.

The `googleGenAIIntegration` adds instrumentation for the `@google/genai` SDK to capture spans by automatically wrapping Google Gen AI client calls and recording LLM interactions with configurable input/output recording.
</PlatformSection>

<PlatformSection notSupported={["javascript.cloudflare", "javascript.nextjs", "javascript"]}>
It is enabled by default and will automatically capture spans for Google Gen AI SDK method calls. You can opt-in to capture inputs and outputs by setting `recordInputs` and `recordOutputs` in the integration config:
<PlatformSection supported={["javascript", "javascript.react", "javascript.angular", "javascript.vue", "javascript.svelte", "javascript.solid", "javascript.ember", "javascript.gatsby", "javascript.nextjs", "javascript.nuxt", "javascript.solidstart", "javascript.sveltekit", "javascript.react-router", "javascript.remix", "javascript.astro", "javascript.tanstackstart-react", "javascript.electron", "javascript.cloudflare"]}>

```javascript
Sentry.init({
dsn: "____PUBLIC_DSN____",
tracesSampleRate: 1.0,
integrations: [
Sentry.googleGenAIIntegration({
recordInputs: true,
recordOutputs: true,
}),
],
});
```
## Browser-Side Usage

</PlatformSection>
_Import name: `Sentry.instrumentGoogleGenAIClient`_

<PlatformSection supported={["javascript.cloudflare"]}>
For Cloudflare Workers, you need to manually instrument the Google Gen AI client using the `instrumentGoogleGenAIClient` helper:

```javascript
import * as Sentry from "@sentry/cloudflare";
import { GoogleGenAI } from "@google/genai";
<Alert>

const genAI = new GoogleGenAI(process.env.API_KEY);
const client = Sentry.instrumentGoogleGenAIClient(genAI, {
recordInputs: true,
recordOutputs: true,
});
For Cloudflare Workers, manual instrumentation is required using `instrumentGoogleGenAIClient`.

// Use the wrapped client instead of the original genAI instance
const result = await client.models.generateContent("Hello!");
```
</Alert>

</PlatformSection>

<PlatformSection supported={["javascript.nextjs"]}>

<Alert>

For Next.js applications using the Edge runtime, manual instrumentation is required using `instrumentGoogleGenAIClient`. This integration is automatically instrumented in the Node.js runtime.

</Alert>

</PlatformSection>

<PlatformSection supported={["javascript"]}>
For browser applications, you need to manually instrument the Google Gen AI client using the `instrumentGoogleGenAIClient` helper:
The `instrumentGoogleGenAIClient` helper adds instrumentation for the `@google/genai` SDK to capture spans by wrapping Google Gen AI client calls and recording LLM interactions with configurable input/output recording. You need to manually wrap your Google Gen AI client instance with this helper. See example below:

```javascript
import * as Sentry from "@sentry/browser";
import { GoogleGenAI } from "@google/genai";

const genAI = new GoogleGenAI(process.env.API_KEY);
const genAI = new GoogleGenAI({
apiKey: "your-api-key", // Warning: API key will be exposed in browser!
});

const client = Sentry.instrumentGoogleGenAIClient(genAI, {
recordInputs: true,
recordOutputs: true,
Comment on lines 82 to 92
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: The browser-side code example is missing the import * as Sentry statement, which will cause a ReferenceError when copied by users.
Severity: HIGH

Suggested Fix

Add the appropriate Sentry import statement, such as import * as Sentry from "@sentry/browser";, to the beginning of the code example in the "Browser-Side Usage" section. The specific import should match the target platform (e.g., @sentry/nextjs for Next.js).

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.

Location:
docs/platforms/javascript/common/configuration/integrations/google-genai.mdx#L81-L92

Potential issue: The code example provided for browser-side usage of the Google Gen AI
integration is missing a required import statement. The example calls
`Sentry.instrumentGoogleGenAIClient(...)` but does not include the necessary `import *
as Sentry from "@sentry/browser";` (or equivalent for other platforms). Users who copy
and paste this code will encounter a `ReferenceError: Sentry is not defined` at runtime,
preventing them from successfully implementing the integration.

Did we get this right? 👍 / 👎 to inform future reviews.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was intentionally removed to avoid introducing platform-specific conditions, such as @sentry/nextjs.

Expand All @@ -91,72 +96,76 @@ const client = Sentry.instrumentGoogleGenAIClient(genAI, {
const result = await client.models.generateContent("Hello!");
```

To customize what data is captured (such as inputs and outputs), see the [Options](#options) in the Configuration section.

</PlatformSection>

## Options
## Configuration

### Options

### `recordInputs`
The following options control what data is captured from Google Gen AI SDK calls:

_Type: `boolean`_
#### `recordInputs`

_Type: `boolean` (optional)_

Records inputs to Google Gen AI SDK method calls (such as prompts and messages).

Defaults to `true` if `sendDefaultPii` is `true`.

```javascript
Sentry.init({
integrations: [Sentry.googleGenAIIntegration({ recordInputs: true })],
});
```

### `recordOutputs`
#### `recordOutputs`

_Type: `boolean`_
_Type: `boolean` (optional)_

Records outputs from Google Gen AI SDK method calls (such as generated text and responses).

Defaults to `true` if `sendDefaultPii` is `true`.

**Usage**

<PlatformSection notSupported={["javascript", "javascript.react", "javascript.angular", "javascript.vue", "javascript.svelte", "javascript.solid", "javascript.ember", "javascript.gatsby"]}>

Automatic Instrumentation

```javascript
Sentry.init({
integrations: [Sentry.googleGenAIIntegration({ recordOutputs: true })],
dsn: "____PUBLIC_DSN____",
tracesSampleRate: 1.0, // Required for AI observability
integrations: [
Sentry.googleGenAIIntegration({
// your options here
}),
],
});
```

## Configuration

By default this integration adds tracing support to Google Gen AI SDK method calls including:

- `models.generateContent()` - Make an API request to generate content with a given model.
- `models.generateContentStream()` - Make an API request to generate content with a given model and yields the response in chunks.
- `chats.create()` - Create chat sessions.
- `sendMessage()` - Send messages in chat sessions.
- `sendMessageStream()` - Stream messages in chat sessions.

The integration will automatically detect streaming vs non-streaming requests and handle them appropriately.

<PlatformSection supported={['javascript.nextjs']}>
</PlatformSection>

## Edge runtime
<PlatformSection supported={["javascript", "javascript.react", "javascript.angular", "javascript.vue", "javascript.svelte", "javascript.solid", "javascript.ember", "javascript.gatsby", "javascript.nextjs", "javascript.nuxt", "javascript.solidstart", "javascript.sveltekit", "javascript.react-router", "javascript.remix", "javascript.astro", "javascript.tanstackstart-react", "javascript.electron", "javascript.cloudflare"]}>

This integration is automatically instrumented in the Node.js runtime. For Next.js applications using the Edge runtime, you need to manually instrument the Google Gen AI client:
Manual Instrumentation

```javascript
import * as Sentry from "@sentry/nextjs";
import { GoogleGenAI } from "@google/genai";

const genAI = new GoogleGenAI(process.env.API_KEY);
const client = Sentry.instrumentGoogleGenAIClient(genAI, {
recordInputs: true,
recordOutputs: true,
// your options here
});

// Use the wrapped client instead of the original genAI instance
const result = await client.models.generateContent("Hello!");
```

</PlatformSection>

## Supported Operations

By default, tracing support is added to the following Google Gen AI SDK method calls:

- `models.generateContent()` - Generate content with a given model
- `models.generateContentStream()` - Stream content generation with a given model
- `chats.create()` - Create chat sessions
- `sendMessage()` - Send messages in chat sessions
- `sendMessageStream()` - Stream messages in chat sessions

Streaming and non-streaming requests are automatically detected and handled appropriately.

## Supported Versions

- `@google/genai`: `>=0.10.0 <2`