Skip to content

Commit ef152a9

Browse files
authored
fix: add entity input/output to agent spans (#840)
1 parent 389987a commit ef152a9

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,27 @@ const transformTelemetryMetadata = (
492492
attributes[SpanAttributes.TRACELOOP_SPAN_KIND] =
493493
TraceloopSpanKindValues.AGENT;
494494
attributes[SpanAttributes.TRACELOOP_ENTITY_NAME] = agentName;
495+
496+
const inputMessages = attributes[SpanAttributes.LLM_INPUT_MESSAGES];
497+
const outputMessages = attributes[SpanAttributes.LLM_OUTPUT_MESSAGES];
498+
const toolArgs = attributes["ai.toolCall.args"];
499+
const toolResult = attributes["ai.toolCall.result"];
500+
501+
if (inputMessages || outputMessages) {
502+
if (inputMessages) {
503+
attributes[SpanAttributes.TRACELOOP_ENTITY_INPUT] = inputMessages;
504+
}
505+
if (outputMessages) {
506+
attributes[SpanAttributes.TRACELOOP_ENTITY_OUTPUT] = outputMessages;
507+
}
508+
} else if (toolArgs || toolResult) {
509+
if (toolArgs) {
510+
attributes[SpanAttributes.TRACELOOP_ENTITY_INPUT] = toolArgs;
511+
}
512+
if (toolResult) {
513+
attributes[SpanAttributes.TRACELOOP_ENTITY_OUTPUT] = toolResult;
514+
}
515+
}
495516
}
496517
}
497518

0 commit comments

Comments
 (0)