Skip to content

Commit 8f8785f

Browse files
committed
prittier
1 parent 5a75921 commit 8f8785f

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

packages/traceloop-sdk/src/lib/tracing/ai-sdk-transformations.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -322,8 +322,12 @@ const transformPrompts = (attributes: Record<string, any>): void => {
322322

323323
const transformPromptTokens = (attributes: Record<string, any>): void => {
324324
// Make sure we have the right naming convention
325-
if (!(SpanAttributes.LLM_USAGE_INPUT_TOKENS in attributes) && AI_USAGE_PROMPT_TOKENS in attributes) {
326-
attributes[SpanAttributes.LLM_USAGE_INPUT_TOKENS] = attributes[AI_USAGE_PROMPT_TOKENS];
325+
if (
326+
!(SpanAttributes.LLM_USAGE_INPUT_TOKENS in attributes) &&
327+
AI_USAGE_PROMPT_TOKENS in attributes
328+
) {
329+
attributes[SpanAttributes.LLM_USAGE_INPUT_TOKENS] =
330+
attributes[AI_USAGE_PROMPT_TOKENS];
327331
}
328332

329333
// Clean up legacy attributes
@@ -333,8 +337,12 @@ const transformPromptTokens = (attributes: Record<string, any>): void => {
333337

334338
const transformCompletionTokens = (attributes: Record<string, any>): void => {
335339
// Make sure we have the right naming convention
336-
if (!(SpanAttributes.LLM_USAGE_OUTPUT_TOKENS in attributes) && AI_USAGE_COMPLETION_TOKENS in attributes) {
337-
attributes[SpanAttributes.LLM_USAGE_OUTPUT_TOKENS] = attributes[AI_USAGE_COMPLETION_TOKENS];
340+
if (
341+
!(SpanAttributes.LLM_USAGE_OUTPUT_TOKENS in attributes) &&
342+
AI_USAGE_COMPLETION_TOKENS in attributes
343+
) {
344+
attributes[SpanAttributes.LLM_USAGE_OUTPUT_TOKENS] =
345+
attributes[AI_USAGE_COMPLETION_TOKENS];
338346
}
339347

340348
// Clean up legacy attributes

0 commit comments

Comments
 (0)