@@ -318,41 +318,25 @@ const transformPrompts = (attributes: Record<string, any>): void => {
318318} ;
319319
320320const transformPromptTokens = ( attributes : Record < string , any > ) : void => {
321- if ( SpanAttributes . LLM_USAGE_INPUT_TOKENS in attributes ) {
322- // Already has input_tokens, delete legacy duplicates
323- if ( AI_USAGE_PROMPT_TOKENS in attributes ) {
324- delete attributes [ AI_USAGE_PROMPT_TOKENS ] ;
325- }
326- if ( SpanAttributes . LLM_USAGE_PROMPT_TOKENS in attributes ) {
327- delete attributes [ SpanAttributes . LLM_USAGE_PROMPT_TOKENS ] ;
328- }
329- } else {
330- // Transform legacy promptTokens to modern input_tokens
331- if ( AI_USAGE_PROMPT_TOKENS in attributes ) {
332- attributes [ SpanAttributes . LLM_USAGE_INPUT_TOKENS ] =
333- attributes [ AI_USAGE_PROMPT_TOKENS ] ;
334- delete attributes [ AI_USAGE_PROMPT_TOKENS ] ;
335- }
321+ // Make sure we have the right naming convention
322+ if ( ! ( SpanAttributes . LLM_USAGE_INPUT_TOKENS in attributes ) && AI_USAGE_PROMPT_TOKENS in attributes ) {
323+ attributes [ SpanAttributes . LLM_USAGE_INPUT_TOKENS ] = attributes [ AI_USAGE_PROMPT_TOKENS ] ;
336324 }
325+
326+ // Clean up legacy attributes
327+ delete attributes [ AI_USAGE_PROMPT_TOKENS ] ;
328+ delete attributes [ SpanAttributes . LLM_USAGE_PROMPT_TOKENS ] ;
337329} ;
338330
339331const transformCompletionTokens = ( attributes : Record < string , any > ) : void => {
340- if ( SpanAttributes . LLM_USAGE_OUTPUT_TOKENS in attributes ) {
341- // Already has output_tokens, delete legacy duplicates
342- if ( AI_USAGE_COMPLETION_TOKENS in attributes ) {
343- delete attributes [ AI_USAGE_COMPLETION_TOKENS ] ;
344- }
345- if ( SpanAttributes . LLM_USAGE_COMPLETION_TOKENS in attributes ) {
346- delete attributes [ SpanAttributes . LLM_USAGE_COMPLETION_TOKENS ] ;
347- }
348- } else {
349- // Transform legacy completionTokens to modern output_tokens
350- if ( AI_USAGE_COMPLETION_TOKENS in attributes ) {
351- attributes [ SpanAttributes . LLM_USAGE_OUTPUT_TOKENS ] =
352- attributes [ AI_USAGE_COMPLETION_TOKENS ] ;
353- delete attributes [ AI_USAGE_COMPLETION_TOKENS ] ;
354- }
332+ // Make sure we have the right naming convention
333+ if ( ! ( SpanAttributes . LLM_USAGE_OUTPUT_TOKENS in attributes ) && AI_USAGE_COMPLETION_TOKENS in attributes ) {
334+ attributes [ SpanAttributes . LLM_USAGE_OUTPUT_TOKENS ] = attributes [ AI_USAGE_COMPLETION_TOKENS ] ;
355335 }
336+
337+ // Clean up legacy attributes
338+ delete attributes [ AI_USAGE_COMPLETION_TOKENS ] ;
339+ delete attributes [ SpanAttributes . LLM_USAGE_COMPLETION_TOKENS ] ;
356340} ;
357341
358342const calculateTotalTokens = ( attributes : Record < string , any > ) : void => {
0 commit comments