@@ -29,52 +29,83 @@ it('traces Google GenAI chat creation and message sending', async ({ signal }) =
2929 const container = envelope [ 1 ] ?. [ 1 ] ?. [ 1 ] as any ;
3030 expect ( container ) . toBeDefined ( ) ;
3131 expect ( container . items ) . toHaveLength ( 3 ) ;
32- const [ firstSpan , secondSpan , thirdSpan ] = container . items ;
32+ expect ( container . items . map ( span => span . name ) . sort ( ) ) . toEqual ( [
33+ 'chat gemini-1.5-pro' ,
34+ 'embeddings text-embedding-004' ,
35+ 'generate_content gemini-1.5-flash' ,
36+ ] ) ;
3337
34- // [0] chat gemini-1.5-pro
35- expect ( firstSpan ! . name ) . toBe ( 'chat gemini-1.5-pro' ) ;
36- expect ( firstSpan ! . status ) . toBe ( 'ok' ) ;
37- expect ( firstSpan ! . attributes [ GEN_AI_OPERATION_NAME_ATTRIBUTE ] ) . toEqual ( { type : 'string' , value : 'chat' } ) ;
38- expect ( firstSpan ! . attributes [ 'sentry.op' ] ) . toEqual ( { type : 'string' , value : 'gen_ai.chat' } ) ;
39- expect ( firstSpan ! . attributes [ 'sentry.origin' ] ) . toEqual ( { type : 'string' , value : 'auto.ai.google_genai' } ) ;
40- expect ( firstSpan ! . attributes [ GEN_AI_SYSTEM_ATTRIBUTE ] ) . toEqual ( { type : 'string' , value : 'google_genai' } ) ;
41- expect ( firstSpan ! . attributes [ GEN_AI_REQUEST_MODEL_ATTRIBUTE ] ) . toEqual ( {
38+ const chatSpan = container . items . find ( span => span . name === ' chat gemini-1.5-pro' ) ;
39+ expect ( chatSpan ) . toBeDefined ( ) ;
40+ expect ( chatSpan ! . status ) . toBe ( 'ok' ) ;
41+ expect ( chatSpan ! . attributes [ GEN_AI_OPERATION_NAME_ATTRIBUTE ] ) . toEqual ( { type : 'string' , value : 'chat' } ) ;
42+ expect ( chatSpan ! . attributes [ 'sentry.op' ] ) . toEqual ( { type : 'string' , value : 'gen_ai.chat' } ) ;
43+ expect ( chatSpan ! . attributes [ 'sentry.origin' ] ) . toEqual ( { type : 'string' , value : 'auto.ai.google_genai' } ) ;
44+ expect ( chatSpan ! . attributes [ GEN_AI_SYSTEM_ATTRIBUTE ] ) . toEqual ( { type : 'string' , value : 'google_genai' } ) ;
45+ expect ( chatSpan ! . attributes [ GEN_AI_REQUEST_MODEL_ATTRIBUTE ] ) . toEqual ( {
4246 type : 'string' ,
4347 value : 'gemini-1.5-pro' ,
4448 } ) ;
45- expect ( firstSpan ! . attributes [ GEN_AI_USAGE_INPUT_TOKENS_ATTRIBUTE ] ) . toEqual ( { type : 'integer' , value : 8 } ) ;
46- expect ( firstSpan ! . attributes [ GEN_AI_USAGE_OUTPUT_TOKENS_ATTRIBUTE ] ) . toEqual ( { type : 'integer' , value : 12 } ) ;
47- expect ( firstSpan ! . attributes [ GEN_AI_USAGE_TOTAL_TOKENS_ATTRIBUTE ] ) . toEqual ( { type : 'integer' , value : 20 } ) ;
49+ expect ( chatSpan ! . attributes [ GEN_AI_USAGE_INPUT_TOKENS_ATTRIBUTE ] ) . toEqual ( { type : 'integer' , value : 8 } ) ;
50+ expect ( chatSpan ! . attributes [ GEN_AI_USAGE_OUTPUT_TOKENS_ATTRIBUTE ] ) . toEqual ( { type : 'integer' , value : 12 } ) ;
51+ expect ( chatSpan ! . attributes [ GEN_AI_USAGE_TOTAL_TOKENS_ATTRIBUTE ] ) . toEqual ( { type : 'integer' , value : 20 } ) ;
4852
49- // [1] generate_content gemini-1.5-flash
50- expect ( secondSpan ! . name ) . toBe ( 'generate_content gemini-1.5-flash' ) ;
51- expect ( secondSpan ! . status ) . toBe ( 'ok' ) ;
52- expect ( secondSpan ! . attributes [ GEN_AI_OPERATION_NAME_ATTRIBUTE ] ) . toEqual ( {
53+ const generateContentSpan = container . items . find ( span => span . name === ' generate_content gemini-1.5-flash' ) ;
54+ expect ( generateContentSpan ) . toBeDefined ( ) ;
55+ expect ( generateContentSpan ! . status ) . toBe ( 'ok' ) ;
56+ expect ( generateContentSpan ! . attributes [ GEN_AI_OPERATION_NAME_ATTRIBUTE ] ) . toEqual ( {
5357 type : 'string' ,
5458 value : 'generate_content' ,
5559 } ) ;
56- expect ( secondSpan ! . attributes [ 'sentry.op' ] ) . toEqual ( { type : 'string' , value : 'gen_ai.generate_content' } ) ;
57- expect ( secondSpan ! . attributes [ 'sentry.origin' ] ) . toEqual ( { type : 'string' , value : 'auto.ai.google_genai' } ) ;
58- expect ( secondSpan ! . attributes [ GEN_AI_SYSTEM_ATTRIBUTE ] ) . toEqual ( { type : 'string' , value : 'google_genai' } ) ;
59- expect ( secondSpan ! . attributes [ GEN_AI_REQUEST_MODEL_ATTRIBUTE ] ) . toEqual ( {
60+ expect ( generateContentSpan ! . attributes [ 'sentry.op' ] ) . toEqual ( {
61+ type : 'string' ,
62+ value : 'gen_ai.generate_content' ,
63+ } ) ;
64+ expect ( generateContentSpan ! . attributes [ 'sentry.origin' ] ) . toEqual ( {
65+ type : 'string' ,
66+ value : 'auto.ai.google_genai' ,
67+ } ) ;
68+ expect ( generateContentSpan ! . attributes [ GEN_AI_SYSTEM_ATTRIBUTE ] ) . toEqual ( {
69+ type : 'string' ,
70+ value : 'google_genai' ,
71+ } ) ;
72+ expect ( generateContentSpan ! . attributes [ GEN_AI_REQUEST_MODEL_ATTRIBUTE ] ) . toEqual ( {
6073 type : 'string' ,
6174 value : 'gemini-1.5-flash' ,
6275 } ) ;
63- expect ( secondSpan ! . attributes [ GEN_AI_REQUEST_TEMPERATURE_ATTRIBUTE ] ) . toEqual ( { type : 'double' , value : 0.7 } ) ;
64- expect ( secondSpan ! . attributes [ GEN_AI_REQUEST_TOP_P_ATTRIBUTE ] ) . toEqual ( { type : 'double' , value : 0.9 } ) ;
65- expect ( secondSpan ! . attributes [ GEN_AI_REQUEST_MAX_TOKENS_ATTRIBUTE ] ) . toEqual ( { type : 'integer' , value : 100 } ) ;
66- expect ( secondSpan ! . attributes [ GEN_AI_USAGE_INPUT_TOKENS_ATTRIBUTE ] ) . toEqual ( { type : 'integer' , value : 8 } ) ;
67- expect ( secondSpan ! . attributes [ GEN_AI_USAGE_OUTPUT_TOKENS_ATTRIBUTE ] ) . toEqual ( { type : 'integer' , value : 12 } ) ;
68- expect ( secondSpan ! . attributes [ GEN_AI_USAGE_TOTAL_TOKENS_ATTRIBUTE ] ) . toEqual ( { type : 'integer' , value : 20 } ) ;
76+ expect ( generateContentSpan ! . attributes [ GEN_AI_REQUEST_TEMPERATURE_ATTRIBUTE ] ) . toEqual ( {
77+ type : 'double' ,
78+ value : 0.7 ,
79+ } ) ;
80+ expect ( generateContentSpan ! . attributes [ GEN_AI_REQUEST_TOP_P_ATTRIBUTE ] ) . toEqual ( { type : 'double' , value : 0.9 } ) ;
81+ expect ( generateContentSpan ! . attributes [ GEN_AI_REQUEST_MAX_TOKENS_ATTRIBUTE ] ) . toEqual ( {
82+ type : 'integer' ,
83+ value : 100 ,
84+ } ) ;
85+ expect ( generateContentSpan ! . attributes [ GEN_AI_USAGE_INPUT_TOKENS_ATTRIBUTE ] ) . toEqual ( {
86+ type : 'integer' ,
87+ value : 8 ,
88+ } ) ;
89+ expect ( generateContentSpan ! . attributes [ GEN_AI_USAGE_OUTPUT_TOKENS_ATTRIBUTE ] ) . toEqual ( {
90+ type : 'integer' ,
91+ value : 12 ,
92+ } ) ;
93+ expect ( generateContentSpan ! . attributes [ GEN_AI_USAGE_TOTAL_TOKENS_ATTRIBUTE ] ) . toEqual ( {
94+ type : 'integer' ,
95+ value : 20 ,
96+ } ) ;
6997
70- // [2] embeddings text-embedding-004
71- expect ( thirdSpan ! . name ) . toBe ( 'embeddings text-embedding-004' ) ;
72- expect ( thirdSpan ! . status ) . toBe ( 'ok' ) ;
73- expect ( thirdSpan ! . attributes [ GEN_AI_OPERATION_NAME_ATTRIBUTE ] ) . toEqual ( { type : 'string' , value : 'embeddings' } ) ;
74- expect ( thirdSpan ! . attributes [ 'sentry.op' ] ) . toEqual ( { type : 'string' , value : 'gen_ai.embeddings' } ) ;
75- expect ( thirdSpan ! . attributes [ 'sentry.origin' ] ) . toEqual ( { type : 'string' , value : 'auto.ai.google_genai' } ) ;
76- expect ( thirdSpan ! . attributes [ GEN_AI_SYSTEM_ATTRIBUTE ] ) . toEqual ( { type : 'string' , value : 'google_genai' } ) ;
77- expect ( thirdSpan ! . attributes [ GEN_AI_REQUEST_MODEL_ATTRIBUTE ] ) . toEqual ( {
98+ const embeddingsSpan = container . items . find ( span => span . name === 'embeddings text-embedding-004' ) ;
99+ expect ( embeddingsSpan ) . toBeDefined ( ) ;
100+ expect ( embeddingsSpan ! . status ) . toBe ( 'ok' ) ;
101+ expect ( embeddingsSpan ! . attributes [ GEN_AI_OPERATION_NAME_ATTRIBUTE ] ) . toEqual ( {
102+ type : 'string' ,
103+ value : 'embeddings' ,
104+ } ) ;
105+ expect ( embeddingsSpan ! . attributes [ 'sentry.op' ] ) . toEqual ( { type : 'string' , value : 'gen_ai.embeddings' } ) ;
106+ expect ( embeddingsSpan ! . attributes [ 'sentry.origin' ] ) . toEqual ( { type : 'string' , value : 'auto.ai.google_genai' } ) ;
107+ expect ( embeddingsSpan ! . attributes [ GEN_AI_SYSTEM_ATTRIBUTE ] ) . toEqual ( { type : 'string' , value : 'google_genai' } ) ;
108+ expect ( embeddingsSpan ! . attributes [ GEN_AI_REQUEST_MODEL_ATTRIBUTE ] ) . toEqual ( {
78109 type : 'string' ,
79110 value : 'text-embedding-004' ,
80111 } ) ;
0 commit comments