@@ -175,6 +175,7 @@ export class ChatMLFetcherImpl extends AbstractChatMLFetcher {
175175
176176 const baseTelemetry = TelemetryData . createAndMarkAsIssued ( {
177177 ...telemetryProperties ,
178+ headerRequestId : ourRequestId ,
178179 baseModel : chatEndpoint . model ,
179180 uiKind : ChatLocation . toString ( location )
180181 } ) ;
@@ -1086,6 +1087,8 @@ export class ChatMLFetcherImpl extends AbstractChatMLFetcher {
10861087 } ) ;
10871088
10881089 const modelRequestId = getRequestId ( connection . responseHeaders ) ;
1090+ // Preserve ourRequestId as headerRequestId if the server didn't echo x-request-id
1091+ modelRequestId . headerRequestId = modelRequestId . headerRequestId || ourRequestId ;
10891092 telemetryData . extendWithRequestId ( modelRequestId ) ;
10901093
10911094 for ( const [ key , value ] of Object . entries ( request ) ) {
@@ -1094,8 +1097,6 @@ export class ChatMLFetcherImpl extends AbstractChatMLFetcher {
10941097 } // Skip messages (PII)
10951098 telemetryData . properties [ `request.option.${ key } ` ] = JSON . stringify ( value ) ?? 'undefined' ;
10961099 }
1097-
1098- telemetryData . properties [ 'headerRequestId' ] = ourRequestId ;
10991100 this . _telemetryService . sendGHTelemetryEvent ( 'request.sent' , telemetryData . properties , telemetryData . measurements ) ;
11001101
11011102 const requestStart = Date . now ( ) ;
@@ -1396,6 +1397,8 @@ export class ChatMLFetcherImpl extends AbstractChatMLFetcher {
13961397 // This ID is hopefully the one the same as ourRequestId, but it is not guaranteed.
13971398 // If they are different then we will override the original one we set in telemetryData above.
13981399 const modelRequestId = getRequestId ( response . headers ) ;
1400+ // Preserve ourRequestId as headerRequestId if the server didn't echo x-request-id
1401+ modelRequestId . headerRequestId = modelRequestId . headerRequestId || ourRequestId ;
13991402 telemetryData . extendWithRequestId ( modelRequestId ) ;
14001403
14011404 // TODO: Add response length (requires parsing)
0 commit comments