Skip to content

Commit 48d3981

Browse files
committed
support empty list boundaries param to get a single bucket histogram
1 parent 8fa79e6 commit 48d3981

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

apps/opentelemetry_experimental/src/otel_meter_default.erl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,9 @@ validate_advisory_param(Name, _Kind, Opt, _Value) ->
9797
?LOG_WARNING("[instrument '~s'] '~s' advisory parameter is not supported, ignoring", [Name, Opt]),
9898
false.
9999

100+
%% empty list denotes a single bucket histogram that can be used for things like summaries
101+
validate_explicit_bucket_boundaries(_Name, []) ->
102+
{true, {explicit_bucket_boundaries, []}};
100103
validate_explicit_bucket_boundaries(Name, [_ | _] = Value) ->
101104
case lists:all(fun is_number/1, Value) and (lists:sort(Value) == Value) of
102105
true ->

apps/opentelemetry_experimental/test/otel_metrics_SUITE.erl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1382,6 +1382,11 @@ advisory_params(_Config) ->
13821382
#{advisory_params => #{explicit_bucket_boundaries => [10, 20, 30]}}),
13831383
?assertEqual(Histogram#instrument.advisory_params, #{explicit_bucket_boundaries => [10, 20, 30]}),
13841384

1385+
%% an empty boundaries list can be used to get a single bucket histogram `(-Inf, +Inf)'
1386+
BHistogram = otel_histogram:create(Meter, b_histogram,
1387+
#{advisory_params => #{explicit_bucket_boundaries => []}}),
1388+
?assertEqual(BHistogram#instrument.advisory_params, #{explicit_bucket_boundaries => []}),
1389+
13851390
Ctx = otel_ctx:new(),
13861391

13871392
?assertEqual(ok, otel_histogram:record(Ctx, Histogram, 15, #{<<"a">> => <<"1">>})),

0 commit comments

Comments
 (0)