diff --git a/libbeat/otelbeat/otelmap/otelmap.go b/libbeat/otelbeat/otelmap/otelmap.go index 8a471524860e..50487d66a56c 100644 --- a/libbeat/otelbeat/otelmap/otelmap.go +++ b/libbeat/otelbeat/otelmap/otelmap.go @@ -101,10 +101,15 @@ func ConvertNonPrimitive[T mapstrOrMap](m T) { s := make([]any, ref.Len()) for i := 0; i < ref.Len(); i++ { elem := ref.Index(i).Interface() - if m, ok := elem.(map[string]any); ok { - ConvertNonPrimitive(m) + if mi, ok := elem.(map[string]any); ok { + ConvertNonPrimitive(mi) + s[i] = mi + } else if mi, ok := elem.(mapstr.M); ok { + ConvertNonPrimitive(mi) + s[i] = map[string]any(mi) + } else { + s[i] = elem } - s[i] = elem } m[key] = s break // we figured out the type, so we don't need the unknown type case diff --git a/libbeat/otelbeat/otelmap/otelmap_test.go b/libbeat/otelbeat/otelmap/otelmap_test.go index a33fc0fa749f..5d2b19bd35fa 100644 --- a/libbeat/otelbeat/otelmap/otelmap_test.go +++ b/libbeat/otelbeat/otelmap/otelmap_test.go @@ -198,7 +198,7 @@ func TestFromMapstrMapstr(t *testing.T) { } func TestFromMapstrSliceMapstr(t *testing.T) { - inputSlice := []mapstr.M{mapstr.M{"item": 1}, mapstr.M{"item": 1}, mapstr.M{"item": 1}} + inputSlice := []mapstr.M{{"item": 1}, {"item": 1}, {"item": 1}} inputMap := mapstr.M{ "slice": inputSlice, } @@ -292,6 +292,7 @@ func TestFromMapstrWithNestedData(t *testing.T) { "inner_int": 43, "inner_map_slice": []any{ map[string]any{"string": "string3"}, + mapstr.M{"number": 12.4}, }, "inner_slice": [2]map[string]any{ // array -> slice {"string": "string2"}, @@ -318,6 +319,7 @@ func TestFromMapstrWithNestedData(t *testing.T) { "inner_int": 43, "inner_map_slice": []any{ map[string]any{"string": "string3"}, + map[string]any{"number": 12.4}, }, "inner_slice": []any{ map[string]any{"string": "string2"},