Skip to content

Commit

Permalink
support empty list boundaries param to get a single bucket histogram
Browse files Browse the repository at this point in the history
  • Loading branch information
tsloughter committed Mar 18, 2024
1 parent b30afaa commit bca6700
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
3 changes: 3 additions & 0 deletions apps/opentelemetry_experimental/src/otel_meter_default.erl
Expand Up @@ -97,6 +97,9 @@ validate_advisory_param(Name, _Kind, Opt, _Value) ->
?LOG_WARNING("[instrument '~s'] '~s' advisory parameter is not supported, ignoring", [Name, Opt]),
false.

%% empty list denotes a single bucket histogram that can be used for things like summaries
validate_explicit_bucket_boundaries(_Name, []) ->
{true, {explicit_bucket_boundaries, []}};
validate_explicit_bucket_boundaries(Name, [_ | _] = Value) ->
case lists:all(fun is_number/1, Value) and (lists:sort(Value) == Value) of
true ->
Expand Down
5 changes: 5 additions & 0 deletions apps/opentelemetry_experimental/test/otel_metrics_SUITE.erl
Expand Up @@ -1382,6 +1382,11 @@ advisory_params(_Config) ->
#{advisory_params => #{explicit_bucket_boundaries => [10, 20, 30]}}),
?assertEqual(Histogram#instrument.advisory_params, #{explicit_bucket_boundaries => [10, 20, 30]}),

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

Ctx = otel_ctx:new(),

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

0 comments on commit bca6700

Please sign in to comment.