Skip to content

Commit d501597

Browse files
committed
otel add gen_ai.input.messages and gen_ai.output.messages
1 parent a189b3d commit d501597

2 files changed

Lines changed: 7 additions & 3 deletions

File tree

backend/modules/observability/lib/otel/consts.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ const (
9797

9898
// otel attribute key
9999
const (
100-
otelAttributeModelInputTools = "gen_ai.tool.definitions"
100+
otelAttributeModelInputTools = "gen_ai.tool.definitions" // model tools
101101
)
102102

103103
var otelMessageEventNameMap = []string{

backend/modules/observability/lib/otel/otel_convert.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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.
2931
var (
3032
FieldConfMap = map[string]FieldConf{
@@ -96,6 +98,7 @@ var (
9698
openInferenceAttributeModelInputMessages,
9799
openInferenceAttributeToolInput,
98100
string(semconv1_27_0.GenAIPromptKey),
101+
string(semconv.GenAIInputMessagesKey),
99102
},
100103
EventName: []string{otelEventModelSystemMessage, otelEventModelUserMessage, otelEventModelToolMessage, otelEventModelAssistantMessage, otelSpringAIEventModelPrompt},
101104
DataType: dataTypeString,
@@ -122,6 +125,7 @@ var (
122125
AttributeKeyPrefix: []string{
123126
openInferenceAttributeModelOutputMessages,
124127
string(semconv1_27_0.GenAICompletionKey),
128+
string(semconv.GenAIOutputMessagesKey),
125129
},
126130
EventName: []string{otelEventModelChoice, otelSpringAIEventModelCompletion},
127131
DataType: dataTypeString,
@@ -677,7 +681,7 @@ func processAttributePrefix(ctx context.Context, fieldKey string, conf FieldConf
677681
}
678682
}
679683
}
680-
case openInferenceAttributeModelInputMessages: // openInference(or litellm) input message
684+
case openInferenceAttributeModelInputMessages, string(semconv.GenAIInputMessagesKey): // openInference(or litellm) or openTelemetry input message
681685
srcInput, err := open_inference.ConvertToModelInput(srcAttrAggrRes)
682686
if err != nil {
683687
continue
@@ -696,7 +700,7 @@ func processAttributePrefix(ctx context.Context, fieldKey string, conf FieldConf
696700
continue
697701
}
698702
}
699-
case openInferenceAttributeModelOutputMessages: // openInference output message
703+
case openInferenceAttributeModelOutputMessages, string(semconv.GenAIOutputMessagesKey): // openInference(or litellm) or openTelemetry output message
700704
resObject, err := open_inference.ConvertToModelOutput(srcAttrAggrRes)
701705
if err == nil {
702706
toBeMarshalObject = resObject

0 commit comments

Comments
 (0)