Skip to content

Commit e8c2b2a

Browse files
authored
Merge pull request #713 from tsloughter/fix-default-temporality
use correct default temporality for streams based on the instrument kind
2 parents d1f3e35 + aaece44 commit e8c2b2a

File tree

10 files changed

+55
-16
lines changed

10 files changed

+55
-16
lines changed

CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,20 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
## Experimental API 0.5.1 - 2024-03-18
11+
12+
### Added
13+
14+
- [instrument kind temporality function for use by the
15+
SDK](https://github.com/open-telemetry/opentelemetry-erlang/pull/713)
16+
17+
## Experimental SDK 0.5.1 - 2024-03-18
18+
19+
### Fixes
20+
21+
- [use correct default temporality for streams based on the instrument
22+
kind](https://github.com/open-telemetry/opentelemetry-erlang/pull/713)
23+
1024
## API 1.3.0 - 2024-03-15
1125

1226
### Changes

apps/opentelemetry_api_experimental/src/opentelemetry_api_experimental.app.src

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{application, opentelemetry_api_experimental,
22
[{description, "API for unstable OpenTelemetry signals"},
3-
{vsn, "0.5.0"},
3+
{vsn, "0.5.1"},
44
{registered, []},
55
{applications,
66
[kernel,

apps/opentelemetry_api_experimental/src/otel_instrument.erl

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
-export([new/5,
2121
new/7,
2222
is_monotonic/1,
23-
temporality/1]).
23+
temporality/1,
24+
kind_temporality/1]).
2425

2526
-include("otel_metrics.hrl").
2627

@@ -99,15 +100,18 @@ is_monotonic(#instrument{kind=?KIND_HISTOGRAM}) ->
99100
is_monotonic(_) ->
100101
false.
101102

102-
temporality(#instrument{kind=?KIND_COUNTER}) ->
103+
temporality(#instrument{kind=Kind}) ->
104+
kind_temporality(Kind).
105+
106+
kind_temporality(?KIND_COUNTER) ->
103107
?TEMPORALITY_DELTA;
104-
temporality(#instrument{kind=?KIND_OBSERVABLE_COUNTER}) ->
108+
kind_temporality(?KIND_OBSERVABLE_COUNTER) ->
105109
?TEMPORALITY_CUMULATIVE;
106-
temporality(#instrument{kind=?KIND_UPDOWN_COUNTER}) ->
110+
kind_temporality(?KIND_UPDOWN_COUNTER) ->
107111
?TEMPORALITY_DELTA;
108-
temporality(#instrument{kind=?KIND_OBSERVABLE_UPDOWNCOUNTER}) ->
112+
kind_temporality(?KIND_OBSERVABLE_UPDOWNCOUNTER) ->
109113
?TEMPORALITY_CUMULATIVE;
110-
temporality(#instrument{kind=?KIND_HISTOGRAM}) ->
114+
kind_temporality(?KIND_HISTOGRAM) ->
111115
?TEMPORALITY_DELTA;
112-
temporality(#instrument{kind=?KIND_OBSERVABLE_GAUGE}) ->
116+
kind_temporality(?KIND_OBSERVABLE_GAUGE) ->
113117
?TEMPORALITY_CUMULATIVE.

apps/opentelemetry_experimental/rebar.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{erl_opts, [debug_info]}.
22
{deps, [{opentelemetry, "~> 1.4"},
33
{opentelemetry_api, "~> 1.3"},
4-
{opentelemetry_api_experimental, "~> 0.5"}]}.
4+
{opentelemetry_api_experimental, "~> 0.5.1"}]}.
55

66
{shell, [
77
% {config, "config/sys.config"},

apps/opentelemetry_experimental/src/opentelemetry_experimental.app.src

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{application, opentelemetry_experimental,
22
[{description, "Implementation of unstable OpenTelemetry signals"},
3-
{vsn, "0.5.0"},
3+
{vsn, "0.5.1"},
44
{registered, []},
55
{mod, {opentelemetry_experimental_app, []}},
66
{applications,

apps/opentelemetry_experimental/src/otel_aggregation.erl

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
-module(otel_aggregation).
22

33
-export([maybe_init_aggregate/6,
4-
default_mapping/0]).
4+
default_mapping/0,
5+
default_temporality_mapping/0]).
56

67
-include_lib("opentelemetry_api_experimental/include/otel_metrics.hrl").
78
-include("otel_view.hrl").
@@ -69,6 +70,19 @@ default_mapping() ->
6970
?KIND_UPDOWN_COUNTER => otel_aggregation_sum,
7071
?KIND_OBSERVABLE_UPDOWNCOUNTER => otel_aggregation_sum}.
7172

73+
%% by default the aggregators use the same temporality as is native to the instrument
74+
-spec default_temporality_mapping() -> #{otel_instrument:kind() => otel_instrument:temporality()}.
75+
default_temporality_mapping() ->
76+
lists:foldl(fun(Kind, Acc) ->
77+
Acc#{Kind => otel_instrument:kind_temporality(Kind)}
78+
end, #{}, [?KIND_COUNTER,
79+
?KIND_OBSERVABLE_COUNTER,
80+
?KIND_HISTOGRAM,
81+
?KIND_OBSERVABLE_GAUGE,
82+
?KIND_UPDOWN_COUNTER,
83+
?KIND_OBSERVABLE_UPDOWNCOUNTER
84+
]).
85+
7286
split(Keys, Map) ->
7387
lists:foldl(fun(Key, {KeptAcc, DroppedAcc}) ->
7488
case maps:take(Key, DroppedAcc) of

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/src/otel_metric_reader.erl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ init([ReaderId, ProviderSup, Config]) ->
8787
Exporter = otel_exporter:init(ExporterModuleConfig),
8888

8989
DefaultAggregationMapping = maps:get(default_aggregation_mapping, Config, otel_aggregation:default_mapping()),
90-
Temporality = maps:get(default_temporality_mapping, Config, #{}),
90+
Temporality = maps:get(default_temporality_mapping, Config, otel_aggregation:default_temporality_mapping()),
9191

9292
%% if a periodic reader is needed then this value is set
9393
%% somehow need to do a default of 10000 MILLIS, but only if this is a periodic reader

apps/opentelemetry_experimental/test/otel_metrics_SUITE.erl

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,7 @@ init_per_testcase(delta_counter, Config) ->
169169
%% delta is the default for a counter with sum aggregation
170170
%% so no need to set any temporality mapping in the reader
171171
ok = application:set_env(opentelemetry_experimental, readers, [#{module => otel_metric_reader,
172-
config => #{exporter => {otel_metric_exporter_pid, self()},
173-
default_temporality_mapping => default_temporality_mapping()}}]),
172+
config => #{exporter => {otel_metric_exporter_pid, self()}}}]),
174173

175174
{ok, _} = application:ensure_all_started(opentelemetry_experimental),
176175

@@ -1383,6 +1382,11 @@ advisory_params(_Config) ->
13831382
#{advisory_params => #{explicit_bucket_boundaries => [10, 20, 30]}}),
13841383
?assertEqual(Histogram#instrument.advisory_params, #{explicit_bucket_boundaries => [10, 20, 30]}),
13851384

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+
13861390
Ctx = otel_ctx:new(),
13871391

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

docs.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ rebar3 compile
1111
rebar3 edoc
1212
sdk_version=1.4.0
1313
api_version=1.3.0
14-
exp_sdk_version=0.5.0
15-
exp_api_version=0.5.0
14+
exp_sdk_version=0.5.1
15+
exp_api_version=0.5.1
1616
otlp_version=1.7.0
1717
zipkin_version=1.1.0
1818
semconv_version=0.2.0

0 commit comments

Comments
 (0)