Skip to content

Commit 8528f24

Browse files
committed
less comments
1 parent 671117b commit 8528f24

File tree

1 file changed

+0
-17
lines changed

1 file changed

+0
-17
lines changed

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

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -310,8 +310,6 @@ const transformPrompts = (attributes: Record<string, any>): void => {
310310
if (AI_PROMPT in attributes) {
311311
try {
312312
const promptData = JSON.parse(attributes[AI_PROMPT] as string);
313-
314-
// Handle case where promptData has a "messages" array
315313
if (promptData.messages && Array.isArray(promptData.messages)) {
316314
const messages = promptData.messages;
317315
const inputMessages: any[] = [];
@@ -324,7 +322,6 @@ const transformPrompts = (attributes: Record<string, any>): void => {
324322
attributes[`${SpanAttributes.ATTR_GEN_AI_PROMPT}.${index}.role`] =
325323
msg.role;
326324

327-
// Add to OpenTelemetry standard gen_ai.input.messages format
328325
inputMessages.push({
329326
role: msg.role,
330327
parts: [
@@ -337,15 +334,13 @@ const transformPrompts = (attributes: Record<string, any>): void => {
337334
},
338335
);
339336

340-
// Set the OpenTelemetry standard input messages attribute
341337
if (inputMessages.length > 0) {
342338
attributes[SpanAttributes.ATTR_GEN_AI_INPUT_MESSAGES] =
343339
JSON.stringify(inputMessages);
344340
}
345341

346342
delete attributes[AI_PROMPT];
347343
}
348-
// Handle case where promptData has a "prompt" string
349344
else if (promptData.prompt && typeof promptData.prompt === "string") {
350345
attributes[`${SpanAttributes.ATTR_GEN_AI_PROMPT}.0.content`] =
351346
promptData.prompt;
@@ -373,7 +368,6 @@ const transformPrompts = (attributes: Record<string, any>): void => {
373368
};
374369

375370
const transformPromptTokens = (attributes: Record<string, any>): void => {
376-
// Make sure we have the right naming convention
377371
if (
378372
!(SpanAttributes.ATTR_GEN_AI_USAGE_PROMPT_TOKENS in attributes) &&
379373
AI_USAGE_PROMPT_TOKENS in attributes
@@ -382,13 +376,11 @@ const transformPromptTokens = (attributes: Record<string, any>): void => {
382376
attributes[AI_USAGE_PROMPT_TOKENS];
383377
}
384378

385-
// Clean up legacy attributes
386379
delete attributes[AI_USAGE_PROMPT_TOKENS];
387380
delete attributes[SpanAttributes.ATTR_GEN_AI_USAGE_PROMPT_TOKENS];
388381
};
389382

390383
const transformCompletionTokens = (attributes: Record<string, any>): void => {
391-
// Make sure we have the right naming convention
392384
if (
393385
!(SpanAttributes.ATTR_GEN_AI_USAGE_OUTPUT_TOKENS in attributes) &&
394386
AI_USAGE_COMPLETION_TOKENS in attributes
@@ -397,7 +389,6 @@ const transformCompletionTokens = (attributes: Record<string, any>): void => {
397389
attributes[AI_USAGE_COMPLETION_TOKENS];
398390
}
399391

400-
// Clean up legacy attributes
401392
delete attributes[AI_USAGE_COMPLETION_TOKENS];
402393
delete attributes[SpanAttributes.ATTR_GEN_AI_USAGE_COMPLETION_TOKENS];
403394
};
@@ -465,10 +456,8 @@ const transformVendor = (attributes: Record<string, any>): void => {
465456
if (AI_MODEL_PROVIDER in attributes) {
466457
const vendor = attributes[AI_MODEL_PROVIDER];
467458

468-
// Find matching vendor prefix in mapping
469459
let mappedVendor = null;
470460
if (typeof vendor === "string" && vendor.length > 0) {
471-
// Extract base provider name for OpenTelemetry standard (e.g., "openai" from "openai.chat")
472461
const providerName = vendor.split(".")[0];
473462
attributes[SpanAttributes.ATTR_GEN_AI_PROVIDER_NAME] = providerName;
474463

@@ -520,7 +509,6 @@ const transformFinishReason = (attributes: Record<string, any>): void => {
520509
const AI_RESPONSE_FINISH_REASON = "ai.response.finishReason";
521510
if (AI_RESPONSE_FINISH_REASON in attributes) {
522511
const finishReason = attributes[AI_RESPONSE_FINISH_REASON];
523-
// Convert to array format for OTel standard
524512
attributes[SpanAttributes.ATTR_GEN_AI_RESPONSE_FINISH_REASONS] = Array.isArray(
525513
finishReason,
526514
)
@@ -531,28 +519,24 @@ const transformFinishReason = (attributes: Record<string, any>): void => {
531519
};
532520

533521
const transformToolCallAttributes = (attributes: Record<string, any>): void => {
534-
// Transform tool name
535522
if ("ai.toolCall.name" in attributes) {
536523
attributes[SpanAttributes.ATTR_GEN_AI_TOOL_NAME] =
537524
attributes["ai.toolCall.name"];
538525
// Keep ai.toolCall.name for now, will be deleted in transformToolCalls
539526
}
540527

541-
// Transform tool call ID
542528
if ("ai.toolCall.id" in attributes) {
543529
attributes[SpanAttributes.ATTR_GEN_AI_TOOL_CALL_ID] =
544530
attributes["ai.toolCall.id"];
545531
delete attributes["ai.toolCall.id"];
546532
}
547533

548-
// Transform tool arguments (keep both OTel and Traceloop versions)
549534
if ("ai.toolCall.args" in attributes) {
550535
attributes[SpanAttributes.ATTR_GEN_AI_TOOL_CALL_ARGUMENTS] =
551536
attributes["ai.toolCall.args"];
552537
// Don't delete yet - transformToolCalls will handle entity input/output
553538
}
554539

555-
// Transform tool result (keep both OTel and Traceloop versions)
556540
if ("ai.toolCall.result" in attributes) {
557541
attributes[SpanAttributes.ATTR_GEN_AI_TOOL_CALL_RESULT] =
558542
attributes["ai.toolCall.result"];
@@ -561,7 +545,6 @@ const transformToolCallAttributes = (attributes: Record<string, any>): void => {
561545
};
562546

563547
const transformConversationId = (attributes: Record<string, any>): void => {
564-
// Check for conversation/session ID in metadata
565548
const conversationId = attributes["ai.telemetry.metadata.conversationId"];
566549
const sessionId = attributes["ai.telemetry.metadata.sessionId"];
567550

0 commit comments

Comments
 (0)