Skip to content

Commit 4047a13

Browse files
committed
pretty:
1 parent ab0580a commit 4047a13

File tree

2 files changed

+27
-24
lines changed

2 files changed

+27
-24
lines changed

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

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -316,23 +316,26 @@ const transformPrompts = (attributes: Record<string, any>): void => {
316316
const messages = promptData.messages;
317317
const inputMessages: any[] = [];
318318

319-
messages.forEach((msg: { role: string; content: any }, index: number) => {
320-
const processedContent = processMessageContent(msg.content);
321-
const contentKey = `${SpanAttributes.LLM_PROMPTS}.${index}.content`;
322-
attributes[contentKey] = processedContent;
323-
attributes[`${SpanAttributes.LLM_PROMPTS}.${index}.role`] = msg.role;
324-
325-
// Add to OpenTelemetry standard gen_ai.input.messages format
326-
inputMessages.push({
327-
role: msg.role,
328-
parts: [
329-
{
330-
type: TYPE_TEXT,
331-
content: processedContent,
332-
},
333-
],
334-
});
335-
});
319+
messages.forEach(
320+
(msg: { role: string; content: any }, index: number) => {
321+
const processedContent = processMessageContent(msg.content);
322+
const contentKey = `${SpanAttributes.LLM_PROMPTS}.${index}.content`;
323+
attributes[contentKey] = processedContent;
324+
attributes[`${SpanAttributes.LLM_PROMPTS}.${index}.role`] =
325+
msg.role;
326+
327+
// Add to OpenTelemetry standard gen_ai.input.messages format
328+
inputMessages.push({
329+
role: msg.role,
330+
parts: [
331+
{
332+
type: TYPE_TEXT,
333+
content: processedContent,
334+
},
335+
],
336+
});
337+
},
338+
);
336339

337340
// Set the OpenTelemetry standard input messages attribute
338341
if (inputMessages.length > 0) {
@@ -527,9 +530,7 @@ const transformFinishReason = (attributes: Record<string, any>): void => {
527530
}
528531
};
529532

530-
const transformToolCallAttributes = (
531-
attributes: Record<string, any>,
532-
): void => {
533+
const transformToolCallAttributes = (attributes: Record<string, any>): void => {
533534
// Transform tool name
534535
if ("ai.toolCall.name" in attributes) {
535536
attributes[SpanAttributes.GEN_AI_TOOL_NAME] =
@@ -704,6 +705,7 @@ const transformToolCalls = (span: ReadableSpan): void => {
704705
const toolName = span.attributes["ai.toolCall.name"];
705706
if (toolName) {
706707
span.attributes[SpanAttributes.TRACELOOP_ENTITY_NAME] = toolName;
708+
delete span.attributes["ai.toolCall.name"];
707709
}
708710
}
709711
};

packages/traceloop-sdk/test/ai-sdk-transformations.test.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2301,7 +2301,10 @@ describe("AI SDK Transformations", () => {
23012301

23022302
transformLLMSpans(attributes);
23032303

2304-
assert.strictEqual(attributes[SpanAttributes.GEN_AI_TOOL_NAME], undefined);
2304+
assert.strictEqual(
2305+
attributes[SpanAttributes.GEN_AI_TOOL_NAME],
2306+
undefined,
2307+
);
23052308
assert.strictEqual(
23062309
attributes[SpanAttributes.GEN_AI_TOOL_CALL_ID],
23072310
undefined,
@@ -2500,9 +2503,7 @@ describe("AI SDK Transformations", () => {
25002503

25012504
// Check metadata transformation
25022505
assert.strictEqual(
2503-
attributes[
2504-
`${SpanAttributes.TRACELOOP_ASSOCIATION_PROPERTIES}.userId`
2505-
],
2506+
attributes[`${SpanAttributes.TRACELOOP_ASSOCIATION_PROPERTIES}.userId`],
25062507
"user_789",
25072508
);
25082509
});

0 commit comments

Comments
 (0)