@@ -16,6 +16,7 @@ import {
1616 GEN_AI_REQUEST_TEMPERATURE_ATTRIBUTE ,
1717 GEN_AI_REQUEST_TOP_K_ATTRIBUTE ,
1818 GEN_AI_REQUEST_TOP_P_ATTRIBUTE ,
19+ GEN_AI_RESPONSE_MODEL_ATTRIBUTE ,
1920 GEN_AI_RESPONSE_TEXT_ATTRIBUTE ,
2021 GEN_AI_RESPONSE_TOOL_CALLS_ATTRIBUTE ,
2122 GEN_AI_SYSTEM_ATTRIBUTE ,
@@ -134,27 +135,48 @@ function extractRequestAttributes(
134135 * Handles different parameter formats for different Google GenAI methods.
135136 */
136137function addPrivateRequestAttributes ( span : Span , params : Record < string , unknown > ) : void {
138+ const messages : { role : 'system' | 'user' ; content : string | string [ ] } [ ] = [ ] ;
139+
140+ // include system prompt if present in config param
141+ if (
142+ 'config' in params &&
143+ params . config &&
144+ typeof params . config === 'object' &&
145+ 'systemInstruction' in params . config
146+ ) {
147+ const content = params . config . systemInstruction as string | string [ ] ;
148+ messages . push ( { role : 'system' , content } ) ;
149+ }
150+
137151 // For models.generateContent: ContentListUnion: Content | Content[] | PartUnion | PartUnion[]
138152 if ( 'contents' in params ) {
139- const contents = params . contents ;
140153 // For models.generateContent: ContentListUnion: Content | Content[] | PartUnion | PartUnion[]
141- const truncatedContents = getTruncatedJsonString ( contents ) ;
142- span . setAttributes ( { [ GEN_AI_REQUEST_MESSAGES_ATTRIBUTE ] : truncatedContents } ) ;
154+ messages . push ( {
155+ role : 'user' ,
156+ content : getTruncatedJsonString ( params . contents ) ,
157+ } ) ;
143158 }
144159
145160 // For chat.sendMessage: message can be string or Part[]
146161 if ( 'message' in params ) {
147- const message = params . message ;
148- const truncatedMessage = getTruncatedJsonString ( message ) ;
149- span . setAttributes ( { [ GEN_AI_REQUEST_MESSAGES_ATTRIBUTE ] : truncatedMessage } ) ;
162+ messages . push ( {
163+ role : 'user' ,
164+ content : getTruncatedJsonString ( params . message ) ,
165+ } ) ;
150166 }
151167
152168 // For chats.create: history contains the conversation history
153169 if ( 'history' in params ) {
154- const history = params . history ;
155- const truncatedHistory = getTruncatedJsonString ( history ) ;
156- span . setAttributes ( { [ GEN_AI_REQUEST_MESSAGES_ATTRIBUTE ] : truncatedHistory } ) ;
170+ messages . push ( {
171+ role : 'user' ,
172+ content : getTruncatedJsonString ( params . history ) ,
173+ } ) ;
157174 }
175+
176+ span . setAttributes ( {
177+ [ GEN_AI_REQUEST_MESSAGES_ATTRIBUTE ] : JSON . stringify ( messages ) ,
178+ [ GEN_AI_RESPONSE_MODEL_ATTRIBUTE ] : String ( params . model ) ,
179+ } ) ;
158180}
159181
160182/**
0 commit comments