@@ -4,10 +4,10 @@ import type { Event } from '../../types-hoist/event';
44import type { Span , SpanAttributes , SpanAttributeValue , SpanJSON , SpanOrigin } from '../../types-hoist/span' ;
55import { spanToJSON } from '../../utils/spanUtils' ;
66import {
7+ GEN_AI_REQUEST_MESSAGES_ATTRIBUTE ,
78 GEN_AI_USAGE_INPUT_TOKENS_CACHE_WRITE_ATTRIBUTE ,
89 GEN_AI_USAGE_INPUT_TOKENS_CACHED_ATTRIBUTE ,
910} from '../ai/gen-ai-attributes' ;
10- import { getTruncatedJsonString } from '../ai/utils' ;
1111import { toolCallSpanMap } from './constants' ;
1212import type { TokenSummary } from './types' ;
1313import {
@@ -20,7 +20,6 @@ import type { ProviderMetadata } from './vercel-ai-attributes';
2020import {
2121 AI_MODEL_ID_ATTRIBUTE ,
2222 AI_MODEL_PROVIDER_ATTRIBUTE ,
23- AI_PROMPT_ATTRIBUTE ,
2423 AI_PROMPT_MESSAGES_ATTRIBUTE ,
2524 AI_PROMPT_TOOLS_ATTRIBUTE ,
2625 AI_RESPONSE_OBJECT_ATTRIBUTE ,
@@ -36,6 +35,7 @@ import {
3635 AI_USAGE_CACHED_INPUT_TOKENS_ATTRIBUTE ,
3736 AI_USAGE_COMPLETION_TOKENS_ATTRIBUTE ,
3837 AI_USAGE_PROMPT_TOKENS_ATTRIBUTE ,
38+ GEN_AI_REQUEST_MODEL_ATTRIBUTE ,
3939 GEN_AI_RESPONSE_MODEL_ATTRIBUTE ,
4040 GEN_AI_USAGE_INPUT_TOKENS_ATTRIBUTE ,
4141 GEN_AI_USAGE_OUTPUT_TOKENS_ATTRIBUTE ,
@@ -136,7 +136,7 @@ function processEndedVercelAiSpan(span: SpanJSON): void {
136136 }
137137
138138 // Rename AI SDK attributes to standardized gen_ai attributes
139- renameAttributeKey ( attributes , AI_PROMPT_MESSAGES_ATTRIBUTE , 'gen_ai.request.messages' ) ;
139+ renameAttributeKey ( attributes , AI_PROMPT_MESSAGES_ATTRIBUTE , GEN_AI_REQUEST_MESSAGES_ATTRIBUTE ) ;
140140 renameAttributeKey ( attributes , AI_RESPONSE_TEXT_ATTRIBUTE , 'gen_ai.response.text' ) ;
141141 renameAttributeKey ( attributes , AI_RESPONSE_TOOL_CALLS_ATTRIBUTE , 'gen_ai.response.tool_calls' ) ;
142142 renameAttributeKey ( attributes , AI_RESPONSE_OBJECT_ATTRIBUTE , 'gen_ai.response.object' ) ;
@@ -146,7 +146,7 @@ function processEndedVercelAiSpan(span: SpanJSON): void {
146146 renameAttributeKey ( attributes , AI_TOOL_CALL_RESULT_ATTRIBUTE , 'gen_ai.tool.output' ) ;
147147
148148 renameAttributeKey ( attributes , AI_SCHEMA_ATTRIBUTE , 'gen_ai.request.schema' ) ;
149- renameAttributeKey ( attributes , AI_MODEL_ID_ATTRIBUTE , 'gen_ai.request.model' ) ;
149+ renameAttributeKey ( attributes , AI_MODEL_ID_ATTRIBUTE , GEN_AI_REQUEST_MODEL_ATTRIBUTE ) ;
150150
151151 addProviderMetadataToAttributes ( attributes ) ;
152152
@@ -209,14 +209,8 @@ function processGenerateSpan(span: Span, name: string, attributes: SpanAttribute
209209 span . setAttribute ( 'gen_ai.function_id' , functionId ) ;
210210 }
211211
212- if ( attributes [ AI_PROMPT_ATTRIBUTE ] ) {
213- const truncatedPrompt = getTruncatedJsonString ( attributes [ AI_PROMPT_ATTRIBUTE ] as string | string [ ] ) ;
214- span . setAttribute ( 'gen_ai.prompt' , truncatedPrompt ) ;
212+ requestMessagesFromPrompt ( span , attributes ) ;
215213
216- if ( ! attributes [ 'gen_ai.request.messages' ] && ! attributes [ AI_PROMPT_MESSAGES_ATTRIBUTE ] ) {
217- requestMessagesFromPrompt ( span , attributes [ AI_PROMPT_ATTRIBUTE ] ) ;
218- }
219- }
220214 if ( attributes [ AI_MODEL_ID_ATTRIBUTE ] && ! attributes [ GEN_AI_RESPONSE_MODEL_ATTRIBUTE ] ) {
221215 span . setAttribute ( GEN_AI_RESPONSE_MODEL_ATTRIBUTE , attributes [ AI_MODEL_ID_ATTRIBUTE ] ) ;
222216 }
0 commit comments