@@ -25,6 +25,8 @@ import (
2525
2626// FieldConfMap Field configuration, supports configuring data sources and export methods for fields, currently supports attribute, event, is_tag, data_type
2727// Among them, attributes and events support configuring multiple, while tags and datatypes only support configuring one.
28+ // For AttributeKey and AttributeKeyPrefix, the field at the head has higher priority, and result will be returned once a match is found.
29+ // For Events, the fields have same priority, and result will be fixed by all fields.
2830// Other types of configurations need to be manually processed in the code.
2931var (
3032 FieldConfMap = map [string ]FieldConf {
6870 IsTag : true ,
6971 DataType : dataTypeString ,
7072 },
73+ "status_code" : {
74+ AttributeKey : []string {otelAttributeStatusCode },
75+ IsTag : false ,
76+ DataType : dataTypeInt64 ,
77+ },
7178 "psm" : {
7279 AttributeKey : []string {"service.name" },
7380 IsTag : false ,
@@ -86,11 +93,13 @@ var (
8693 springAIAttributeToolInput ,
8794 otelAttributeInput ,
8895 apmInput ,
96+ otelAttributeToolInput ,
8997 },
9098 AttributeKeyPrefix : []string {
9199 openInferenceAttributeModelInputMessages ,
92100 openInferenceAttributeToolInput ,
93101 string (semconv1_27_0 .GenAIPromptKey ),
102+ string (semconv .GenAIInputMessagesKey ),
94103 },
95104 EventName : []string {otelEventModelSystemMessage , otelEventModelUserMessage , otelEventModelToolMessage , otelEventModelAssistantMessage , otelSpringAIEventModelPrompt },
96105 DataType : dataTypeString ,
@@ -113,10 +122,12 @@ var (
113122 springAIAttributeToolOutput ,
114123 otelAttributeOutput ,
115124 apmOutput ,
125+ otelAttributeToolOutput ,
116126 },
117127 AttributeKeyPrefix : []string {
118128 openInferenceAttributeModelOutputMessages ,
119129 string (semconv1_27_0 .GenAICompletionKey ),
130+ string (semconv .GenAIOutputMessagesKey ),
120131 },
121132 EventName : []string {otelEventModelChoice , otelSpringAIEventModelCompletion },
122133 DataType : dataTypeString ,
@@ -343,6 +354,11 @@ func OtelSpanConvertToSendSpan(ctx context.Context, spaceID string, resourceScop
343354 }
344355 if conf .IsTag {
345356 tagsLong [fieldKey ] = value
357+ } else {
358+ switch fieldKey {
359+ case "status_code" :
360+ statusCode = int32 (value )
361+ }
346362 }
347363 case dataTypeBool :
348364 value , ok := srcValue .(bool )
@@ -384,7 +400,7 @@ func OtelSpanConvertToSendSpan(ctx context.Context, spaceID string, resourceScop
384400 // set attributes
385401 calOtherAttribute (ctx , span , tagsString , tagsLong , tagsDouble , tagsBool )
386402 // set runtime
387- calRuntime (systemTagsString , resourceScopeSpan )
403+ calRuntime (systemTagsString , tagsString , resourceScopeSpan )
388404
389405 result := & LoopSpan {
390406 StartTime : startTimeUnixNanoInt64 / 1000 ,
@@ -530,12 +546,19 @@ func calOtherAttribute(ctx context.Context, span *Span, tagsString map[string]st
530546 }
531547}
532548
533- func calRuntime (systemTagsString map [string ]string , resourceScopeSpan * ResourceScopeSpan ) {
534- systemTagsString [tracespec .Runtime_ ] = getRuntime (resourceScopeSpan )
549+ func calRuntime (systemTagsString map [string ]string , tagsString map [ string ] string , resourceScopeSpan * ResourceScopeSpan ) {
550+ systemTagsString [tracespec .Runtime_ ] = getRuntime (tagsString , resourceScopeSpan )
535551}
536552
537- func getRuntime (resourceScopeSpan * ResourceScopeSpan ) string {
538- runtime := processRuntime (resourceScopeSpan )
553+ func getRuntime (tagsString map [string ]string , resourceScopeSpan * ResourceScopeSpan ) string {
554+ if len (tagsString ) > 0 {
555+ if runtime , ok := tagsString [otelAttributeSystemRuntime ]; ok && len (runtime ) > 0 {
556+ delete (tagsString , otelAttributeSystemRuntime )
557+ return runtime
558+ }
559+ }
560+
561+ runtime := processRuntimeByScope (resourceScopeSpan )
539562 marshalString , err := sonic .MarshalString (runtime )
540563 if err != nil {
541564 return "" // unexpected
@@ -544,7 +567,7 @@ func getRuntime(resourceScopeSpan *ResourceScopeSpan) string {
544567 return marshalString
545568}
546569
547- func processRuntime (resourceScopeSpan * ResourceScopeSpan ) * tracespec.Runtime {
570+ func processRuntimeByScope (resourceScopeSpan * ResourceScopeSpan ) * tracespec.Runtime {
548571 res := & tracespec.Runtime {
549572 Library : tracespec .VLibOpentelemetry ,
550573 Scene : "" ,
@@ -667,7 +690,7 @@ func processAttributePrefix(ctx context.Context, fieldKey string, conf FieldConf
667690 }
668691 }
669692 }
670- case openInferenceAttributeModelInputMessages : // openInference(or litellm) input message
693+ case openInferenceAttributeModelInputMessages , string ( semconv . GenAIInputMessagesKey ) : // openInference(or litellm) or openTelemetry input message
671694 srcInput , err := open_inference .ConvertToModelInput (srcAttrAggrRes )
672695 if err != nil {
673696 continue
@@ -686,7 +709,7 @@ func processAttributePrefix(ctx context.Context, fieldKey string, conf FieldConf
686709 continue
687710 }
688711 }
689- case openInferenceAttributeModelOutputMessages : // openInference output message
712+ case openInferenceAttributeModelOutputMessages , string ( semconv . GenAIOutputMessagesKey ) : // openInference(or litellm) or openTelemetry output message
690713 resObject , err := open_inference .ConvertToModelOutput (srcAttrAggrRes )
691714 if err == nil {
692715 toBeMarshalObject = resObject
0 commit comments