Skip to content

Commit 720834b

Browse files
authored
feat: Document Google Gen AI Integration (#15061)
<!-- Use this checklist to make sure your PR is ready for merge. You may delete any sections you don't need. --> ## DESCRIBE YOUR PR Documents Google Gen AI integration ## IS YOUR CHANGE URGENT? Help us prioritize incoming PRs by letting us know when the change needs to go live. - [ ] Urgent deadline (GA date, etc.): <!-- ENTER DATE HERE --> - [X] Other deadline: Oct 1st - [ ] None: Not urgent, can wait up to 1 week+ ## SLA - Teamwork makes the dream work, so please add a reviewer to your PRs. - Please give the docs team up to 1 week to review your PR unless you've added an urgent due date to it. Thanks in advance for your help! ## PRE-MERGE CHECKLIST *Make sure you've checked the following before merging your changes:* - [X] Checked Vercel preview for correctness, including links - [ ] PR was reviewed and approved by any necessary SMEs (subject matter experts) - [ ] PR was reviewed and approved by a member of the [Sentry docs team](https://github.com/orgs/getsentry/teams/docs) ## LEGAL BOILERPLATE <!-- Sentry employees and contractors can delete or ignore this section. --> Look, I get it. The entity doing business as "Sentry" was incorporated in the State of Delaware in 2015 as Functional Software, Inc. and is gonna need some rights from me in order to utilize my contributions in this here PR. So here's the deal: I retain all rights, title and interest in and to my contributions, and by keeping this boilerplate intact I confirm that Sentry can use, modify, copy, and redistribute my contributions, under Sentry's choice of terms. ## EXTRA RESOURCES - [Sentry Docs contributor guide](https://docs.sentry.io/contributing/)
1 parent 48059da commit 720834b

File tree

16 files changed

+155
-0
lines changed

16 files changed

+155
-0
lines changed
Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
---
2+
title: Google Gen AI
3+
description: "Adds instrumentation for Google Gen AI SDK."
4+
supported:
5+
- javascript.node
6+
- javascript.aws-lambda
7+
- javascript.azure-functions
8+
- javascript.connect
9+
- javascript.express
10+
- javascript.fastify
11+
- javascript.gcp-functions
12+
- javascript.hapi
13+
- javascript.hono
14+
- javascript.koa
15+
- javascript.nestjs
16+
- javascript.electron
17+
- javascript.nextjs
18+
- javascript.nuxt
19+
- javascript.solidstart
20+
- javascript.sveltekit
21+
- javascript.react-router
22+
- javascript.remix
23+
- javascript.astro
24+
- javascript.bun
25+
- javascript.tanstackstart-react
26+
- javascript.cloudflare
27+
---
28+
29+
<Alert>
30+
31+
This integration works in the Node.js, Cloudflare Workers, and Vercel Edge Functions runtimes. It requires SDK version `10.14.0` or higher.
32+
33+
</Alert>
34+
35+
_Import name: `Sentry.googleGenAIIntegration`_
36+
37+
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.
38+
39+
<PlatformSection notSupported={["javascript.cloudflare", "javascript.nextjs"]}>
40+
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:
41+
42+
```javascript
43+
Sentry.init({
44+
dsn: "____PUBLIC_DSN____",
45+
tracesSampleRate: 1.0,
46+
integrations: [
47+
Sentry.googleGenAIIntegration({
48+
recordInputs: true,
49+
recordOutputs: true,
50+
}),
51+
],
52+
});
53+
```
54+
55+
</PlatformSection>
56+
57+
<PlatformSection supported={["javascript.cloudflare"]}>
58+
For Cloudflare Workers, you need to manually instrument the Google Gen AI client using the `instrumentGoogleGenAIClient` helper:
59+
60+
```javascript
61+
import * as Sentry from "@sentry/cloudflare";
62+
import { GoogleGenAI } from "@google/genai";
63+
64+
const genAI = new GoogleGenAI(process.env.API_KEY);
65+
const client = Sentry.instrumentGoogleGenAIClient(genAI, {
66+
recordInputs: true,
67+
recordOutputs: true,
68+
});
69+
70+
// Use the wrapped client instead of the original genAI instance
71+
const result = await client.models.generateContent("Hello!");
72+
```
73+
74+
</PlatformSection>
75+
76+
<PlatformSection supported={['javascript.nextjs']}>
77+
78+
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:
79+
80+
```javascript
81+
import * as Sentry from "@sentry/nextjs";
82+
import { GoogleGenAI } from "@google/genai";
83+
84+
const genAI = new GoogleGenAI(process.env.API_KEY);
85+
const client = Sentry.instrumentGoogleGenAIClient(genAI, {
86+
recordInputs: true,
87+
recordOutputs: true,
88+
});
89+
90+
// Use the wrapped client instead of the original genAI instance
91+
const result = await client.models.generateContent("Hello!");
92+
```
93+
94+
</PlatformSection>
95+
96+
## Options
97+
98+
### `recordInputs`
99+
100+
_Type: `boolean`_
101+
102+
Records inputs to Google Gen AI SDK method calls (such as prompts and messages).
103+
104+
Defaults to `true` if `sendDefaultPii` is `true`.
105+
106+
```javascript
107+
Sentry.init({
108+
integrations: [Sentry.googleGenAIIntegration({ recordInputs: true })],
109+
});
110+
```
111+
112+
### `recordOutputs`
113+
114+
_Type: `boolean`_
115+
116+
Records outputs from Google Gen AI SDK method calls (such as generated text and responses).
117+
118+
Defaults to `true` if `sendDefaultPii` is `true`.
119+
120+
```javascript
121+
Sentry.init({
122+
integrations: [Sentry.googleGenAIIntegration({ recordOutputs: true })],
123+
});
124+
```
125+
126+
## Configuration
127+
128+
By default this integration adds tracing support to Google Gen AI SDK method calls including:
129+
130+
- `models.generateContent()` - Make an API request to generate content with a given model.
131+
- `models.generateContentStream()` - Make an API request to generate content with a given model and yields the response in chunks.
132+
- `chats.create()` - Create chat sessions.
133+
- `sendMessage()` - Send messages in chat sessions.
134+
- `sendMessageStream()` - Stream messages in chat sessions.
135+
136+
The integration will automatically detect streaming vs non-streaming requests and handle them appropriately.
137+
138+
## Supported Versions
139+
140+
- `@google/genai`: `>=0.10.0 <2`

docs/platforms/javascript/common/tracing/instrumentation/ai-agents-module.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ The JavaScript SDK supports automatic instrumentation for some AI libraries. We
3939
</PlatformLink>
4040
- <PlatformLink to="/configuration/integrations/openai/">OpenAI</PlatformLink>
4141
- <PlatformLink to="/configuration/integrations/anthropic/">Anthropic</PlatformLink>
42+
- <PlatformLink to="/configuration/integrations/google-genai/">Google Gen AI SDK</PlatformLink>
4243

4344
## Manual Instrumentation
4445

platform-includes/configuration/integrations/javascript.astro.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,4 +83,5 @@ Depending on whether an integration enhances the functionality of a particular r
8383
| [`trpcMiddleware`](./trpc) | ||||
8484
| [`openAIIntegration`](./openai) || || |
8585
| [`anthropicAIIntegration`](./anthropic) |||| |
86+
| [`googleGenAIIntegration`](./google-genai) |||| |
8687
| [`zodErrorsIntegration`](./zodErrors) | | | ||

platform-includes/configuration/integrations/javascript.aws-lambda.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
| [`vercelAiIntegration`](./vercelai) || || |
2121
| [`openAIIntegration`](./openai) || || |
2222
| [`anthropicAIIntegration`](./anthropic) |||| |
23+
| [`googleGenAIIntegration`](./google-genai) |||| |
2324
| [`amqplibIntegration`](./amqplib) | | || |
2425
| [`anrIntegration`](./anr) | || | |
2526
| [`captureConsoleIntegration`](./captureconsole) | | | ||

platform-includes/configuration/integrations/javascript.bun.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
| [`vercelAiIntegration`](./vercelai) || || |
3333
| [`openAIIntegration`](./openai) || || |
3434
| [`anthropicAIIntegration`](./anthropic) |||| |
35+
| [`googleGenAIIntegration`](./google-genai) |||| |
3536
| [`captureConsoleIntegration`](./captureconsole) | | | ||
3637
| [`dataloaderIntegration`](./dataloader) | | || |
3738
| [`extraErrorDataIntegration`](./extraerrordata) | | | ||

platform-includes/configuration/integrations/javascript.connect.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
| [`vercelAiIntegration`](./vercelai) || || |
3434
| [`openAIIntegration`](./openai) || || |
3535
| [`anthropicAIIntegration`](./anthropic) |||| |
36+
| [`googleGenAIIntegration`](./google-genai) |||| |
3637
| [`anrIntegration`](./anr) | || | |
3738
| [`captureConsoleIntegration`](./captureconsole) | | | ||
3839
| [`eventLoopBlockIntegration`](./event-loop-block) | || | |

platform-includes/configuration/integrations/javascript.fastify.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
| [`vercelAiIntegration`](./vercelai) || || |
3434
| [`openAIIntegration`](./openai) || || |
3535
| [`anthropicAIIntegration`](./anthropic) |||| |
36+
| [`googleGenAIIntegration`](./google-genai) |||| |
3637
| [`anrIntegration`](./anr) | || | |
3738
| [`captureConsoleIntegration`](./captureconsole) | | | ||
3839
| [`eventLoopBlockIntegration`](./event-loop-block) | || | |

platform-includes/configuration/integrations/javascript.gcp-functions.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
| [`vercelAiIntegration`](./vercelai) || || |
2121
| [`openAIIntegration`](./openai) || || |
2222
| [`anthropicAIIntegration`](./anthropic) |||| |
23+
| [`googleGenAIIntegration`](./google-genai) |||| |
2324
| [`amqplibIntegration`](./amqplib) | | || |
2425
| [`anrIntegration`](./anr) | || | |
2526
| [`captureConsoleIntegration`](./captureconsole) | | | ||

platform-includes/configuration/integrations/javascript.hapi.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
| [`vercelAiIntegration`](./vercelai) || || |
3434
| [`openAIIntegration`](./openai) || || |
3535
| [`anthropicAIIntegration`](./anthropic) |||| |
36+
| [`googleGenAIIntegration`](./google-genai) |||| |
3637
| [`anrIntegration`](./anr) | || | |
3738
| [`captureConsoleIntegration`](./captureconsole) | | | ||
3839
| [`eventLoopBlockIntegration`](./event-loop-block) | || | |

platform-includes/configuration/integrations/javascript.nestjs.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,5 @@
4646
| [`unleashIntegration`](./unleash) | | | ||
4747
| [`openAIIntegration`](./openai) || || |
4848
| [`anthropicAIIntegration`](./anthropic) |||| |
49+
| [`googleGenAIIntegration`](./google-genai) |||| |
4950
| [`zodErrorsIntegration`](./zodErrors) | | | ||

0 commit comments

Comments
 (0)