Skip to content

Commit 8fa79e6

Browse files
committed
use correct default temporality for streams based on the instrument kind
1 parent d1f3e35 commit 8fa79e6

File tree

5 files changed

+37
-11
lines changed

5 files changed

+37
-11
lines changed

CHANGELOG.md

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

88
## [Unreleased]
99

10+
## Experimental SDK
11+
12+
### Fixes
13+
14+
- [use correct default temporality for streams based on the instrument
15+
kind](https://github.com/open-telemetry/opentelemetry-erlang/pull/713)
16+
17+
## API
18+
1019
## API 1.3.0 - 2024-03-15
1120

1221
### Changes

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/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_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: 1 addition & 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

0 commit comments

Comments
 (0)