@@ -16,7 +16,7 @@ import {
1616 GEN_AI_USAGE_INPUT_TOKENS_ATTRIBUTE ,
1717 GEN_AI_USAGE_OUTPUT_TOKENS_ATTRIBUTE ,
1818} from '../ai/gen-ai-attributes' ;
19- import { extractSystemInstructions , getTruncatedJsonString } from '../ai/utils' ;
19+ import { extractSystemInstructions , getJsonString , getTruncatedJsonString } from '../ai/utils' ;
2020import { toolCallSpanContextMap } from './constants' ;
2121import type { TokenSummary , ToolCallSpanContext } from './types' ;
2222import { AI_PROMPT_ATTRIBUTE , AI_PROMPT_MESSAGES_ATTRIBUTE } from './vercel-ai-attributes' ;
@@ -227,7 +227,7 @@ export function convertUserInputToMessagesFormat(userInput: string): { role: str
227227 * Generate a request.messages JSON array from the prompt field in the
228228 * invoke_agent op
229229 */
230- export function requestMessagesFromPrompt ( span : Span , attributes : SpanAttributes ) : void {
230+ export function requestMessagesFromPrompt ( span : Span , attributes : SpanAttributes , enableTruncation : boolean ) : void {
231231 if (
232232 typeof attributes [ AI_PROMPT_ATTRIBUTE ] === 'string' &&
233233 ! attributes [ GEN_AI_INPUT_MESSAGES_ATTRIBUTE ] &&
@@ -247,11 +247,13 @@ export function requestMessagesFromPrompt(span: Span, attributes: SpanAttributes
247247 }
248248
249249 const filteredLength = Array . isArray ( filteredMessages ) ? filteredMessages . length : 0 ;
250- const truncatedMessages = getTruncatedJsonString ( filteredMessages ) ;
250+ const messagesJson = enableTruncation
251+ ? getTruncatedJsonString ( filteredMessages )
252+ : getJsonString ( filteredMessages ) ;
251253
252254 span . setAttributes ( {
253- [ AI_PROMPT_ATTRIBUTE ] : truncatedMessages ,
254- [ GEN_AI_INPUT_MESSAGES_ATTRIBUTE ] : truncatedMessages ,
255+ [ AI_PROMPT_ATTRIBUTE ] : messagesJson ,
256+ [ GEN_AI_INPUT_MESSAGES_ATTRIBUTE ] : messagesJson ,
255257 [ GEN_AI_INPUT_MESSAGES_ORIGINAL_LENGTH_ATTRIBUTE ] : filteredLength ,
256258 } ) ;
257259 }
@@ -268,11 +270,13 @@ export function requestMessagesFromPrompt(span: Span, attributes: SpanAttributes
268270 }
269271
270272 const filteredLength = Array . isArray ( filteredMessages ) ? filteredMessages . length : 0 ;
271- const truncatedMessages = getTruncatedJsonString ( filteredMessages ) ;
273+ const messagesJson = enableTruncation
274+ ? getTruncatedJsonString ( filteredMessages )
275+ : getJsonString ( filteredMessages ) ;
272276
273277 span . setAttributes ( {
274- [ AI_PROMPT_MESSAGES_ATTRIBUTE ] : truncatedMessages ,
275- [ GEN_AI_INPUT_MESSAGES_ATTRIBUTE ] : truncatedMessages ,
278+ [ AI_PROMPT_MESSAGES_ATTRIBUTE ] : messagesJson ,
279+ [ GEN_AI_INPUT_MESSAGES_ATTRIBUTE ] : messagesJson ,
276280 [ GEN_AI_INPUT_MESSAGES_ORIGINAL_LENGTH_ATTRIBUTE ] : filteredLength ,
277281 } ) ;
278282 }
0 commit comments