diff --git a/docs/platforms/javascript/common/configuration/integrations/google-genai.mdx b/docs/platforms/javascript/common/configuration/integrations/google-genai.mdx index 0d86204dfcb75..14838fa32bf90 100644 --- a/docs/platforms/javascript/common/configuration/integrations/google-genai.mdx +++ b/docs/platforms/javascript/common/configuration/integrations/google-genai.mdx @@ -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 --- + + +## 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. + -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. -_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. + - -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: + -```javascript -Sentry.init({ - dsn: "____PUBLIC_DSN____", - tracesSampleRate: 1.0, - integrations: [ - Sentry.googleGenAIIntegration({ - recordInputs: true, - recordOutputs: true, - }), - ], -}); -``` +## Browser-Side Usage - +_Import name: `Sentry.instrumentGoogleGenAIClient`_ -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"; + -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!"); -``` + + + + + + + + +For Next.js applications using the Edge runtime, manual instrumentation is required using `instrumentGoogleGenAIClient`. This integration is automatically instrumented in the Node.js runtime. + + - -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, @@ -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. + -## 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** + + + +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. - - + -## Edge runtime + -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!"); ``` +## 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`