Skip to content

Commit 98be90e

Browse files
authored
fix: instrument unit must be an atom not the number 1 (#950)
* fix: instrument unit must be an atom not the number 1 * fix: make description optional in metrics protobuf map * chore: ignore eqwalizer complaining about matchspec
1 parent 4f0689d commit 98be90e

File tree

5 files changed

+18
-14
lines changed

5 files changed

+18
-14
lines changed

apps/opentelemetry_api_experimental/src/otel_instrument.erl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@
4141

4242
-type advisory_params() :: #{explicit_bucket_boundaries => [number(), ...]}.
4343

44-
-type opts() :: #{description => description(),
45-
unit => unit(),
46-
advisory_params => advisory_params()}.
44+
-type opts() :: #{description => description() | undefined,
45+
unit => unit() | undefined,
46+
advisory_params => advisory_params() | undefined}.
4747

4848
-type t() :: #instrument{}.
4949

apps/opentelemetry_experimental/include/otel_metrics.hrl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@
115115
{
116116
name :: otel_view:name(),
117117
scope :: opentelemetry:instrumentation_scope() | undefined,
118-
description :: otel_instrument:description(),
119-
unit :: otel_instrument:unit(),
118+
description :: otel_instrument:description() | undefined,
119+
unit :: otel_instrument:unit() | undefined,
120120
data :: #sum{} | #gauge{} | #histogram{}
121121
}).

apps/opentelemetry_experimental/src/otel_otlp_metrics.erl

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,16 @@ to_proto(#metric{name=Name,
6363
data=Data}) ->
6464
Metric =
6565
#{name => otel_otlp_common:to_binary(Name),
66-
description => Description,
6766
data => to_data(Data)},
68-
case Unit of
69-
undefined -> Metric;
70-
_ -> Metric#{unit => otel_otlp_common:to_binary(Unit)}
67+
68+
Metric1 = case Unit of
69+
undefined -> Metric;
70+
_ -> Metric#{unit => otel_otlp_common:to_binary(Unit)}
71+
end,
72+
73+
case Description of
74+
undefined -> Metric1;
75+
_ -> Metric1#{description => Description}
7176
end.
7277

7378
to_data(#sum{aggregation_temporality=Temporality,

apps/opentelemetry_experimental/src/otel_view.erl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,6 @@
4949
criteria/0,
5050
config/0]).
5151

52-
-eqwalizer({nowarn_function, maybe_init_meter/3}).
53-
5452
-include_lib("opentelemetry_api/include/gradualizer.hrl").
5553

5654
%% ignore dialyzer warnings in functions using matchspecs or related to those that do
@@ -182,6 +180,7 @@ criteria_to_instrument_matchspec(_) ->
182180
%% eqwalizer:ignore using ignore as an ets matchspec workaround
183181
ets:match_spec_compile([{#instrument{_='_'}, [], [true]}]).
184182

183+
%% eqwalizer:ignore using ignore as an ets matchspec workaround
185184
maybe_init_meter(#instrument{meter='_'}) ->
186185
%% eqwalizer:ignore using ignore as an ets matchspec workaround
187186
{'_', #meter{instrumentation_scope=#instrumentation_scope{_='_'},

apps/opentelemetry_experimental/test/otel_metrics_SUITE.erl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1774,7 +1774,7 @@ async_cumulative_page_faults(_Config) ->
17741774

17751775
CounterName = page_faults,
17761776
CounterDesc = <<"number of page faults">>,
1777-
CounterUnit = 1,
1777+
CounterUnit = '1',
17781778

17791779
?assert(otel_meter_server:add_view(#{instrument_name => CounterName},
17801780
#{aggregation_module => otel_aggregation_sum})),
@@ -1834,7 +1834,7 @@ async_delta_page_faults(_Config) ->
18341834

18351835
CounterName = page_faults,
18361836
CounterDesc = <<"number of page faults">>,
1837-
CounterUnit = 1,
1837+
CounterUnit = '1',
18381838

18391839
?assert(otel_meter_server:add_view(#{instrument_name => CounterName},
18401840
#{aggregation_module => otel_aggregation_sum})),
@@ -1915,7 +1915,7 @@ async_attribute_removal(_Config) ->
19151915

19161916
CounterName = page_faults,
19171917
CounterDesc = <<"number of page faults">>,
1918-
CounterUnit = 1,
1918+
CounterUnit = '1',
19191919

19201920
?assert(otel_meter_server:add_view(#{instrument_name => CounterName},
19211921
#{aggregation_module => otel_aggregation_sum,

0 commit comments

Comments
 (0)