Skip to content

Commit de72c86

Browse files
committed
fix(vercel-sdk): vendor names
1 parent d1badff commit de72c86

File tree

2 files changed

+36
-5
lines changed

2 files changed

+36
-5
lines changed

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

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,29 @@ const AI_USAGE_PROMPT_TOKENS = "ai.usage.promptTokens";
1414
const AI_USAGE_COMPLETION_TOKENS = "ai.usage.completionTokens";
1515
const AI_MODEL_PROVIDER = "ai.model.provider";
1616

17+
// Vendor mapping from AI SDK provider prefixes to standardized LLM_SYSTEM values
18+
// Uses prefixes to match AI SDK patterns like "openai.chat", "anthropic.messages", etc.
19+
const VENDOR_MAPPING: Record<string, string> = {
20+
"openai": "OpenAI",
21+
"anthropic": "Anthropic",
22+
"cohere": "Cohere",
23+
"mistral": "MistralAI",
24+
"groq": "Groq",
25+
"replicate": "Replicate",
26+
"together": "TogetherAI",
27+
"fireworks": "Fireworks",
28+
"deepseek": "DeepSeek",
29+
"perplexity": "Perplexity",
30+
"amazon-bedrock": "AWS",
31+
"bedrock": "AWS",
32+
"azure": "Azure",
33+
"google": "Google",
34+
"vertex": "Google",
35+
"ollama": "Ollama",
36+
"huggingface": "HuggingFace",
37+
"openrouter": "OpenRouter",
38+
};
39+
1740
export const transformAiSdkSpanName = (span: ReadableSpan): void => {
1841
// Unfortunately, the span name is not writable as this is not the intended behavior
1942
// but it is a workaround to set the correct span name
@@ -87,11 +110,19 @@ export const calculateTotalTokens = (attributes: Record<string, any>): void => {
87110
export const transformVendor = (attributes: Record<string, any>): void => {
88111
if (AI_MODEL_PROVIDER in attributes) {
89112
const vendor = attributes[AI_MODEL_PROVIDER];
90-
if (vendor && vendor.startsWith("openai")) {
91-
attributes[SpanAttributes.LLM_SYSTEM] = "OpenAI";
92-
} else {
93-
attributes[SpanAttributes.LLM_SYSTEM] = vendor;
113+
114+
// Find matching vendor prefix in mapping
115+
let mappedVendor = null;
116+
if (vendor && vendor.length > 0) {
117+
for (const prefix of Object.keys(VENDOR_MAPPING)) {
118+
if (vendor.startsWith(prefix)) {
119+
mappedVendor = VENDOR_MAPPING[prefix];
120+
break;
121+
}
122+
}
94123
}
124+
125+
attributes[SpanAttributes.LLM_SYSTEM] = mappedVendor || vendor;
95126
delete attributes[AI_MODEL_PROVIDER];
96127
}
97128
};

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ describe("AI SDK Transformations", () => {
373373

374374
transformVendor(attributes);
375375

376-
assert.strictEqual(attributes[SpanAttributes.LLM_SYSTEM], "anthropic");
376+
assert.strictEqual(attributes[SpanAttributes.LLM_SYSTEM], "Anthropic");
377377
assert.strictEqual(attributes["ai.model.provider"], undefined);
378378
});
379379

0 commit comments

Comments
 (0)