Skip to content

Commit a8a1618

Browse files
committed
refactor: use helper function in both places for agent extraction
Previously, both transformTelemetryMetadata and transformAiSdkSpanNames had their own logic to extract agent name from ai.telemetry.metadata.agent attributes. This consolidates both to use the shared getAgentNameFromAttributes helper, eliminating code duplication. Addresses PR feedback about existing agent extraction code.
1 parent 15c7824 commit a8a1618

File tree

1 file changed

+2
-6
lines changed

1 file changed

+2
-6
lines changed

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,8 @@ const transformTelemetryMetadata = (
433433
): void => {
434434
const metadataAttributes: Record<string, string> = {};
435435
const keysToDelete: string[] = [];
436-
let agentName: string | null = null;
436+
// Use the helper function to extract agent name
437+
const agentName = getAgentNameFromAttributes(attributes);
437438

438439
// Find all ai.telemetry.metadata.* attributes
439440
for (const [key, value] of Object.entries(attributes)) {
@@ -448,11 +449,6 @@ const transformTelemetryMetadata = (
448449
const stringValue = typeof value === "string" ? value : String(value);
449450
metadataAttributes[metadataKey] = stringValue;
450451

451-
// Check for agent-specific metadata
452-
if (metadataKey === "agent") {
453-
agentName = stringValue;
454-
}
455-
456452
// Also set as traceloop association property attribute
457453
attributes[
458454
`${SpanAttributes.TRACELOOP_ASSOCIATION_PROPERTIES}.${metadataKey}`

0 commit comments

Comments
 (0)