Skip to content

Commit 623a1fe

Browse files
author
Tristan Sloughter
authored
Merge pull request #628 from albertored/advisory-parameters
Support explicit_bucket_boundaries advisory parameters
2 parents a5f1d52 + 8c09768 commit 623a1fe

14 files changed

+249
-80
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3030
### Changes
3131

3232
- [Allow to create observable instruments without passing callback arguments](https://github.com/open-telemetry/opentelemetry-erlang/pull/604)
33+
- [Allow to give `advisory_params` to instrument creation functions](https://github.com/open-telemetry/opentelemetry-erlang/pull/628)
3334

3435
## Experimental SDK
3536

3637
### Added
3738

3839
- [Add `instrument_unit` to view criteria](https://github.com/open-telemetry/opentelemetry-erlang/pull/604)
3940
- [Validate instrument name](https://github.com/open-telemetry/opentelemetry-erlang/pull/604)
41+
- [Handle `explict_bucket_boundaries` advisory parameter](https://github.com/open-telemetry/opentelemetry-erlang/pull/628)
42+
- [Rename `boundaries` to `explict_bucket_boundaries` in histogram explicit aggregation options](https://github.com/open-telemetry/opentelemetry-erlang/pull/628)
4043

4144
### Changes
4245

apps/opentelemetry_api_experimental/include/otel_metrics.hrl

+10-9
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
-record(instrument, {module :: module(),
2-
meter :: otel_meter:t(),
3-
name :: otel_instrument:name(),
4-
description :: otel_instrument:description() | undefined,
5-
kind :: otel_instrument:kind(),
6-
unit :: otel_instrument:unit() | undefined,
7-
temporality :: otel_instrument:temporality(),
8-
callback :: otel_instrument:callback() | undefined,
9-
callback_args :: otel_instrument:callback_args() | undefined}).
1+
-record(instrument, {module :: module(),
2+
meter :: otel_meter:t(),
3+
name :: otel_instrument:name(),
4+
description :: otel_instrument:description() | undefined,
5+
kind :: otel_instrument:kind(),
6+
unit :: otel_instrument:unit() | undefined,
7+
temporality :: otel_instrument:temporality(),
8+
callback :: otel_instrument:callback() | undefined,
9+
callback_args :: otel_instrument:callback_args() | undefined,
10+
advisory_params :: otel_instrument:advisory_params() | undefined}).
1011

1112
-define(TEMPORALITY_DELTA, temporality_delta).
1213
-define(TEMPORALITY_CUMULATIVE, temporality_cumulative).

apps/opentelemetry_api_experimental/src/otel_counter.erl

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
-spec create(Meter, Name, Opts) -> otel_instrument:t() when
2929
Meter :: otel_meter:t(),
3030
Name :: otel_instrument:name(),
31-
Opts :: otel_meter:opts().
31+
Opts :: otel_instrument:opts().
3232
create(Meter, Name, Opts) ->
3333
otel_meter:create_counter(Meter, Name, Opts).
3434

apps/opentelemetry_api_experimental/src/otel_histogram.erl

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
-spec create(Meter, Name, Opts) -> otel_instrument:t() when
3030
Meter :: otel_meter:t(),
3131
Name :: otel_instrument:name(),
32-
Opts :: otel_meter:opts().
32+
Opts :: otel_instrument:opts().
3333
create(Meter, Name, Opts) ->
3434
otel_meter:create_histogram(Meter, Name, Opts).
3535

apps/opentelemetry_api_experimental/src/otel_instrument.erl

+39-23
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
%%%-------------------------------------------------------------------------
1818
-module(otel_instrument).
1919

20-
-export([new/6,
21-
new/8,
20+
-export([new/5,
21+
new/7,
2222
is_monotonic/1,
2323
temporality/1]).
2424

@@ -38,6 +38,12 @@
3838

3939
-type temporality() :: ?TEMPORALITY_DELTA | ?TEMPORALITY_CUMULATIVE.
4040

41+
-type advisory_params() :: #{explicit_bucket_boundaries => [number(), ...]}.
42+
43+
-type opts() :: #{description => description(),
44+
unit => unit(),
45+
advisory_params => advisory_params()}.
46+
4147
-type t() :: #instrument{}.
4248

4349
-export_type([t/0,
@@ -48,29 +54,39 @@
4854
temporality/0,
4955
callback/0,
5056
callback_args/0,
51-
callback_result/0]).
57+
callback_result/0,
58+
advisory_params/0,
59+
opts/0]).
5260

53-
-spec new(module(), otel_meter:t(), kind(), name(), description() | undefined, unit() | undefined) -> t().
54-
new(Module, Meter, Kind, Name, Description, Unit) ->
55-
#instrument{module = Module,
56-
meter = Meter,
57-
name = Name,
58-
description = Description,
59-
temporality = ?TEMPORALITY_DELTA,
60-
kind = Kind,
61-
unit = Unit}.
61+
-spec new(module(), otel_meter:t(), kind(), name(), opts()) -> t().
62+
new(Module, Meter, Kind, Name, Opts) ->
63+
Description = maps:get(description, Opts, undefined),
64+
Unit = maps:get(unit, Opts, undefined),
65+
AdvisoryParams = maps:get(advisory_params, Opts, undefined),
66+
#instrument{module = Module,
67+
meter = Meter,
68+
name = Name,
69+
description = Description,
70+
temporality = ?TEMPORALITY_DELTA,
71+
kind = Kind,
72+
unit = Unit,
73+
advisory_params = AdvisoryParams}.
6274

63-
-spec new(module(), otel_meter:t(), kind(), name(), description() | undefined, unit() | undefined, callback(), callback_args()) -> t().
64-
new(Module, Meter, Kind, Name, Description, Unit, Callback, CallbackArgs) ->
65-
#instrument{module = Module,
66-
meter = Meter,
67-
name = Name,
68-
description = Description,
69-
kind = Kind,
70-
unit = Unit,
71-
temporality = ?TEMPORALITY_CUMULATIVE,
72-
callback = Callback,
73-
callback_args = CallbackArgs}.
75+
-spec new(module(), otel_meter:t(), kind(), name(), callback(), callback_args(), opts()) -> t().
76+
new(Module, Meter, Kind, Name, Callback, CallbackArgs, Opts) ->
77+
Description = maps:get(description, Opts, undefined),
78+
Unit = maps:get(unit, Opts, undefined),
79+
AdvisoryParams = maps:get(advisory_params, Opts, undefined),
80+
#instrument{module = Module,
81+
meter = Meter,
82+
name = Name,
83+
description = Description,
84+
kind = Kind,
85+
unit = Unit,
86+
temporality = ?TEMPORALITY_CUMULATIVE,
87+
callback = Callback,
88+
callback_args = CallbackArgs,
89+
advisory_params = AdvisoryParams}.
7490

7591
is_monotonic(#instrument{kind=?KIND_COUNTER}) ->
7692
true;

apps/opentelemetry_api_experimental/src/otel_meter.erl

+14-18
Original file line numberDiff line numberDiff line change
@@ -42,55 +42,51 @@
4242
Meter :: t(),
4343
Name :: otel_instrument:name(),
4444
Kind :: otel_instrument:kind(),
45-
Opts :: opts().
45+
Opts :: otel_instrument:opts().
4646

4747
-callback create_instrument(Meter, Name, Kind, Callback, CallbackArgs, Opts) -> otel_instrument:t() when
4848
Meter :: t(),
4949
Name :: otel_instrument:name(),
5050
Kind :: otel_instrument:kind(),
5151
Callback :: otel_instrument:callback(),
5252
CallbackArgs :: otel_instrument:callback_args(),
53-
Opts :: opts().
53+
Opts :: otel_instrument:opts().
5454

5555
-callback register_callback(Meter, Instruments, Callback, CallbackArgs) -> ok when
5656
Meter :: t(),
5757
Instruments :: otel_instrument:t(),
5858
Callback :: otel_instrument:callback(),
5959
CallbackArgs :: otel_instrument:callback_args().
6060

61-
-type opts() :: #{description => otel_instrument:description(),
62-
unit => otel_instrument:unit()}.
63-
6461
-type t() :: {module(), term()}.
6562

66-
-export_type([t/0,
67-
opts/0]).
63+
-export_type([t/0]).
6864

6965
-spec create_counter(Meter, Name, Opts) -> otel_instrument:t() when
7066
Meter :: t(),
7167
Name :: otel_instrument:name(),
72-
Opts :: opts().
68+
Opts :: otel_instrument:opts().
7369
create_counter(Meter, Name, Opts) ->
7470
create_instrument(Meter, Name, ?KIND_COUNTER, Opts).
7571

7672
-spec create_updown_counter(Meter, Name, Opts) -> otel_instrument:t() when
7773
Meter :: t(),
7874
Name :: otel_instrument:name(),
79-
Opts :: opts().
75+
Opts :: otel_instrument:opts().
8076
create_updown_counter(Meter, Name, Opts) ->
8177
create_instrument(Meter, Name, ?KIND_UPDOWN_COUNTER, Opts).
8278

8379
-spec create_histogram(Meter, Name, Opts) -> otel_instrument:t() when
8480
Meter :: t(),
8581
Name :: otel_instrument:name(),
86-
Opts :: opts().
82+
Opts :: otel_instrument:opts().
8783
create_histogram(Meter, Name, Opts) ->
8884
create_instrument(Meter, Name, ?KIND_HISTOGRAM, Opts).
8985

9086
-spec create_observable_counter(Meter, Name, Opts) -> otel_instrument:t() when
9187
Meter :: t(),
9288
Name :: otel_instrument:name(),
93-
Opts :: opts().
89+
Opts :: otel_instrument:opts().
9490
create_observable_counter(Meter, Name, Opts) ->
9591
create_instrument(Meter, Name, ?KIND_OBSERVABLE_COUNTER, Opts).
9692

@@ -99,14 +95,14 @@ create_observable_counter(Meter, Name, Opts) ->
9995
Name :: otel_instrument:name(),
10096
Callback :: otel_instrument:callback(),
10197
CallbackArgs :: otel_instrument:callback_args(),
102-
Opts :: opts().
98+
Opts :: otel_instrument:opts().
10399
create_observable_counter(Meter, Name, Callback, CallbackArgs, Opts) ->
104100
create_instrument(Meter, Name, ?KIND_OBSERVABLE_COUNTER, Callback, CallbackArgs, Opts).
105101

106102
-spec create_observable_gauge(Meter, Name, Opts) -> otel_instrument:t() when
107103
Meter :: t(),
108104
Name :: otel_instrument:name(),
109-
Opts :: opts().
105+
Opts :: otel_instrument:opts().
110106
create_observable_gauge(Meter, Name, Opts) ->
111107
create_instrument(Meter, Name, ?KIND_OBSERVABLE_GAUGE, Opts).
112108

@@ -115,14 +111,14 @@ create_observable_gauge(Meter, Name, Opts) ->
115111
Name :: otel_instrument:name(),
116112
Callback :: otel_instrument:callback(),
117113
CallbackArgs :: otel_instrument:callback_args(),
118-
Opts :: opts().
114+
Opts :: otel_instrument:opts().
119115
create_observable_gauge(Meter, Name, Callback, CallbackArgs, Opts) ->
120116
create_instrument(Meter, Name, ?KIND_OBSERVABLE_GAUGE, Callback, CallbackArgs, Opts).
121117

122118
-spec create_observable_updowncounter(Meter, Name, Opts) -> otel_instrument:t() when
123119
Meter :: t(),
124120
Name :: otel_instrument:name(),
125-
Opts :: opts().
121+
Opts :: otel_instrument:opts().
126122
create_observable_updowncounter(Meter, Name, Opts) ->
127123
create_instrument(Meter, Name, ?KIND_OBSERVABLE_UPDOWNCOUNTER, Opts).
128124

@@ -131,7 +127,7 @@ create_observable_updowncounter(Meter, Name, Opts) ->
131127
Name :: otel_instrument:name(),
132128
Callback :: otel_instrument:callback(),
133129
CallbackArgs :: otel_instrument:callback_args(),
134-
Opts :: opts().
130+
Opts :: otel_instrument:opts().
135131
create_observable_updowncounter(Meter, Name, Callback, CallbackArgs, Opts) ->
136132
create_instrument(Meter, Name, ?KIND_OBSERVABLE_UPDOWNCOUNTER, Callback, CallbackArgs, Opts).
137133

@@ -145,7 +141,7 @@ scope(Meter={Module, _}) ->
145141
Meter :: t(),
146142
Name :: otel_instrument:name(),
147143
Kind :: otel_instrument:kind(),
148-
Opts :: opts().
144+
Opts :: otel_instrument:opts().
149145
create_instrument(Meter={Module, _}, Name, Kind, Opts) ->
150146
Module:create_instrument(Meter, Name, Kind, Opts).
151147

@@ -155,7 +151,7 @@ create_instrument(Meter={Module, _}, Name, Kind, Opts) ->
155151
Kind :: otel_instrument:kind(),
156152
Callback :: otel_instrument:callback(),
157153
CallbackArgs :: otel_instrument:callback_args(),
158-
Opts :: opts().
154+
Opts :: otel_instrument:opts().
159155
create_instrument(Meter={Module, _}, Name, Kind, Callback, CallbackArgs, Opts) ->
160156
Module:create_instrument(Meter, Name, Kind, Callback, CallbackArgs, Opts).
161157

apps/opentelemetry_api_experimental/src/otel_meter_noop.erl

+2-4
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,7 @@ register_callback(_Meter, _Instruments, _Callback, _CallbackArgs) ->
4141
ok.
4242

4343
create_instrument(Meter, Name, Kind, Opts) ->
44-
otel_instrument:new(?MODULE, Meter, Kind, Name, maps:get(description, Opts, undefined),
45-
maps:get(unit, Opts, undefined)).
44+
otel_instrument:new(?MODULE, Meter, Kind, Name, Opts).
4645

4746
create_instrument(Meter, Name, Kind, Callback, CallbackArgs, Opts) ->
48-
otel_instrument:new(?MODULE, Meter, Kind, Name, maps:get(description, Opts, undefined),
49-
maps:get(unit, Opts, undefined), Callback, CallbackArgs).
47+
otel_instrument:new(?MODULE, Meter, Kind, Name, Callback, CallbackArgs, Opts).

apps/opentelemetry_api_experimental/src/otel_updown_counter.erl

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
-spec create(Meter, Name, Opts) -> otel_instrument:t() when
2929
Meter :: otel_meter:t(),
3030
Name :: otel_instrument:name(),
31-
Opts :: otel_meter:opts().
31+
Opts :: otel_instrument:opts().
3232
create(Meter, Name, Opts) ->
3333
otel_meter:create_updown_counter(Meter, Name, Opts).
3434

apps/opentelemetry_experimental/include/otel_metrics.hrl

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
start_time_unix_nano :: integer() | {const, eqwalizer:dynamic()} | '$9' | '$2' | undefined,
6363
%% instrument_temporality :: otel_aggregation:temporality(),
6464
%% default: [0.0, 5.0, 10.0, 25.0, 50.0, 75.0, 100.0, 250.0, 500.0, 1000.0]
65-
boundaries :: [float()] | match_spec([float()]),
65+
explicit_bucket_boundaries :: [float()] | match_spec([float()]),
6666
record_min_max :: boolean() | match_spec(boolean()),
6767
checkpoint :: #explicit_histogram_checkpoint{} | match_spec(#explicit_histogram_checkpoint{}) | {#explicit_histogram_checkpoint{}},
6868
bucket_counts :: counters:counters_ref() | match_spec(undefined),

apps/opentelemetry_experimental/src/otel_aggregation_histogram_explicit.erl

+10-10
Original file line numberDiff line numberDiff line change
@@ -136,12 +136,12 @@ init(#view_aggregation{name=Name,
136136
reader=ReaderId,
137137
aggregation_options=Options}, Attributes) ->
138138
Key = {Name, Attributes, ReaderId},
139-
Boundaries = maps:get(boundaries, Options, ?DEFAULT_BOUNDARIES),
139+
ExplicitBucketBoundaries = maps:get(explicit_bucket_boundaries, Options, ?DEFAULT_BOUNDARIES),
140140
RecordMinMax = maps:get(record_min_max, Options, true),
141141
#explicit_histogram_aggregation{key=Key,
142142
start_time_unix_nano=erlang:system_time(nanosecond),
143-
boundaries=Boundaries,
144-
bucket_counts=new_bucket_counts(Boundaries),
143+
explicit_bucket_boundaries=ExplicitBucketBoundaries,
144+
bucket_counts=new_bucket_counts(ExplicitBucketBoundaries),
145145
checkpoint=undefined,
146146
record_min_max=RecordMinMax,
147147
min=infinity, %% works because any atom is > any integer
@@ -153,17 +153,17 @@ aggregate(Table, #view_aggregation{name=Name,
153153
reader=ReaderId,
154154
aggregation_options=Options}, Value, Attributes) ->
155155
Key = {Name, Attributes, ReaderId},
156-
Boundaries = maps:get(boundaries, Options, ?DEFAULT_BOUNDARIES),
156+
ExplicitBucketBoundaries = maps:get(explicit_bucket_boundaries, Options, ?DEFAULT_BOUNDARIES),
157157
try ets:lookup_element(Table, Key, #explicit_histogram_aggregation.bucket_counts) of
158158
BucketCounts0 ->
159159
BucketCounts = case BucketCounts0 of
160160
undefined ->
161-
new_bucket_counts(Boundaries);
161+
new_bucket_counts(ExplicitBucketBoundaries);
162162
_ ->
163163
BucketCounts0
164164
end,
165165

166-
BucketIdx = find_bucket(Boundaries, Value),
166+
BucketIdx = find_bucket(ExplicitBucketBoundaries, Value),
167167
counters:add(BucketCounts, BucketIdx, 1),
168168

169169
MS = ?AGGREATE_MATCH_SPEC(Key, Value, BucketCounts),
@@ -181,7 +181,7 @@ checkpoint(Tab, #view_aggregation{name=Name,
181181
temporality=?TEMPORALITY_DELTA}, CollectionStartNano) ->
182182
MS = [{#explicit_histogram_aggregation{key='$1',
183183
start_time_unix_nano='$9',
184-
boundaries='$2',
184+
explicit_bucket_boundaries='$2',
185185
record_min_max='$3',
186186
checkpoint='_',
187187
bucket_counts='$5',
@@ -193,7 +193,7 @@ checkpoint(Tab, #view_aggregation{name=Name,
193193
{'=:=', {element, 3, '$1'}, {const, ReaderId}}],
194194
[{#explicit_histogram_aggregation{key='$1',
195195
start_time_unix_nano={const, CollectionStartNano},
196-
boundaries='$2',
196+
explicit_bucket_boundaries='$2',
197197
record_min_max='$3',
198198
checkpoint={#explicit_histogram_checkpoint{bucket_counts='$5',
199199
min='$6',
@@ -229,7 +229,7 @@ collect(Tab, #view_aggregation{name=Name,
229229

230230
datapoint(CollectionStartNano, #explicit_histogram_aggregation{
231231
key={_, Attributes, _},
232-
boundaries=Boundaries,
232+
explicit_bucket_boundaries=Boundaries,
233233
start_time_unix_nano=StartTimeUnixNano,
234234
checkpoint=undefined,
235235
bucket_counts=BucketCounts,
@@ -253,7 +253,7 @@ datapoint(CollectionStartNano, #explicit_histogram_aggregation{
253253
};
254254
datapoint(CollectionStartNano, #explicit_histogram_aggregation{
255255
key={_, Attributes, _},
256-
boundaries=Boundaries,
256+
explicit_bucket_boundaries=Boundaries,
257257
checkpoint=#explicit_histogram_checkpoint{bucket_counts=BucketCounts,
258258
min=Min,
259259
max=Max,

0 commit comments

Comments
 (0)