@@ -322,32 +322,23 @@ function patchModelMethod(
322322 }
323323 } ;
324324
325- let result : Promise < unknown > ;
326325 try {
327- result = Promise . resolve ( original . apply ( this , args ) ) ;
326+ const result = Promise . resolve ( original . apply ( this , args ) ) ;
327+ // `doStream` resolves to `{ stream, ... }` before the stream is consumed; we end here (start/end
328+ // bracket the call) to match the channel timing.
329+ return result . then ( value => {
330+ message . result = value ;
331+ enrichSpanOnEnd ( span , message , options ) ;
332+ span . end ( ) ;
333+ clearStreamCallId ( ) ;
334+ return value ;
335+ } ) ;
328336 } catch ( error ) {
329337 span . setStatus ( { code : SPAN_STATUS_ERROR , message : error instanceof Error ? error . message : 'unknown_error' } ) ;
330338 span . end ( ) ;
331339 clearStreamCallId ( ) ;
332340 throw error ;
333341 }
334- // `doStream` resolves to `{ stream, ... }` before the stream is consumed; we end here (start/end
335- // bracket the call) to match the channel timing.
336- return result . then (
337- value => {
338- message . result = value ;
339- enrichSpanOnEnd ( span , message , options ) ;
340- span . end ( ) ;
341- clearStreamCallId ( ) ;
342- return value ;
343- } ,
344- error => {
345- span . setStatus ( { code : SPAN_STATUS_ERROR , message : error instanceof Error ? error . message : 'unknown_error' } ) ;
346- span . end ( ) ;
347- clearStreamCallId ( ) ;
348- throw error ;
349- } ,
350- ) ;
351342 } ;
352343}
353344
@@ -356,7 +347,7 @@ function buildTextMessage(type: 'generateText' | 'streamText'): MessageBuilder {
356347 type,
357348 event : {
358349 callId : nextCallId ( ) ,
359- operationId : type === 'streamText' ? ' ai.streamText' : 'ai.generateText' ,
350+ operationId : ` ai.${ type } ` ,
360351 functionId : asString ( telemetry . functionId ) ,
361352 ...modelFields ( options . model ) ,
362353 maxRetries : options . maxRetries ,
0 commit comments