MCPcopy Create free account
hub / github.com/getsentry/sentry-javascript / getTruncatedJsonString

Function getTruncatedJsonString

packages/core/src/tracing/ai/utils.ts:211–223  ·  view source on GitHub ↗
(value: T | T[])

Source from the content-addressed store, hash-verified

209 * @returns The truncated JSON string
210 */
211export function getTruncatedJsonString<T>(value: T | T[]): string {
212 if (typeof value === 'string') {
213 // Some values are already JSON strings, so we don't need to duplicate the JSON parsing
214 return truncateGenAiStringInput(value);
215 }
216 if (Array.isArray(value)) {
217 // truncateGenAiMessages returns an array of strings, so we need to stringify it
218 const truncatedMessages = truncateGenAiMessages(value);
219 return JSON.stringify(truncatedMessages);
220 }
221 // value is an object, so we need to stringify it
222 return JSON.stringify(value);
223}
224
225/**
226 * Extract system instructions from messages array.

Callers 9

applyFunction · 0.90
addRequestAttributesFunction · 0.90
setMessagesAttributeFunction · 0.90

Calls 2

truncateGenAiStringInputFunction · 0.90
truncateGenAiMessagesFunction · 0.90

Tested by

no test coverage detected