From 67e1991ec3ffbfbd6ba552ca21866c6141f6443a Mon Sep 17 00:00:00 2001 From: Bryan Naegele Date: Fri, 26 Apr 2024 13:29:04 -0600 Subject: [PATCH 1/4] Test case for string list attr bug --- .../test/opentelemetry_exporter_SUITE.erl | 36 +++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/apps/opentelemetry_exporter/test/opentelemetry_exporter_SUITE.erl b/apps/opentelemetry_exporter/test/opentelemetry_exporter_SUITE.erl index df9a86a7..a88c4edf 100644 --- a/apps/opentelemetry_exporter/test/opentelemetry_exporter_SUITE.erl +++ b/apps/opentelemetry_exporter/test/opentelemetry_exporter_SUITE.erl @@ -314,8 +314,9 @@ span_round_trip(_Config) -> attributes = [{<<"attr-3">>, <<"value-3">>}]}], Events), attributes = otel_attributes:new([{<<"attr-2">>, <<"value-2">>}, {attr_3, true}, - {<<"map-key-1">>, #{<<"map-key-1">> => 123}}, - {<<"list-key-1">>, [3.14, 9.345]} + {<<"map-key-1">>, #{<<"map-kv-1">> => 123}}, + {<<"binary-list-key-1">>, [<<"value-1">>, <<"value-2">>]}, + {<<"atom-list-key-1">>, [kv1, kv2]} ], 128, 128), status = #status{code=?OTEL_STATUS_OK, message = <<"">>}, @@ -327,6 +328,37 @@ span_round_trip(_Config) -> PbSpan1 = maps:filter(fun(_, V) -> V =/= undefined end, PbSpan), DecodedProto = opentelemetry_exporter_trace_service_pb:decode_msg(Proto, span), + % erlang:dump(DecodedProto), + ExpectedAttributes = [#{key => <<"map-key-1">>, + value => + #{value => + {kvlist_value, + #{values => + [#{key => <<"map-kv-1">>, + value => + #{value => + {int_value,123}}}]}}}}, + #{key => <<"binary-list-key-1">>, + value => + #{value => + {array_value, + #{values => + [#{value => {string_value,<<"value-1">>}}, + #{value => + {string_value,<<"value-2">>}}]}}}}, + #{key => <<"atom-list-key-1">>, + value => + #{value => + {array_value, + #{values => + [#{value => {string_value,<<"value-1">>}}, + #{value => + {string_value,<<"value-2">>}}]}}}}, + #{key => <<"attr-2">>, + value => #{value => {string_value,<<"value-2">>}}}, + #{key => <<"attr_3">>, + value => #{value => {string_value,<<"true">>}}}], + ?assertEqual(ExpectedAttributes, maps:get(attributes, DecodedProto)), ?assertEqual(maps:with([trace_id, span_id], DecodedProto), maps:with([trace_id, span_id], PbSpan1)), From fbcb0f3ac011bd583ffccf7d9b78841ab27e8dd2 Mon Sep 17 00:00:00 2001 From: Bryan Naegele Date: Fri, 26 Apr 2024 15:45:36 -0600 Subject: [PATCH 2/4] Start suite to test attribute conversions --- .../test/otel_otlp_common_SUITE.erl | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 apps/opentelemetry_exporter/test/otel_otlp_common_SUITE.erl diff --git a/apps/opentelemetry_exporter/test/otel_otlp_common_SUITE.erl b/apps/opentelemetry_exporter/test/otel_otlp_common_SUITE.erl new file mode 100644 index 00000000..b962ed48 --- /dev/null +++ b/apps/opentelemetry_exporter/test/otel_otlp_common_SUITE.erl @@ -0,0 +1,39 @@ +-module(otel_otlp_common_SUITE). + +-compile(export_all). +-compile(nowarn_export_all). + +-include_lib("stdlib/include/assert.hrl"). +-include_lib("common_test/include/ct.hrl"). +-include_lib("opentelemetry_api/include/opentelemetry.hrl"). + +all() -> + [ + to_attrs_list_atoms, + to_attrs_list_binaries, + to_attrs_tuple_binaries + ]. + + +init_per_suite(Config) -> + Config. + +end_per_suite(_Config) -> + ok. + +to_attrs_list_atoms(_Config) -> + ArrayExpected = #{value => {array_value, #{values => [#{value => {string_value,<<"a">>}}, #{value => {string_value,<<"b">>}}]}}}, + [#{value := Actual}] = otel_otlp_common:to_attributes(#{atoms => [a, b]}), + ?assertEqual(ArrayExpected, Actual). + + +to_attrs_list_binaries(_Config) -> + ArrayExpected = #{value => {array_value, #{values => [#{value => {string_value,<<"a">>}}, #{value => {string_value,<<"b">>}}]}}}, + [#{value := Actual}] = otel_otlp_common:to_attributes(#{atoms => [<<"a">>, <<"b">>]}), + ?assertEqual(ArrayExpected, Actual). + + +to_attrs_tuple_binaries(_Config) -> + ArrayExpected = #{value => {array_value, #{values => [#{value => {string_value,<<"a">>}}, #{value => {string_value,<<"b">>}}]}}}, + [#{value := Actual}] = otel_otlp_common:to_attributes(#{atoms => {<<"a">>, <<"b">>}}), + ?assertEqual(ArrayExpected, Actual). From 46ed4de140aa5267bd1c2fac24540b6f29edf43a Mon Sep 17 00:00:00 2001 From: Bryan Naegele Date: Wed, 10 Jul 2024 08:13:21 -0600 Subject: [PATCH 3/4] Update opentelemetry_exporter_SUITE.erl --- .../test/opentelemetry_exporter_SUITE.erl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/opentelemetry_exporter/test/opentelemetry_exporter_SUITE.erl b/apps/opentelemetry_exporter/test/opentelemetry_exporter_SUITE.erl index a88c4edf..0e7a9c20 100644 --- a/apps/opentelemetry_exporter/test/opentelemetry_exporter_SUITE.erl +++ b/apps/opentelemetry_exporter/test/opentelemetry_exporter_SUITE.erl @@ -346,6 +346,8 @@ span_round_trip(_Config) -> [#{value => {string_value,<<"value-1">>}}, #{value => {string_value,<<"value-2">>}}]}}}}, + #{key => <<"attr-2">>, + value => #{value => {string_value,<<"value-2">>}}}, #{key => <<"atom-list-key-1">>, value => #{value => @@ -354,8 +356,6 @@ span_round_trip(_Config) -> [#{value => {string_value,<<"value-1">>}}, #{value => {string_value,<<"value-2">>}}]}}}}, - #{key => <<"attr-2">>, - value => #{value => {string_value,<<"value-2">>}}}, #{key => <<"attr_3">>, value => #{value => {string_value,<<"true">>}}}], ?assertEqual(ExpectedAttributes, maps:get(attributes, DecodedProto)), From 1f4458b4a0f0ea16eadeebf55199c84ca2ab1421 Mon Sep 17 00:00:00 2001 From: Bryan Naegele Date: Wed, 10 Jul 2024 08:52:05 -0600 Subject: [PATCH 4/4] Update opentelemetry_exporter_SUITE.erl --- .../test/opentelemetry_exporter_SUITE.erl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/opentelemetry_exporter/test/opentelemetry_exporter_SUITE.erl b/apps/opentelemetry_exporter/test/opentelemetry_exporter_SUITE.erl index 0e7a9c20..1d26770d 100644 --- a/apps/opentelemetry_exporter/test/opentelemetry_exporter_SUITE.erl +++ b/apps/opentelemetry_exporter/test/opentelemetry_exporter_SUITE.erl @@ -358,7 +358,7 @@ span_round_trip(_Config) -> {string_value,<<"value-2">>}}]}}}}, #{key => <<"attr_3">>, value => #{value => {string_value,<<"true">>}}}], - ?assertEqual(ExpectedAttributes, maps:get(attributes, DecodedProto)), + ?assertMatch(ExpectedAttributes, maps:get(attributes, DecodedProto)), ?assertEqual(maps:with([trace_id, span_id], DecodedProto), maps:with([trace_id, span_id], PbSpan1)),