@@ -787,18 +787,16 @@ describe("AI SDK Transformations", () => {
787787 } ) ;
788788
789789 describe ( "transformAiSdkAttributes - prompt tokens" , ( ) => {
790- it ( "should transform ai.usage.promptTokens to LLM usage attribute " , ( ) => {
790+ it ( "should delete ai.usage.promptTokens and gen_ai. usage.prompt_tokens (keep input_tokens) " , ( ) => {
791791 const attributes = {
792792 "ai.usage.promptTokens" : 50 ,
793+ "gen_ai.usage.input_tokens" : 50 ,
793794 someOtherAttr : "value" ,
794795 } ;
795796
796797 transformLLMSpans ( attributes ) ;
797798
798- assert . strictEqual (
799- attributes [ SpanAttributes . LLM_USAGE_PROMPT_TOKENS ] ,
800- 50 ,
801- ) ;
799+ assert . strictEqual ( attributes [ SpanAttributes . LLM_USAGE_INPUT_TOKENS ] , 50 ) ;
802800 assert . strictEqual ( attributes [ "ai.usage.promptTokens" ] , undefined ) ;
803801 assert . strictEqual ( attributes . someOtherAttr , "value" ) ;
804802 } ) ;
@@ -814,28 +812,31 @@ describe("AI SDK Transformations", () => {
814812 assert . deepStrictEqual ( attributes , originalAttributes ) ;
815813 } ) ;
816814
817- it ( "should handle zero prompt tokens" , ( ) => {
815+ it ( "should handle zero input tokens" , ( ) => {
818816 const attributes = {
819817 "ai.usage.promptTokens" : 0 ,
818+ "gen_ai.usage.input_tokens" : 0 ,
820819 } ;
821820
822821 transformLLMSpans ( attributes ) ;
823822
824- assert . strictEqual ( attributes [ SpanAttributes . LLM_USAGE_PROMPT_TOKENS ] , 0 ) ;
823+ assert . strictEqual ( attributes [ SpanAttributes . LLM_USAGE_INPUT_TOKENS ] , 0 ) ;
824+ assert . strictEqual ( attributes [ "ai.usage.promptTokens" ] , undefined ) ;
825825 } ) ;
826826 } ) ;
827827
828828 describe ( "transformAiSdkAttributes - completion tokens" , ( ) => {
829- it ( "should transform ai.usage.completionTokens to LLM usage attribute " , ( ) => {
829+ it ( "should delete ai.usage.completionTokens and gen_ai. usage.completion_tokens (keep output_tokens) " , ( ) => {
830830 const attributes = {
831831 "ai.usage.completionTokens" : 25 ,
832+ "gen_ai.usage.output_tokens" : 25 ,
832833 someOtherAttr : "value" ,
833834 } ;
834835
835836 transformLLMSpans ( attributes ) ;
836837
837838 assert . strictEqual (
838- attributes [ SpanAttributes . LLM_USAGE_COMPLETION_TOKENS ] ,
839+ attributes [ SpanAttributes . LLM_USAGE_OUTPUT_TOKENS ] ,
839840 25 ,
840841 ) ;
841842 assert . strictEqual ( attributes [ "ai.usage.completionTokens" ] , undefined ) ;
@@ -853,25 +854,24 @@ describe("AI SDK Transformations", () => {
853854 assert . deepStrictEqual ( attributes , originalAttributes ) ;
854855 } ) ;
855856
856- it ( "should handle zero completion tokens" , ( ) => {
857+ it ( "should handle zero output tokens" , ( ) => {
857858 const attributes = {
858859 "ai.usage.completionTokens" : 0 ,
860+ "gen_ai.usage.output_tokens" : 0 ,
859861 } ;
860862
861863 transformLLMSpans ( attributes ) ;
862864
863- assert . strictEqual (
864- attributes [ SpanAttributes . LLM_USAGE_COMPLETION_TOKENS ] ,
865- 0 ,
866- ) ;
865+ assert . strictEqual ( attributes [ SpanAttributes . LLM_USAGE_OUTPUT_TOKENS ] , 0 ) ;
866+ assert . strictEqual ( attributes [ "ai.usage.completionTokens" ] , undefined ) ;
867867 } ) ;
868868 } ) ;
869869
870870 describe ( "transformAiSdkAttributes - total tokens calculation" , ( ) => {
871- it ( "should calculate total tokens from prompt and completion tokens" , ( ) => {
871+ it ( "should calculate total tokens from input and output tokens" , ( ) => {
872872 const attributes = {
873- [ SpanAttributes . LLM_USAGE_PROMPT_TOKENS ] : 50 ,
874- [ SpanAttributes . LLM_USAGE_COMPLETION_TOKENS ] : 25 ,
873+ [ SpanAttributes . LLM_USAGE_INPUT_TOKENS ] : 50 ,
874+ [ SpanAttributes . LLM_USAGE_OUTPUT_TOKENS ] : 25 ,
875875 } ;
876876
877877 transformLLMSpans ( attributes ) ;
@@ -881,18 +881,18 @@ describe("AI SDK Transformations", () => {
881881
882882 it ( "should handle string token values" , ( ) => {
883883 const attributes = {
884- [ SpanAttributes . LLM_USAGE_PROMPT_TOKENS ] : "50" ,
885- [ SpanAttributes . LLM_USAGE_COMPLETION_TOKENS ] : "25" ,
884+ [ SpanAttributes . LLM_USAGE_INPUT_TOKENS ] : "50" ,
885+ [ SpanAttributes . LLM_USAGE_OUTPUT_TOKENS ] : "25" ,
886886 } ;
887887
888888 transformLLMSpans ( attributes ) ;
889889
890890 assert . strictEqual ( attributes [ SpanAttributes . LLM_USAGE_TOTAL_TOKENS ] , 75 ) ;
891891 } ) ;
892892
893- it ( "should not calculate total when prompt tokens are missing" , ( ) => {
893+ it ( "should not calculate total when input tokens are missing" , ( ) => {
894894 const attributes = {
895- [ SpanAttributes . LLM_USAGE_COMPLETION_TOKENS ] : 25 ,
895+ [ SpanAttributes . LLM_USAGE_OUTPUT_TOKENS ] : 25 ,
896896 } ;
897897
898898 transformLLMSpans ( attributes ) ;
@@ -903,9 +903,9 @@ describe("AI SDK Transformations", () => {
903903 ) ;
904904 } ) ;
905905
906- it ( "should not calculate total when completion tokens are missing" , ( ) => {
906+ it ( "should not calculate total when output tokens are missing" , ( ) => {
907907 const attributes = {
908- [ SpanAttributes . LLM_USAGE_PROMPT_TOKENS ] : 50 ,
908+ [ SpanAttributes . LLM_USAGE_INPUT_TOKENS ] : 50 ,
909909 } ;
910910
911911 transformLLMSpans ( attributes ) ;
@@ -1017,6 +1017,8 @@ describe("AI SDK Transformations", () => {
10171017 "ai.prompt.messages" : JSON . stringify ( [ { role : "user" , content : "Hi" } ] ) ,
10181018 "ai.usage.promptTokens" : 10 ,
10191019 "ai.usage.completionTokens" : 5 ,
1020+ "gen_ai.usage.input_tokens" : 10 ,
1021+ "gen_ai.usage.output_tokens" : 5 ,
10201022 "ai.model.provider" : "openai.chat" ,
10211023 someOtherAttr : "value" ,
10221024 } ;
@@ -1043,15 +1045,9 @@ describe("AI SDK Transformations", () => {
10431045 "user" ,
10441046 ) ;
10451047
1046- // Check token transformations
1047- assert . strictEqual (
1048- attributes [ SpanAttributes . LLM_USAGE_PROMPT_TOKENS ] ,
1049- 10 ,
1050- ) ;
1051- assert . strictEqual (
1052- attributes [ SpanAttributes . LLM_USAGE_COMPLETION_TOKENS ] ,
1053- 5 ,
1054- ) ;
1048+ // Check token transformations - should keep input/output tokens
1049+ assert . strictEqual ( attributes [ SpanAttributes . LLM_USAGE_INPUT_TOKENS ] , 10 ) ;
1050+ assert . strictEqual ( attributes [ SpanAttributes . LLM_USAGE_OUTPUT_TOKENS ] , 5 ) ;
10551051 assert . strictEqual ( attributes [ SpanAttributes . LLM_USAGE_TOTAL_TOKENS ] , 15 ) ;
10561052
10571053 // Check vendor transformation
@@ -1062,6 +1058,14 @@ describe("AI SDK Transformations", () => {
10621058 assert . strictEqual ( attributes [ "ai.prompt.messages" ] , undefined ) ;
10631059 assert . strictEqual ( attributes [ "ai.usage.promptTokens" ] , undefined ) ;
10641060 assert . strictEqual ( attributes [ "ai.usage.completionTokens" ] , undefined ) ;
1061+ assert . strictEqual (
1062+ attributes [ SpanAttributes . LLM_USAGE_PROMPT_TOKENS ] ,
1063+ undefined ,
1064+ ) ;
1065+ assert . strictEqual (
1066+ attributes [ SpanAttributes . LLM_USAGE_COMPLETION_TOKENS ] ,
1067+ undefined ,
1068+ ) ;
10651069 assert . strictEqual ( attributes [ "ai.model.provider" ] , undefined ) ;
10661070
10671071 // Check other attributes are preserved
@@ -1089,6 +1093,8 @@ describe("AI SDK Transformations", () => {
10891093 "ai.prompt.messages" : JSON . stringify ( [ { role : "user" , content : "Hi" } ] ) ,
10901094 "ai.usage.promptTokens" : 10 ,
10911095 "ai.usage.completionTokens" : 5 ,
1096+ "gen_ai.usage.input_tokens" : 10 ,
1097+ "gen_ai.usage.output_tokens" : 5 ,
10921098 "ai.model.provider" : "azure-openai.chat" ,
10931099 someOtherAttr : "value" ,
10941100 } ;
@@ -1115,15 +1121,9 @@ describe("AI SDK Transformations", () => {
11151121 "user" ,
11161122 ) ;
11171123
1118- // Check token transformations
1119- assert . strictEqual (
1120- attributes [ SpanAttributes . LLM_USAGE_PROMPT_TOKENS ] ,
1121- 10 ,
1122- ) ;
1123- assert . strictEqual (
1124- attributes [ SpanAttributes . LLM_USAGE_COMPLETION_TOKENS ] ,
1125- 5 ,
1126- ) ;
1124+ // Check token transformations - should keep input/output tokens
1125+ assert . strictEqual ( attributes [ SpanAttributes . LLM_USAGE_INPUT_TOKENS ] , 10 ) ;
1126+ assert . strictEqual ( attributes [ SpanAttributes . LLM_USAGE_OUTPUT_TOKENS ] , 5 ) ;
11271127 assert . strictEqual ( attributes [ SpanAttributes . LLM_USAGE_TOTAL_TOKENS ] , 15 ) ;
11281128
11291129 // Check vendor transformation
@@ -1134,6 +1134,14 @@ describe("AI SDK Transformations", () => {
11341134 assert . strictEqual ( attributes [ "ai.prompt.messages" ] , undefined ) ;
11351135 assert . strictEqual ( attributes [ "ai.usage.promptTokens" ] , undefined ) ;
11361136 assert . strictEqual ( attributes [ "ai.usage.completionTokens" ] , undefined ) ;
1137+ assert . strictEqual (
1138+ attributes [ SpanAttributes . LLM_USAGE_PROMPT_TOKENS ] ,
1139+ undefined ,
1140+ ) ;
1141+ assert . strictEqual (
1142+ attributes [ SpanAttributes . LLM_USAGE_COMPLETION_TOKENS ] ,
1143+ undefined ,
1144+ ) ;
11371145 assert . strictEqual ( attributes [ "ai.model.provider" ] , undefined ) ;
11381146
11391147 // Check other attributes are preserved
0 commit comments