@@ -14,6 +14,29 @@ const AI_USAGE_PROMPT_TOKENS = "ai.usage.promptTokens";
1414const AI_USAGE_COMPLETION_TOKENS = "ai.usage.completionTokens" ;
1515const 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+
1740export 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 => {
87110export 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} ;
0 commit comments