diff --git a/libbeat/otelbeat/otelmap/otelmap.go b/libbeat/otelbeat/otelmap/otelmap.go index 0e1aeb216e5a..8a471524860e 100644 --- a/libbeat/otelbeat/otelmap/otelmap.go +++ b/libbeat/otelbeat/otelmap/otelmap.go @@ -100,13 +100,11 @@ func ConvertNonPrimitive[T mapstrOrMap](m T) { if ref.Kind() == reflect.Slice || ref.Kind() == reflect.Array { s := make([]any, ref.Len()) for i := 0; i < ref.Len(); i++ { - elem := ref.Index(i) - if elem.Kind() == reflect.Map && elem.Type().Key().Kind() == reflect.String && elem.Type().Elem().Kind() == reflect.Interface { - if m, ok := elem.Interface().(map[string]any); ok { - ConvertNonPrimitive(m) - } + elem := ref.Index(i).Interface() + if m, ok := elem.(map[string]any); ok { + ConvertNonPrimitive(m) } - s[i] = elem.Interface() + 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 8c5de4024128..a33fc0fa749f 100644 --- a/libbeat/otelbeat/otelmap/otelmap_test.go +++ b/libbeat/otelbeat/otelmap/otelmap_test.go @@ -281,7 +281,8 @@ func TestFromMapstrWithNestedData(t *testing.T) { "bool_slice": []bool{false, true}, "inner": []mapstr.M{ { - "inner_int": 42, + "inner_int": 42, + "inner_map_slice": [1]any{nil}, "inner_slice": []map[string]any{ // slice -> slice {"string": "string"}, {"number": 12.3}, @@ -289,6 +290,9 @@ func TestFromMapstrWithNestedData(t *testing.T) { }, { "inner_int": 43, + "inner_map_slice": []any{ + map[string]any{"string": "string3"}, + }, "inner_slice": [2]map[string]any{ // array -> slice {"string": "string2"}, {"number": 12.4}, @@ -303,7 +307,8 @@ func TestFromMapstrWithNestedData(t *testing.T) { "bool_slice": []any{false, true}, "inner": []any{ map[string]any{ - "inner_int": 42, + "inner_int": 42, + "inner_map_slice": []any{nil}, "inner_slice": []any{ map[string]any{"string": "string"}, map[string]any{"number": 12.3}, @@ -311,6 +316,9 @@ func TestFromMapstrWithNestedData(t *testing.T) { }, map[string]any{ "inner_int": 43, + "inner_map_slice": []any{ + map[string]any{"string": "string3"}, + }, "inner_slice": []any{ map[string]any{"string": "string2"}, map[string]any{"number": 12.4},