Skip to content

Commit 48f1a1a

Browse files
authored
Merge pull request #9 from sneako/meta-as-strings
cast metadata field values that are ints or floats, to binary
2 parents 2f0f8ef + fcd802e commit 48f1a1a

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

src/oc_reporter_datadog.erl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,12 @@ build_span(Span, Service, Type) ->
125125
<<"type">> => to_tag(Type),
126126
<<"meta">> => to_meta(Span#span.attributes)}.
127127

128-
to_meta(Attributes) -> maps:map(fun to_tag/2, Attributes).
128+
to_meta(Attributes) -> maps:map(fun to_meta/2, Attributes).
129+
130+
to_meta(_Name, Value) when is_integer(Value) -> integer_to_binary(Value);
131+
to_meta(_Name, Value) when is_float(Value) ->
132+
float_to_binary(Value, [compact, {decimals, 253}]);
133+
to_meta(Name, Value) -> to_tag(Name, Value).
129134

130135
to_tag(Value) -> to_tag(nil, Value).
131136

test/oc_reporter_datadog_SUITE.erl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ init_per_testcase(_, Config) ->
1616
span_id = 1,
1717
start_time = wts:timestamp(),
1818
end_time = wts:timestamp(),
19-
attributes = #{foo => "bar"}
19+
attributes = #{foo => "bar", baz => 10, buz => 1.0}
2020
},
2121
Options = oc_reporter_datadog:init([{http_client, fun mock_client/3}]),
2222
[{span, Span}, {options, Options} | Config].
@@ -38,7 +38,7 @@ test_reports_spans(Config) ->
3838
<<"span_id">> := 1,
3939
<<"type">> := <<"custom">>,
4040
<<"duration">> := _,
41-
<<"meta">> := #{<<"foo">> := <<"bar">>}} = RSpan,
41+
<<"meta">> := #{<<"foo">> := <<"bar">>, <<"baz">> := <<"10">>, <<"buz">> := <<"1.0">>}} = RSpan,
4242
ok;
4343
Msg ->
4444
ct:fail("Unknown message: ~p", [Msg])

0 commit comments

Comments
 (0)