diff --git a/dev-packages/node-integration-tests/suites/tracing/google-genai-v3/instrument-with-recording.mjs b/dev-packages/node-integration-tests/suites/tracing/google-genai-v3/instrument-with-recording.mjs new file mode 100644 index 000000000000..46a27dd03b74 --- /dev/null +++ b/dev-packages/node-integration-tests/suites/tracing/google-genai-v3/instrument-with-recording.mjs @@ -0,0 +1,9 @@ +import * as Sentry from '@sentry/node'; +import { loggingTransport } from '@sentry-internal/node-integration-tests'; + +Sentry.init({ + dsn: 'https://public@dsn.ingest.sentry.io/1337', + release: '1.0', + tracesSampleRate: 1.0, + transport: loggingTransport, +}); diff --git a/dev-packages/node-integration-tests/suites/tracing/google-genai-v3/scenario-decisions.mjs b/dev-packages/node-integration-tests/suites/tracing/google-genai-v3/scenario-decisions.mjs new file mode 100644 index 000000000000..24ed641fc873 --- /dev/null +++ b/dev-packages/node-integration-tests/suites/tracing/google-genai-v3/scenario-decisions.mjs @@ -0,0 +1,90 @@ +import { GoogleGenAI } from '@google/genai'; +import * as Sentry from '@sentry/node'; +import express from 'express'; + +function startMockGoogleGenAIServer() { + const app = express(); + app.use(express.json({ limit: '1mb' })); + + app.post('/v1/decisions', (req, res) => { + if (req.body.model === 'models/error-model') { + // A 400, not a 500: the decisions client retries 5xx responses with backoff by default. + res.status(400).end('Bad request'); + return; + } + + res.send({ + answers: { + wants_refund: { type: 'noul', noul: 0.97, confidence: 0.94 }, + department: { + type: 'choice', + choice: 'billing', + probabilities: { billing: 0.82, other: 0.18 }, + confidence: 0.82, + }, + urgency: { + type: 'score', + score: 1, + probabilities: { 0: 0.05, 1: 0.95 }, + legend: { 0: 'low', 1: 'high' }, + confidence: 0.93, + }, + }, + usage: { total_input_tokens: 382, total_cached_tokens: 256, total_output_tokens: 0, total_tokens: 382 }, + }); + }); + + return new Promise(resolve => { + const server = app.listen(0, () => { + resolve(server); + }); + }); +} + +const questions = { + wants_refund: { + type: 'noul', + instructions: 'Is a refund requested?', + criteria: { true_description: 'Asks for money back' }, + }, + department: { + type: 'choice', + instructions: 'Which team should handle this?', + criteria: { billing: 'Charges and refunds', other: 'Anything else' }, + }, + urgency: { type: 'score', instructions: 'How urgent is this ticket?', criteria: ['low', 'high'] }, +}; + +async function run() { + const server = await startMockGoogleGenAIServer(); + + await Sentry.startSpan({ op: 'function', name: 'main' }, async () => { + const client = new GoogleGenAI({ + apiKey: 'mock-api-key', + httpOptions: { baseUrl: `http://localhost:${server.address().port}` }, + }); + + await client.decisions.create({ + model: 'models/gemini-3-flash', + input: 'I was charged twice and want a refund.', + questions, + }); + + await client.decisions.create({ + model: 'models/gemini-3-flash', + input: [ + { type: 'text', text: 'Is the package damaged?' }, + { type: 'image', mime_type: 'image/png', data: 'iVBORw0KGgoAAAANSUhEUg==' }, + ], + questions: { damaged: { type: 'noul', instructions: 'Is there visible damage?' } }, + }); + + try { + await client.decisions.create({ model: 'models/error-model', input: 'Error test', questions }); + } catch {} + }); + + server.close(); +} + +run(); diff --git a/dev-packages/node-integration-tests/suites/tracing/google-genai-v3/test.ts b/dev-packages/node-integration-tests/suites/tracing/google-genai-v3/test.ts index b63580b79057..67aad77b3348 100644 --- a/dev-packages/node-integration-tests/suites/tracing/google-genai-v3/test.ts +++ b/dev-packages/node-integration-tests/suites/tracing/google-genai-v3/test.ts @@ -1,18 +1,21 @@ import { afterAll, describe, expect } from 'vitest'; import { + GEN_AI_INPUT_MESSAGES, GEN_AI_OPERATION_NAME, + GEN_AI_OUTPUT_MESSAGES, GEN_AI_PROVIDER_NAME, GEN_AI_REQUEST_MAX_TOKENS, GEN_AI_REQUEST_MODEL, GEN_AI_REQUEST_TEMPERATURE, GEN_AI_REQUEST_TOP_P, + GEN_AI_USAGE_CACHE_READ_INPUT_TOKENS, GEN_AI_USAGE_INPUT_TOKENS, GEN_AI_USAGE_OUTPUT_TOKENS, GEN_AI_USAGE_TOTAL_TOKENS, SENTRY_OP, SENTRY_ORIGIN, } from '@sentry/conventions/attributes'; -import { GEN_AI_CHAT, GEN_AI_EMBEDDINGS, GEN_AI_GENERATE_CONTENT } from '@sentry/conventions/op'; +import { GEN_AI_CHAT, GEN_AI_DECIDE, GEN_AI_EMBEDDINGS, GEN_AI_GENERATE_CONTENT } from '@sentry/conventions/op'; import { supports } from '../../../utils'; import { cleanupChildProcesses, createEsmAndCjsTests } from '../../../utils/runner'; @@ -118,4 +121,94 @@ describe.runIf(supports({ min: 22 }))('Google GenAI integration (v3)', () => { }, { additionalDependencies: { '@google/genai': '^3' } }, ); + + createEsmAndCjsTests( + __dirname, + 'scenario-decisions.mjs', + 'instrument-with-recording.mjs', + (createRunner, test) => { + test('instruments decisions.create as decide spans on @google/genai v3', async () => { + const runner = createRunner().ignore('event'); + const spansPromise = runner.collectStreamedSpansUntilSegment('main'); + + await runner.start().completed(); + + const allSpans = await spansPromise; + const mainSpan = allSpans.find(span => span.name === 'main'); + const spans = allSpans.filter(span => span.attributes[SENTRY_OP]?.value === GEN_AI_DECIDE); + expect(spans).toHaveLength(3); + for (const span of spans) { + expect(span.parent_span_id).toBe(mainSpan!.span_id); + } + + // Both successful spans share a name and may arrive in any order, so match on the input. + const inputOf = (span: (typeof spans)[number]): string => String(span.attributes[GEN_AI_INPUT_MESSAGES]?.value); + const textSpan = spans.find(span => inputOf(span).includes('charged twice')); + const imageSpan = spans.find(span => inputOf(span).includes('package damaged')); + + expect(textSpan!.name).toBe('decide models/gemini-3-flash'); + expect(textSpan!.status).toBe('ok'); + expect(textSpan!.attributes).toMatchObject({ + [SENTRY_ORIGIN]: { value: EXPECTED_ORIGIN }, + [GEN_AI_OPERATION_NAME]: { value: 'decide' }, + [GEN_AI_PROVIDER_NAME]: { value: 'google_genai' }, + [GEN_AI_REQUEST_MODEL]: { value: 'models/gemini-3-flash' }, + [GEN_AI_USAGE_INPUT_TOKENS]: { value: 382 }, + [GEN_AI_USAGE_CACHE_READ_INPUT_TOKENS]: { value: 256 }, + [GEN_AI_USAGE_OUTPUT_TOKENS]: { value: 0 }, + [GEN_AI_USAGE_TOTAL_TOKENS]: { value: 382 }, + }); + expect(JSON.parse(textSpan!.attributes[GEN_AI_INPUT_MESSAGES]!.value as string)).toEqual([ + { + type: 'evaluation', + state: 'I was charged twice and want a refund.', + questions: { + wants_refund: { + type: 'noul', + instructions: 'Is a refund requested?', + criteria: { true_description: 'Asks for money back' }, + }, + department: { + type: 'choice', + instructions: 'Which team should handle this?', + criteria: { billing: 'Charges and refunds', other: 'Anything else' }, + }, + urgency: { type: 'score', instructions: 'How urgent is this ticket?', criteria: ['low', 'high'] }, + }, + }, + ]); + expect(JSON.parse(textSpan!.attributes[GEN_AI_OUTPUT_MESSAGES]!.value as string)).toEqual([ + { + type: 'evaluation', + answers: { + wants_refund: { type: 'noul', noul: 0.97, confidence: 0.94 }, + department: { + type: 'choice', + choice: 'billing', + probabilities: { billing: 0.82, other: 0.18 }, + confidence: 0.82, + }, + urgency: { + type: 'score', + score: 1, + probabilities: { 0: 0.05, 1: 0.95 }, + legend: { 0: 'low', 1: 'high' }, + confidence: 0.93, + }, + }, + }, + ]); + + expect(JSON.parse(imageSpan!.attributes[GEN_AI_INPUT_MESSAGES]!.value as string)[0].state).toEqual([ + { type: 'text', text: 'Is the package damaged?' }, + { type: 'image', mime_type: 'image/png', data: 'iVBORw0KGgoAAAANSUhEUg==' }, + ]); + + const errorSpan = spans.find(span => span.name === 'decide models/error-model'); + expect(errorSpan!.status).toBe('error'); + expect(errorSpan!.attributes[GEN_AI_OPERATION_NAME].value).toBe('decide'); + }); + }, + { additionalDependencies: { '@google/genai': '^3' } }, + ); }); diff --git a/packages/server-utils/src/ai/google-genai/constants.ts b/packages/server-utils/src/ai/google-genai/constants.ts index 12fec18a7ba4..b2b41592a516 100644 --- a/packages/server-utils/src/ai/google-genai/constants.ts +++ b/packages/server-utils/src/ai/google-genai/constants.ts @@ -6,6 +6,7 @@ export const GOOGLE_GENAI_INTEGRATION_NAME = 'Google_GenAI' as const; // https://ai.google.dev/api/rest/v1/chats/sendMessage // https://googleapis.github.io/js-genai/release_docs/classes/models.Models.html#generatecontentstream // https://googleapis.github.io/js-genai/release_docs/classes/chats.Chat.html#sendmessagestream +// https://ai.google.dev/api/decisions export const GOOGLE_GENAI_METHOD_REGISTRY = { 'models.generateContent': { operation: 'generate_content' }, 'models.generateContentStream': { operation: 'generate_content', streaming: true }, @@ -13,6 +14,7 @@ export const GOOGLE_GENAI_METHOD_REGISTRY = { 'chats.create': { proxyResultPath: 'chat' }, 'chat.sendMessage': { operation: 'chat' }, 'chat.sendMessageStream': { operation: 'chat', streaming: true }, + 'decisions.create': { operation: 'decide' }, } as const satisfies InstrumentedMethodRegistry; // Constants for internal use diff --git a/packages/server-utils/src/ai/google-genai/decisions.ts b/packages/server-utils/src/ai/google-genai/decisions.ts new file mode 100644 index 000000000000..5ae62f634d48 --- /dev/null +++ b/packages/server-utils/src/ai/google-genai/decisions.ts @@ -0,0 +1,36 @@ +// Google's questions and answers already use Jev's layout, so only the evaluated input is renamed. +import { GEN_AI_OUTPUT_MESSAGES } from '@sentry/conventions/attributes'; +import type { Span } from '@sentry/core'; +import { isObjectLike } from '@sentry/core'; +import { getEvaluationInputMessages, getEvaluationOutputMessages, getTokenUsageAttributes } from '../core/utils'; + +/** + * Serialize a decisions request. Its evidence is `input` where Jev's is `state`; it is recorded as `state` + * so both render the same. + */ +export function getDecisionInputMessages(params: Record): string | undefined { + return getEvaluationInputMessages({ state: params.input, questions: params.questions }); +} + +export function addDecisionResponseAttributes(span: Span, response: unknown, recordOutputs: boolean): void { + if (!isObjectLike(response)) { + return; + } + + if (isObjectLike(response.usage)) { + const usage = response.usage as Record; + span.setAttributes( + getTokenUsageAttributes( + usage.total_input_tokens, + usage.total_output_tokens, + undefined, + usage.total_cached_tokens, + usage.total_tokens, + ), + ); + } + + if (recordOutputs && response.answers !== undefined) { + span.setAttribute(GEN_AI_OUTPUT_MESSAGES, getEvaluationOutputMessages(response.answers)); + } +} diff --git a/packages/server-utils/src/ai/google-genai/index.ts b/packages/server-utils/src/ai/google-genai/index.ts index d80559565ba4..60a3f653c008 100644 --- a/packages/server-utils/src/ai/google-genai/index.ts +++ b/packages/server-utils/src/ai/google-genai/index.ts @@ -34,10 +34,12 @@ import { buildMethodPath, getErrorStatus, getGenAiSpanOp, + getRequestSignal, getTokenUsageAttributes, resolveAIRecordingOptions, } from '../core/utils'; import { GOOGLE_GENAI_METHOD_REGISTRY, GOOGLE_GENAI_SYSTEM_NAME } from './constants'; +import { addDecisionResponseAttributes, getDecisionInputMessages } from './decisions'; import { instrumentStream } from './streaming'; import type { Candidate, ContentPart, GoogleGenAIOptions, GoogleGenAIResponse } from './types'; import type { ContentListUnion, Message, PartListUnion } from './utils'; @@ -135,6 +137,11 @@ export function extractRequestAttributes( attributes[GEN_AI_TOOL_DEFINITIONS] = JSON.stringify(functionDeclarations); } } + + const decisionInput = recordInputs && operationName === 'decide' ? getDecisionInputMessages(params) : undefined; + if (decisionInput) { + attributes[GEN_AI_INPUT_MESSAGES] = decisionInput; + } } else { attributes[GEN_AI_REQUEST_MODEL] = extractModel({}, context); } @@ -198,9 +205,19 @@ export function addPrivateRequestAttributes(span: Span, params: Record | undefined): Abo return (params?.config as { abortSignal?: AbortSignal } | undefined)?.abortSignal; } +/** `decisions.create` takes its abort signal in its request options, not in a `config`. */ +export function getCallAbortSignal( + operationName: string, + params: Record | undefined, + requestOptions: unknown, +): AbortSignal | undefined { + return operationName === 'decide' ? getRequestSignal(requestOptions) : getAbortSignal(params); +} + /** * Instrument any async or synchronous genai method with Sentry spans * Handles operations like models.generateContent and chat.sendMessage and chats.create @@ -318,7 +344,7 @@ function instrumentMethod( const operationName = instrumentedMethod.operation || 'unknown'; const params = args[0] as Record | undefined; const attributeParams = resolveChatParams(operationName, params, context); - const abortSignal = getAbortSignal(attributeParams); + const abortSignal = getCallAbortSignal(operationName, attributeParams, args[1]); const requestAttributes = extractRequestAttributes( operationName, attributeParams, @@ -377,7 +403,7 @@ function instrumentMethod( result => { // Only add response attributes for content-producing methods, not for embeddings if (!isEmbeddings) { - addResponseAttributes(span, result, options.recordOutputs); + addResponseAttributes(span, result, options.recordOutputs, operationName); } }, ); diff --git a/packages/server-utils/src/integrations/google-genai.ts b/packages/server-utils/src/integrations/google-genai.ts index 6ffae5f8df56..8704b4e19612 100644 --- a/packages/server-utils/src/integrations/google-genai.ts +++ b/packages/server-utils/src/integrations/google-genai.ts @@ -15,6 +15,7 @@ import { addResponseAttributes, extractRequestAttributes, getAbortSignal, + getCallAbortSignal, resolveChatParams, } from '../ai/google-genai'; import { shouldSkipAiProviderSpan } from '../ai/pi-ai/providers'; @@ -37,6 +38,7 @@ const INSTRUMENTED_CHANNELS = [ { channel: CHANNELS.GOOGLE_GENAI_GENERATE_CONTENT, operation: 'generate_content' }, { channel: CHANNELS.GOOGLE_GENAI_EMBED_CONTENT, operation: 'embeddings' }, { channel: CHANNELS.GOOGLE_GENAI_CHAT, operation: 'chat' }, + { channel: CHANNELS.GOOGLE_GENAI_DECIDE, operation: 'decide' }, ] as const; const _googleGenAIIntegration = ((options: GoogleGenAIOptions = {}) => { @@ -61,7 +63,7 @@ function instrumentGoogleGenai(options: GoogleGenAIOptions): void { data.arguments?.[0] as Record | undefined, data.self, ); - markCancelledIfAborted(span, getAbortSignal(params)); + markCancelledIfAborted(span, getCallAbortSignal(operation, params, data.arguments?.[1])); } // Embeddings responses carry no content attributes. if (operation !== 'embeddings') { @@ -69,6 +71,7 @@ function instrumentGoogleGenai(options: GoogleGenAIOptions): void { span, data.result as GoogleGenAIResponse, resolveAIRecordingOptions(options).recordOutputs, + operation, ); } }, @@ -171,8 +174,8 @@ function wrapStreamResult( /** * Diagnostics-channel-based Google GenAI integration. Subscribes to the * `orchestrion:@google/genai:*` diagnostics_channels injected into the SDK's `Models` - * (`generateContent`/`generateContentStream`/`embedContent`) and `Chat` - * (`sendMessage`/`sendMessageStream`) methods, so it requires the Sentry runtime hook or - * bundler plugin. + * (`generateContent`/`generateContentStream`/`embedContent`), `Chat` + * (`sendMessage`/`sendMessageStream`) and decisions (`create`) methods, so it requires the Sentry + * runtime hook or bundler plugin. */ export const googleGenAIIntegration = defineIntegration(_googleGenAIIntegration); diff --git a/packages/server-utils/src/orchestrion/config/google-genai.ts b/packages/server-utils/src/orchestrion/config/google-genai.ts index d643ed6e59d1..500b8eb50bc7 100644 --- a/packages/server-utils/src/orchestrion/config/google-genai.ts +++ b/packages/server-utils/src/orchestrion/config/google-genai.ts @@ -34,6 +34,12 @@ export const googleGenAiConfig = [ functionQuery: { className: 'Chat', methodName, kind: 'Auto' as const }, })), ), + // `client.decisions` (`@google/genai` >= 3.2.0) returns typed answers rather than generated content. + ...NODE_DIST_FILES.map(filePath => ({ + channelName: 'decide', + module: { name: '@google/genai', versionRange: '>=3.2.0 <4', filePath }, + functionQuery: { className: 'GeminiNextGenDecisions', methodName: 'create', kind: 'Async' as const }, + })), ] satisfies InstrumentationConfig[]; export const googleGenAiModuleNames = getModuleNames(googleGenAiConfig); @@ -42,4 +48,5 @@ export const googleGenAiChannels = { GOOGLE_GENAI_GENERATE_CONTENT: 'orchestrion:@google/genai:generate-content', GOOGLE_GENAI_EMBED_CONTENT: 'orchestrion:@google/genai:embed-content', GOOGLE_GENAI_CHAT: 'orchestrion:@google/genai:chat', + GOOGLE_GENAI_DECIDE: 'orchestrion:@google/genai:decide', } as const; diff --git a/packages/server-utils/test/ai/lib/tracing/caller-abort.test.ts b/packages/server-utils/test/ai/lib/tracing/caller-abort.test.ts index d6deff64250e..6d88ea390555 100644 --- a/packages/server-utils/test/ai/lib/tracing/caller-abort.test.ts +++ b/packages/server-utils/test/ai/lib/tracing/caller-abort.test.ts @@ -43,6 +43,15 @@ const providers: Array<{ name: string; call: () => Call }> = [ }; }, }, + { + // `decisions.create` has no streaming variant, so `stream` is ignored. + name: 'google-genai decisions', + call: () => { + const client = instrumentGoogleGenAIClient({ decisions: { create: rejectingMethod() } }); + return signal => + client.decisions.create({ model: 'models/gemini-3-flash', input: 'Hello', questions: {} }, { signal }); + }, + }, { name: 'mistral', call: () => { diff --git a/packages/server-utils/test/ai/lib/tracing/google-genai.test.ts b/packages/server-utils/test/ai/lib/tracing/google-genai.test.ts index 1001a10ea766..a9b2e0343027 100644 --- a/packages/server-utils/test/ai/lib/tracing/google-genai.test.ts +++ b/packages/server-utils/test/ai/lib/tracing/google-genai.test.ts @@ -2,6 +2,7 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'; import { GEN_AI_INPUT_MESSAGES, GEN_AI_OPERATION_NAME, + GEN_AI_OUTPUT_MESSAGES, GEN_AI_PROVIDER_NAME, GEN_AI_REQUEST_FREQUENCY_PENALTY, GEN_AI_REQUEST_MAX_TOKENS, @@ -12,8 +13,13 @@ import { GEN_AI_REQUEST_TOP_P, GEN_AI_SYSTEM_INSTRUCTIONS, GEN_AI_TOOL_DEFINITIONS, + GEN_AI_USAGE_CACHE_READ_INPUT_TOKENS, + GEN_AI_USAGE_INPUT_TOKENS, + GEN_AI_USAGE_OUTPUT_TOKENS, + GEN_AI_USAGE_TOTAL_TOKENS, } from '@sentry/conventions/attributes'; -import { getMainCarrier, setCurrentClient, spanToStaticSpanJSON } from '@sentry/core'; +import { GEN_AI_DECIDE } from '@sentry/conventions/op'; +import { getClient, getMainCarrier, setCurrentClient, spanToStaticSpanJSON } from '@sentry/core'; import type { Span } from '@sentry/core'; import { instrumentGoogleGenAIClient } from '../../../../src/ai/google-genai'; import { getDefaultTestClientOptions, TestClient } from '../../../mocks/client'; @@ -314,3 +320,87 @@ describe('instrumentGoogleGenAIClient chat config propagation', () => { expect(data[GEN_AI_REQUEST_MAX_TOKENS]).toBe(150); }); }); + +describe('instrumentGoogleGenAIClient decisions.create', () => { + beforeEach(() => { + getMainCarrier().__SENTRY__ = undefined; + }); + + afterEach(() => { + getMainCarrier().__SENTRY__ = undefined; + }); + + const DECISION_REQUEST = { + model: 'models/gemini-3-flash', + input: 'I was charged twice and want a refund.', + questions: { wants_refund: { type: 'noul', instructions: 'Is a refund requested?' } }, + }; + const DECISION_RESPONSE = { + answers: { wants_refund: { type: 'noul', noul: 0.97, confidence: 0.94 } }, + usage: { total_input_tokens: 382, total_cached_tokens: 256, total_output_tokens: 0, total_tokens: 382 }, + }; + + function fakeDecisionsClient(create = vi.fn().mockResolvedValue(DECISION_RESPONSE)) { + return { decisions: { create } }; + } + + it('records the input when the span starts, so samplers can read it', async () => { + setupClient('stream'); + const inputsAtStart: unknown[] = []; + getClient()!.on('spanStart', span => inputsAtStart.push(spanToStaticSpanJSON(span).data[GEN_AI_INPUT_MESSAGES])); + const instrumented = instrumentGoogleGenAIClient(fakeDecisionsClient()); + + await instrumented.decisions.create(DECISION_REQUEST); + + expect(inputsAtStart).toEqual([ + JSON.stringify([{ type: 'evaluation', state: DECISION_REQUEST.input, questions: DECISION_REQUEST.questions }]), + ]); + }); + + it('records a decide span with its answers and token usage', async () => { + const endedSpans = setupClient('stream'); + const instrumented = instrumentGoogleGenAIClient(fakeDecisionsClient()); + + await instrumented.decisions.create(DECISION_REQUEST); + + expect(endedSpans).toHaveLength(1); + const json = spanToStaticSpanJSON(endedSpans[0]!); + expect(json.description).toBe('decide models/gemini-3-flash'); + expect(json.op).toBe(GEN_AI_DECIDE); + expect(json.data[GEN_AI_OPERATION_NAME]).toBe('decide'); + expect(json.data[GEN_AI_USAGE_INPUT_TOKENS]).toBe(382); + expect(json.data[GEN_AI_USAGE_CACHE_READ_INPUT_TOKENS]).toBe(256); + expect(json.data[GEN_AI_USAGE_OUTPUT_TOKENS]).toBe(0); + expect(json.data[GEN_AI_USAGE_TOTAL_TOKENS]).toBe(382); + expect(JSON.parse(json.data[GEN_AI_OUTPUT_MESSAGES] as string)).toEqual([ + { type: 'evaluation', answers: DECISION_RESPONSE.answers }, + ]); + }); + + it('records neither input nor answers when recording is off', async () => { + const endedSpans = setupClient('stream'); + const instrumented = instrumentGoogleGenAIClient(fakeDecisionsClient(), { + recordInputs: false, + recordOutputs: false, + }); + + await instrumented.decisions.create(DECISION_REQUEST); + + const { data } = spanToStaticSpanJSON(endedSpans[0]!); + expect(data[GEN_AI_INPUT_MESSAGES]).toBeUndefined(); + expect(data[GEN_AI_OUTPUT_MESSAGES]).toBeUndefined(); + expect(data[GEN_AI_USAGE_INPUT_TOKENS]).toBe(382); + }); + + it('marks a failed call as an internal error', async () => { + const endedSpans = setupClient('stream'); + const instrumented = instrumentGoogleGenAIClient( + fakeDecisionsClient(vi.fn().mockRejectedValue(new Error('500 Internal server error'))), + ); + + await expect(instrumented.decisions.create(DECISION_REQUEST)).rejects.toThrow('500 Internal server error'); + + expect(endedSpans).toHaveLength(1); + expect(spanToStaticSpanJSON(endedSpans[0]!).status).toBe('internal_error'); + }); +});