Skip to content

Commit 88c9ac3

Browse files
committed
runtime support get from attribute
1 parent d501597 commit 88c9ac3

4 files changed

Lines changed: 26 additions & 14 deletions

File tree

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ const (
3535
otelAttributePromptKey = "cozeloop.prompt_key"
3636
otelAttributePromptVersion = "cozeloop.prompt_version"
3737
otelAttributePromptProvider = "cozeloop.prompt_provider"
38+
39+
// system
40+
otelAttributeSystemRuntime = "cozeloop.system_tag_runtime"
3841
)
3942

4043
// openinference attribute key

backend/modules/observability/lib/otel/open_inference/openinference.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,14 @@ func convertModelMsg(msg map[string]interface{}) map[string]interface{} {
6767
modelMsg["reasoning_content"] = c
6868
}
6969

70-
// contents
70+
// contents or parts
7171
var contents []interface{}
72-
if c, ok := msg["contents"].([]interface{}); ok && len(c) > 0 {
73-
contents = c
74-
} else if c, ok := msg["content"].([]interface{}); ok && len(c) > 0 {
75-
contents = c
72+
partsKey := []string{"contents", "content", "parts"}
73+
for _, key := range partsKey {
74+
if parts, ok := msg[key].([]interface{}); ok && len(parts) > 0 {
75+
contents = parts
76+
break
77+
}
7678
}
7779
if len(contents) > 0 {
7880
parts := make([]interface{}, 0, len(contents))

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

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ func OtelSpanConvertToSendSpan(ctx context.Context, spaceID string, resourceScop
398398
// set attributes
399399
calOtherAttribute(ctx, span, tagsString, tagsLong, tagsDouble, tagsBool)
400400
// set runtime
401-
calRuntime(systemTagsString, resourceScopeSpan)
401+
calRuntime(systemTagsString, tagsString, resourceScopeSpan)
402402

403403
result := &LoopSpan{
404404
StartTime: startTimeUnixNanoInt64 / 1000,
@@ -544,12 +544,19 @@ func calOtherAttribute(ctx context.Context, span *Span, tagsString map[string]st
544544
}
545545
}
546546

547-
func calRuntime(systemTagsString map[string]string, resourceScopeSpan *ResourceScopeSpan) {
548-
systemTagsString[tracespec.Runtime_] = getRuntime(resourceScopeSpan)
547+
func calRuntime(systemTagsString map[string]string, tagsString map[string]string, resourceScopeSpan *ResourceScopeSpan) {
548+
systemTagsString[tracespec.Runtime_] = getRuntime(tagsString, resourceScopeSpan)
549549
}
550550

551-
func getRuntime(resourceScopeSpan *ResourceScopeSpan) string {
552-
runtime := processRuntime(resourceScopeSpan)
551+
func getRuntime(tagsString map[string]string, resourceScopeSpan *ResourceScopeSpan) string {
552+
if len(tagsString) > 0 {
553+
if runtime, ok := tagsString[otelAttributeSystemRuntime]; ok && len(runtime) > 0 {
554+
delete(tagsString, otelAttributeSystemRuntime)
555+
return runtime
556+
}
557+
}
558+
559+
runtime := processRuntimeByScope(resourceScopeSpan)
553560
marshalString, err := sonic.MarshalString(runtime)
554561
if err != nil {
555562
return "" // unexpected
@@ -558,7 +565,7 @@ func getRuntime(resourceScopeSpan *ResourceScopeSpan) string {
558565
return marshalString
559566
}
560567

561-
func processRuntime(resourceScopeSpan *ResourceScopeSpan) *tracespec.Runtime {
568+
func processRuntimeByScope(resourceScopeSpan *ResourceScopeSpan) *tracespec.Runtime {
562569
res := &tracespec.Runtime{
563570
Library: tracespec.VLibOpentelemetry,
564571
Scene: "",

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1036,7 +1036,7 @@ func TestProcessRuntime(t *testing.T) {
10361036
panic(r) // Re-panic if unexpected
10371037
}
10381038
}()
1039-
result := processRuntime(tt.resourceScopeSpan)
1039+
result := processRuntimeByScope(tt.resourceScopeSpan)
10401040
tt.validate(t, result)
10411041
})
10421042
}
@@ -1093,7 +1093,7 @@ func TestGetRuntime(t *testing.T) {
10931093
panic(r) // Re-panic if unexpected
10941094
}
10951095
}()
1096-
result := getRuntime(tt.resourceScopeSpan)
1096+
result := getRuntime(nil, tt.resourceScopeSpan)
10971097
tt.validate(t, result)
10981098
})
10991099
}
@@ -1149,7 +1149,7 @@ func TestCalRuntime(t *testing.T) {
11491149

11501150
for _, tt := range tests {
11511151
t.Run(tt.name, func(t *testing.T) {
1152-
calRuntime(tt.systemTagsString, tt.resourceScopeSpan)
1152+
calRuntime(tt.systemTagsString, nil, tt.resourceScopeSpan)
11531153
tt.validate(t, tt.systemTagsString)
11541154
})
11551155
}

0 commit comments

Comments
 (0)