@@ -44,12 +44,6 @@ describe.each([
4444 // else, we use the OTel processor
4545 const expectedOrigin = usesChannels ? 'auto.vercelai.channel' : 'auto.vercelai.otel' ;
4646
47- // Streamed model-call spans get usage/finish/output on every path. The parent invoke_agent span only
48- // gets the streamed aggregate where the operation span outlives the stream: the OTel path (v6, native
49- // spans) and the v7 channel (asyncEnd deferred on total usage). In v6 orchestrion the operation span
50- // ends synchronously when `streamText` returns, before the stream drains, so it can't be enriched.
51- const enrichesInvokeAgentForStream = ! ( version === '6' && isOrchestrionEnabled ( ) ) ;
52-
5347 // We only run this in ESM and CJS to verify full support
5448 // Other suites we only run in ESM to simplify the test setup
5549 createEsmAndCjsTests (
@@ -628,16 +622,14 @@ describe.each([
628622 '[{"role":"assistant","parts":[{"type":"text","content":"Stream response!"}],"finish_reason":"stop"}]' ,
629623 ) ;
630624
631- // The summed usage and output also land on the parent invoke_agent span, except where its
632- // span ends before the stream drains (see `enrichesInvokeAgentForStream`).
633- if ( enrichesInvokeAgentForStream ) {
634- expect ( invokeAgent . attributes ?. [ GEN_AI_USAGE_INPUT_TOKENS_ATTRIBUTE ] ?. value ) . toBe ( 10 ) ;
635- expect ( invokeAgent . attributes ?. [ GEN_AI_USAGE_OUTPUT_TOKENS_ATTRIBUTE ] ?. value ) . toBe ( 20 ) ;
636- expect ( invokeAgent . attributes ?. [ GEN_AI_USAGE_TOTAL_TOKENS_ATTRIBUTE ] ?. value ) . toBe ( 30 ) ;
637- expect ( invokeAgent . attributes ?. [ GEN_AI_OUTPUT_MESSAGES_ATTRIBUTE ] ?. value ) . toBe (
638- '[{"role":"assistant","parts":[{"type":"text","content":"Stream response!"}],"finish_reason":"stop"}]' ,
639- ) ;
640- }
625+ // The summed usage and output also land on the parent invoke_agent span, whose own
626+ // channel result is otherwise undefined for a stream.
627+ expect ( invokeAgent . attributes ?. [ GEN_AI_USAGE_INPUT_TOKENS_ATTRIBUTE ] ?. value ) . toBe ( 10 ) ;
628+ expect ( invokeAgent . attributes ?. [ GEN_AI_USAGE_OUTPUT_TOKENS_ATTRIBUTE ] ?. value ) . toBe ( 20 ) ;
629+ expect ( invokeAgent . attributes ?. [ GEN_AI_USAGE_TOTAL_TOKENS_ATTRIBUTE ] ?. value ) . toBe ( 30 ) ;
630+ expect ( invokeAgent . attributes ?. [ GEN_AI_OUTPUT_MESSAGES_ATTRIBUTE ] ?. value ) . toBe (
631+ '[{"role":"assistant","parts":[{"type":"text","content":"Stream response!"}],"finish_reason":"stop"}]' ,
632+ ) ;
641633 } ,
642634 } )
643635 . start ( )
@@ -672,11 +664,9 @@ describe.each([
672664 expect ( invokeAgent . status ) . toBe ( 'ok' ) ;
673665 expect ( invokeAgent . attributes ?. [ 'vercel.ai.operationId' ] ?. value ) . toBe ( 'ai.streamText' ) ;
674666 // Usage is summed across the two streamed model calls (10+15, 20+25, 30+40).
675- if ( enrichesInvokeAgentForStream ) {
676- expect ( invokeAgent . attributes ?. [ GEN_AI_USAGE_INPUT_TOKENS_ATTRIBUTE ] ?. value ) . toBe ( 25 ) ;
677- expect ( invokeAgent . attributes ?. [ GEN_AI_USAGE_OUTPUT_TOKENS_ATTRIBUTE ] ?. value ) . toBe ( 45 ) ;
678- expect ( invokeAgent . attributes ?. [ GEN_AI_USAGE_TOTAL_TOKENS_ATTRIBUTE ] ?. value ) . toBe ( 70 ) ;
679- }
667+ expect ( invokeAgent . attributes ?. [ GEN_AI_USAGE_INPUT_TOKENS_ATTRIBUTE ] ?. value ) . toBe ( 25 ) ;
668+ expect ( invokeAgent . attributes ?. [ GEN_AI_USAGE_OUTPUT_TOKENS_ATTRIBUTE ] ?. value ) . toBe ( 45 ) ;
669+ expect ( invokeAgent . attributes ?. [ GEN_AI_USAGE_TOTAL_TOKENS_ATTRIBUTE ] ?. value ) . toBe ( 70 ) ;
680670
681671 const generateContents = container . items . filter (
682672 span => span . attributes ?. [ 'sentry.op' ] ?. value === 'gen_ai.generate_content' ,
@@ -743,9 +733,7 @@ describe.each([
743733 expect ( invokeAgent ) . toBeDefined ( ) ;
744734 expect ( invokeAgent . status ) . toBe ( 'ok' ) ;
745735 expect ( invokeAgent . attributes ?. [ 'vercel.ai.operationId' ] ?. value ) . toBe ( 'ai.streamText' ) ;
746- if ( enrichesInvokeAgentForStream ) {
747- expect ( invokeAgent . attributes ?. [ GEN_AI_USAGE_TOTAL_TOKENS_ATTRIBUTE ] ?. value ) . toBe ( 30 ) ;
748- }
736+ expect ( invokeAgent . attributes ?. [ GEN_AI_USAGE_TOTAL_TOKENS_ATTRIBUTE ] ?. value ) . toBe ( 30 ) ;
749737
750738 const generateContent = container . items . find (
751739 span => span . attributes ?. [ 'sentry.op' ] ?. value === 'gen_ai.generate_content' ,
0 commit comments