Skip to content

Commit 6bcd3ab

Browse files
committed
Add missing google operation name attribute
1 parent 623e6f1 commit 6bcd3ab

1 file changed

Lines changed: 31 additions & 0 deletions

File tree

  • dev-packages/node-integration-tests/suites/tracing/google-genai

dev-packages/node-integration-tests/suites/tracing/google-genai/test.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { afterAll, describe, expect } from 'vitest';
22
import {
33
GEN_AI_EMBEDDINGS_INPUT_ATTRIBUTE,
44
GEN_AI_INPUT_MESSAGES_ATTRIBUTE,
5+
GEN_AI_OPERATION_NAME_ATTRIBUTE,
56
GEN_AI_INPUT_MESSAGES_ORIGINAL_LENGTH_ATTRIBUTE,
67
GEN_AI_REQUEST_AVAILABLE_TOOLS_ATTRIBUTE,
78
GEN_AI_REQUEST_MAX_TOKENS_ATTRIBUTE,
@@ -41,6 +42,7 @@ describe('Google GenAI integration', () => {
4142
expect(firstSpan!.name).toBe('chat gemini-1.5-pro');
4243
expect(firstSpan!.status).toBe('ok');
4344
expect(firstSpan!.attributes['sentry.op'].value).toBe('gen_ai.chat');
45+
expect(firstSpan!.attributes[GEN_AI_OPERATION_NAME_ATTRIBUTE].value).toBe('chat');
4446
expect(firstSpan!.attributes['sentry.origin'].value).toBe('auto.ai.google_genai');
4547
expect(firstSpan!.attributes[GEN_AI_SYSTEM_ATTRIBUTE].value).toBe('google_genai');
4648
expect(firstSpan!.attributes[GEN_AI_REQUEST_MODEL_ATTRIBUTE].value).toBe('gemini-1.5-pro');
@@ -52,6 +54,7 @@ describe('Google GenAI integration', () => {
5254
expect(secondSpan!.name).toBe('generate_content gemini-1.5-flash');
5355
expect(secondSpan!.status).toBe('ok');
5456
expect(secondSpan!.attributes['sentry.op'].value).toBe('gen_ai.generate_content');
57+
expect(secondSpan!.attributes[GEN_AI_OPERATION_NAME_ATTRIBUTE].value).toBe('generate_content');
5558
expect(secondSpan!.attributes[GEN_AI_SYSTEM_ATTRIBUTE].value).toBe('google_genai');
5659
expect(secondSpan!.attributes[GEN_AI_REQUEST_MODEL_ATTRIBUTE].value).toBe('gemini-1.5-flash');
5760
expect(secondSpan!.attributes[GEN_AI_REQUEST_TEMPERATURE_ATTRIBUTE].value).toBe(0.7);
@@ -65,6 +68,7 @@ describe('Google GenAI integration', () => {
6568
expect(thirdSpan!.name).toBe('generate_content error-model');
6669
expect(thirdSpan!.status).toBe('error');
6770
expect(thirdSpan!.attributes['sentry.op'].value).toBe('gen_ai.generate_content');
71+
expect(thirdSpan!.attributes[GEN_AI_OPERATION_NAME_ATTRIBUTE].value).toBe('generate_content');
6872
expect(thirdSpan!.attributes[GEN_AI_SYSTEM_ATTRIBUTE].value).toBe('google_genai');
6973
expect(thirdSpan!.attributes[GEN_AI_REQUEST_MODEL_ATTRIBUTE].value).toBe('error-model');
7074
},
@@ -88,6 +92,7 @@ describe('Google GenAI integration', () => {
8892
expect(firstSpan!.name).toBe('chat gemini-1.5-pro');
8993
expect(firstSpan!.status).toBe('ok');
9094
expect(firstSpan!.attributes['sentry.op'].value).toBe('gen_ai.chat');
95+
expect(firstSpan!.attributes[GEN_AI_OPERATION_NAME_ATTRIBUTE].value).toBe('chat');
9196
expect(firstSpan!.attributes[GEN_AI_SYSTEM_ATTRIBUTE].value).toBe('google_genai');
9297
expect(firstSpan!.attributes[GEN_AI_REQUEST_MODEL_ATTRIBUTE].value).toBe('gemini-1.5-pro');
9398
expect(firstSpan!.attributes[GEN_AI_INPUT_MESSAGES_ATTRIBUTE]).toBeDefined();
@@ -100,6 +105,7 @@ describe('Google GenAI integration', () => {
100105
expect(secondSpan!.name).toBe('generate_content gemini-1.5-flash');
101106
expect(secondSpan!.status).toBe('ok');
102107
expect(secondSpan!.attributes['sentry.op'].value).toBe('gen_ai.generate_content');
108+
expect(secondSpan!.attributes[GEN_AI_OPERATION_NAME_ATTRIBUTE].value).toBe('generate_content');
103109
expect(secondSpan!.attributes[GEN_AI_INPUT_MESSAGES_ATTRIBUTE]).toBeDefined();
104110
expect(secondSpan!.attributes[GEN_AI_RESPONSE_TEXT_ATTRIBUTE]).toBeDefined();
105111
expect(secondSpan!.attributes[GEN_AI_REQUEST_TEMPERATURE_ATTRIBUTE].value).toBe(0.7);
@@ -110,6 +116,7 @@ describe('Google GenAI integration', () => {
110116
expect(thirdSpan!.name).toBe('generate_content error-model');
111117
expect(thirdSpan!.status).toBe('error');
112118
expect(thirdSpan!.attributes['sentry.op'].value).toBe('gen_ai.generate_content');
119+
expect(thirdSpan!.attributes[GEN_AI_OPERATION_NAME_ATTRIBUTE].value).toBe('generate_content');
113120
expect(thirdSpan!.attributes[GEN_AI_INPUT_MESSAGES_ATTRIBUTE]).toBeDefined();
114121
},
115122
})
@@ -130,14 +137,17 @@ describe('Google GenAI integration', () => {
130137

131138
// [0] chat.sendMessage with custom options (PII enabled via recordInputs/recordOutputs)
132139
expect(firstSpan!.name).toBe('chat gemini-1.5-pro');
140+
expect(firstSpan!.attributes[GEN_AI_OPERATION_NAME_ATTRIBUTE].value).toBe('chat');
133141
expect(firstSpan!.attributes[GEN_AI_INPUT_MESSAGES_ATTRIBUTE]).toBeDefined();
134142
expect(firstSpan!.attributes[GEN_AI_RESPONSE_TEXT_ATTRIBUTE]).toBeDefined();
135143

136144
// [1] models.generateContent with custom options
137145
expect(secondSpan!.name).toBe('generate_content gemini-1.5-flash');
146+
expect(secondSpan!.attributes[GEN_AI_OPERATION_NAME_ATTRIBUTE].value).toBe('generate_content');
138147

139148
// [2] error handling with custom options
140149
expect(thirdSpan!.name).toBe('generate_content error-model');
150+
expect(thirdSpan!.attributes[GEN_AI_OPERATION_NAME_ATTRIBUTE].value).toBe('generate_content');
141151
},
142152
})
143153
.start()
@@ -161,6 +171,7 @@ describe('Google GenAI integration', () => {
161171
// [0] Non-streaming with tools
162172
expect(firstSpan!.name).toBe('generate_content gemini-2.0-flash-001');
163173
expect(firstSpan!.status).toBe('ok');
174+
expect(firstSpan!.attributes[GEN_AI_OPERATION_NAME_ATTRIBUTE].value).toBe('generate_content');
164175
expect(firstSpan!.attributes[GEN_AI_REQUEST_AVAILABLE_TOOLS_ATTRIBUTE].value).toBe(
165176
EXPECTED_AVAILABLE_TOOLS_JSON,
166177
);
@@ -175,6 +186,7 @@ describe('Google GenAI integration', () => {
175186
// [1] Streaming with tools
176187
expect(secondSpan!.name).toBe('generate_content gemini-2.0-flash-001');
177188
expect(secondSpan!.status).toBe('ok');
189+
expect(secondSpan!.attributes[GEN_AI_OPERATION_NAME_ATTRIBUTE].value).toBe('generate_content');
178190
expect(secondSpan!.attributes[GEN_AI_REQUEST_AVAILABLE_TOOLS_ATTRIBUTE].value).toBe(
179191
EXPECTED_AVAILABLE_TOOLS_JSON,
180192
);
@@ -191,6 +203,7 @@ describe('Google GenAI integration', () => {
191203
// [2] Without tools for comparison
192204
expect(thirdSpan!.name).toBe('generate_content gemini-2.0-flash-001');
193205
expect(thirdSpan!.status).toBe('ok');
206+
expect(thirdSpan!.attributes[GEN_AI_OPERATION_NAME_ATTRIBUTE].value).toBe('generate_content');
194207
expect(thirdSpan!.attributes[GEN_AI_REQUEST_AVAILABLE_TOOLS_ATTRIBUTE]).toBeUndefined();
195208
expect(thirdSpan!.attributes[GEN_AI_INPUT_MESSAGES_ATTRIBUTE]).toBeDefined();
196209
expect(thirdSpan!.attributes[GEN_AI_RESPONSE_TEXT_ATTRIBUTE]).toBeDefined();
@@ -217,6 +230,7 @@ describe('Google GenAI integration', () => {
217230
// [0] models.generateContentStream (streaming)
218231
expect(firstSpan!.name).toBe('generate_content gemini-1.5-flash');
219232
expect(firstSpan!.status).toBe('ok');
233+
expect(firstSpan!.attributes[GEN_AI_OPERATION_NAME_ATTRIBUTE].value).toBe('generate_content');
220234
expect(firstSpan!.attributes[GEN_AI_RESPONSE_STREAMING_ATTRIBUTE].value).toBe(true);
221235
expect(firstSpan!.attributes[GEN_AI_REQUEST_TEMPERATURE_ATTRIBUTE].value).toBe(0.7);
222236
expect(firstSpan!.attributes[GEN_AI_REQUEST_TOP_P_ATTRIBUTE].value).toBe(0.9);
@@ -231,6 +245,7 @@ describe('Google GenAI integration', () => {
231245
// [1] chat.sendMessageStream (streaming)
232246
expect(secondSpan!.name).toBe('chat gemini-1.5-pro');
233247
expect(secondSpan!.status).toBe('ok');
248+
expect(secondSpan!.attributes[GEN_AI_OPERATION_NAME_ATTRIBUTE].value).toBe('chat');
234249
expect(secondSpan!.attributes[GEN_AI_RESPONSE_STREAMING_ATTRIBUTE].value).toBe(true);
235250
expect(secondSpan!.attributes[GEN_AI_RESPONSE_ID_ATTRIBUTE].value).toBe('mock-response-streaming-id');
236251
expect(secondSpan!.attributes[GEN_AI_RESPONSE_MODEL_ATTRIBUTE].value).toBe('gemini-1.5-pro');
@@ -239,11 +254,13 @@ describe('Google GenAI integration', () => {
239254
expect(thirdSpan!.name).toBe('generate_content blocked-model');
240255
expect(thirdSpan!.status).toBe('error');
241256
expect(thirdSpan!.attributes['sentry.op'].value).toBe('gen_ai.generate_content');
257+
expect(thirdSpan!.attributes[GEN_AI_OPERATION_NAME_ATTRIBUTE].value).toBe('generate_content');
242258

243259
// [3] error handling for streaming
244260
expect(fourthSpan!.name).toBe('generate_content error-model');
245261
expect(fourthSpan!.status).toBe('error');
246262
expect(fourthSpan!.attributes['sentry.op'].value).toBe('gen_ai.generate_content');
263+
expect(fourthSpan!.attributes[GEN_AI_OPERATION_NAME_ATTRIBUTE].value).toBe('generate_content');
247264
},
248265
})
249266
.start()
@@ -264,6 +281,7 @@ describe('Google GenAI integration', () => {
264281
// [0] models.generateContentStream (streaming) with PII
265282
expect(firstSpan!.name).toBe('generate_content gemini-1.5-flash');
266283
expect(firstSpan!.status).toBe('ok');
284+
expect(firstSpan!.attributes[GEN_AI_OPERATION_NAME_ATTRIBUTE].value).toBe('generate_content');
267285
expect(firstSpan!.attributes[GEN_AI_RESPONSE_STREAMING_ATTRIBUTE].value).toBe(true);
268286
expect(firstSpan!.attributes[GEN_AI_INPUT_MESSAGES_ATTRIBUTE]).toBeDefined();
269287
expect(firstSpan!.attributes[GEN_AI_REQUEST_TEMPERATURE_ATTRIBUTE].value).toBe(0.7);
@@ -274,20 +292,23 @@ describe('Google GenAI integration', () => {
274292
// [1] chat.sendMessageStream (streaming) with PII
275293
expect(secondSpan!.name).toBe('chat gemini-1.5-pro');
276294
expect(secondSpan!.status).toBe('ok');
295+
expect(secondSpan!.attributes[GEN_AI_OPERATION_NAME_ATTRIBUTE].value).toBe('chat');
277296
expect(secondSpan!.attributes[GEN_AI_RESPONSE_STREAMING_ATTRIBUTE].value).toBe(true);
278297
expect(secondSpan!.attributes[GEN_AI_INPUT_MESSAGES_ATTRIBUTE]).toBeDefined();
279298
expect(secondSpan!.attributes[GEN_AI_RESPONSE_FINISH_REASONS_ATTRIBUTE].value).toBe('["STOP"]');
280299

281300
// [2] blocked content stream with PII
282301
expect(thirdSpan!.name).toBe('generate_content blocked-model');
283302
expect(thirdSpan!.status).toBe('error');
303+
expect(thirdSpan!.attributes[GEN_AI_OPERATION_NAME_ATTRIBUTE].value).toBe('generate_content');
284304
expect(thirdSpan!.attributes[GEN_AI_RESPONSE_STREAMING_ATTRIBUTE].value).toBe(true);
285305
expect(thirdSpan!.attributes[GEN_AI_INPUT_MESSAGES_ATTRIBUTE]).toBeDefined();
286306
expect(thirdSpan!.attributes[GEN_AI_REQUEST_TEMPERATURE_ATTRIBUTE].value).toBe(0.7);
287307

288308
// [3] error handling for streaming with PII
289309
expect(fourthSpan!.name).toBe('generate_content error-model');
290310
expect(fourthSpan!.status).toBe('error');
311+
expect(fourthSpan!.attributes[GEN_AI_OPERATION_NAME_ATTRIBUTE].value).toBe('generate_content');
291312
expect(fourthSpan!.attributes[GEN_AI_REQUEST_TEMPERATURE_ATTRIBUTE].value).toBe(0.7);
292313
expect(fourthSpan!.attributes[GEN_AI_INPUT_MESSAGES_ATTRIBUTE]).toBeDefined();
293314
},
@@ -314,6 +335,7 @@ describe('Google GenAI integration', () => {
314335
// [0] First call: Last message is large and gets truncated (only C's remain, D's are cropped)
315336
expect(firstSpan!.name).toBe('generate_content gemini-1.5-flash');
316337
expect(firstSpan!.status).toBe('ok');
338+
expect(firstSpan!.attributes[GEN_AI_OPERATION_NAME_ATTRIBUTE].value).toBe('generate_content');
317339
expect(firstSpan!.attributes[GEN_AI_INPUT_MESSAGES_ORIGINAL_LENGTH_ATTRIBUTE].value).toBe(3);
318340
expect(firstSpan!.attributes[GEN_AI_INPUT_MESSAGES_ATTRIBUTE].value).toMatch(
319341
/^\[\{"role":"user","parts":\[\{"text":"C+"\}\]\}\]$/,
@@ -322,6 +344,7 @@ describe('Google GenAI integration', () => {
322344
// [1] Second call: Last message is small and kept without truncation
323345
expect(secondSpan!.name).toBe('generate_content gemini-1.5-flash');
324346
expect(secondSpan!.status).toBe('ok');
347+
expect(secondSpan!.attributes[GEN_AI_OPERATION_NAME_ATTRIBUTE].value).toBe('generate_content');
325348
expect(secondSpan!.attributes[GEN_AI_INPUT_MESSAGES_ORIGINAL_LENGTH_ATTRIBUTE].value).toBe(3);
326349
expect(secondSpan!.attributes[GEN_AI_INPUT_MESSAGES_ATTRIBUTE].value).toBe(
327350
JSON.stringify([
@@ -355,6 +378,7 @@ describe('Google GenAI integration', () => {
355378

356379
// [0] generate_content with system instructions extracted
357380
expect(firstSpan!.name).toBe('generate_content gemini-1.5-flash');
381+
expect(firstSpan!.attributes[GEN_AI_OPERATION_NAME_ATTRIBUTE].value).toBe('generate_content');
358382
expect(firstSpan!.attributes[GEN_AI_SYSTEM_INSTRUCTIONS_ATTRIBUTE].value).toBe(
359383
JSON.stringify([{ type: 'text', content: 'You are a helpful assistant' }]),
360384
);
@@ -380,6 +404,7 @@ describe('Google GenAI integration', () => {
380404
expect(firstSpan!.name).toBe('embeddings text-embedding-004');
381405
expect(firstSpan!.status).toBe('ok');
382406
expect(firstSpan!.attributes['sentry.op'].value).toBe('gen_ai.embeddings');
407+
expect(firstSpan!.attributes[GEN_AI_OPERATION_NAME_ATTRIBUTE].value).toBe('embeddings');
383408
expect(firstSpan!.attributes['sentry.origin'].value).toBe('auto.ai.google_genai');
384409
expect(firstSpan!.attributes[GEN_AI_SYSTEM_ATTRIBUTE].value).toBe('google_genai');
385410
expect(firstSpan!.attributes[GEN_AI_REQUEST_MODEL_ATTRIBUTE].value).toBe('text-embedding-004');
@@ -389,11 +414,13 @@ describe('Google GenAI integration', () => {
389414
expect(secondSpan!.name).toBe('embeddings error-model');
390415
expect(secondSpan!.status).toBe('error');
391416
expect(secondSpan!.attributes['sentry.op'].value).toBe('gen_ai.embeddings');
417+
expect(secondSpan!.attributes[GEN_AI_OPERATION_NAME_ATTRIBUTE].value).toBe('embeddings');
392418

393419
// [2] embedContent with array contents (no PII)
394420
expect(thirdSpan!.name).toBe('embeddings text-embedding-004');
395421
expect(thirdSpan!.status).toBe('ok');
396422
expect(thirdSpan!.attributes['sentry.op'].value).toBe('gen_ai.embeddings');
423+
expect(thirdSpan!.attributes[GEN_AI_OPERATION_NAME_ATTRIBUTE].value).toBe('embeddings');
397424
},
398425
})
399426
.start()
@@ -414,6 +441,7 @@ describe('Google GenAI integration', () => {
414441
// [0] embedContent with string contents and PII
415442
expect(firstSpan!.name).toBe('embeddings text-embedding-004');
416443
expect(firstSpan!.status).toBe('ok');
444+
expect(firstSpan!.attributes[GEN_AI_OPERATION_NAME_ATTRIBUTE].value).toBe('embeddings');
417445
expect(firstSpan!.attributes[GEN_AI_SYSTEM_ATTRIBUTE].value).toBe('google_genai');
418446
expect(firstSpan!.attributes[GEN_AI_EMBEDDINGS_INPUT_ATTRIBUTE].value).toBe(
419447
'What is the capital of France?',
@@ -422,11 +450,13 @@ describe('Google GenAI integration', () => {
422450
// [1] embedContent error model with PII
423451
expect(secondSpan!.name).toBe('embeddings error-model');
424452
expect(secondSpan!.status).toBe('error');
453+
expect(secondSpan!.attributes[GEN_AI_OPERATION_NAME_ATTRIBUTE].value).toBe('embeddings');
425454
expect(secondSpan!.attributes[GEN_AI_EMBEDDINGS_INPUT_ATTRIBUTE].value).toBe('This will fail');
426455

427456
// [2] embedContent with array contents and PII
428457
expect(thirdSpan!.name).toBe('embeddings text-embedding-004');
429458
expect(thirdSpan!.status).toBe('ok');
459+
expect(thirdSpan!.attributes[GEN_AI_OPERATION_NAME_ATTRIBUTE].value).toBe('embeddings');
430460
expect(thirdSpan!.attributes[GEN_AI_EMBEDDINGS_INPUT_ATTRIBUTE].value).toBe(
431461
'[{"role":"user","parts":[{"text":"First input text"}]},{"role":"user","parts":[{"text":"Second input text"}]}]',
432462
);
@@ -454,6 +484,7 @@ describe('Google GenAI integration', () => {
454484
const [firstSpan] = container.items;
455485

456486
// [0] generate_content with full (non-truncated) input messages
487+
expect(firstSpan!.attributes[GEN_AI_OPERATION_NAME_ATTRIBUTE].value).toBe('generate_content');
457488
expect(firstSpan!.attributes[GEN_AI_INPUT_MESSAGES_ATTRIBUTE].value).toBe(
458489
JSON.stringify([
459490
{ role: 'user', parts: [{ text: longContent }] },

0 commit comments

Comments
 (0)