@@ -3,6 +3,7 @@ defmodule OtelMetricTests do
3
3
4
4
require OpenTelemetryAPIExperimental.Counter , as: Counter
5
5
require OpenTelemetryAPIExperimental.UpDownCounter , as: UpDownCounter
6
+ require OpenTelemetryAPIExperimental.Histogram , as: Histogram
6
7
7
8
require Record
8
9
@ fields Record . extract ( :metric , from_lib: "opentelemetry_experimental/include/otel_metrics.hrl" )
@@ -16,6 +17,9 @@ defmodule OtelMetricTests do
16
17
@ fields Record . extract ( :sum , from_lib: "opentelemetry_experimental/include/otel_metrics.hrl" )
17
18
Record . defrecordp ( :sum , @ fields )
18
19
20
+ @ fields Record . extract ( :histogram , from_lib: "opentelemetry_experimental/include/otel_metrics.hrl" )
21
+ Record . defrecordp ( :histogram , @ fields )
22
+
19
23
setup do
20
24
Application . load ( :opentelemetry_experimental )
21
25
Application . load ( :opentelemetry )
@@ -34,7 +38,7 @@ defmodule OtelMetricTests do
34
38
observable_counter: :temporality_cumulative ,
35
39
updown_counter: :temporality_delta ,
36
40
observable_updowncounter: :temporality_cumulative ,
37
- histogram: :temporality_delta ,
41
+ histogram: :temporality_cumulative ,
38
42
observable_gauge: :temporality_cumulative
39
43
}
40
44
}
@@ -97,4 +101,32 @@ defmodule OtelMetricTests do
97
101
data: sum ( datapoints: [ datapoint ( value: 9 ) ] )
98
102
) }
99
103
end
104
+
105
+ test "create Histogram with macros" do
106
+ Histogram . create ( :histogram_a , % { unit: "1" , description: "some histogram_a" } )
107
+ Histogram . record ( :histogram_a , 1 )
108
+
109
+ :otel_meter_server . force_flush ( )
110
+
111
+ assert_receive { :metric ,
112
+ metric (
113
+ name: :histogram_a ,
114
+ data: histogram ( aggregation_temporality: :temporality_cumulative ,
115
+ datapoints: [ { :histogram_datapoint , % { } , _ , _ , 1 , 1 , [ 0 , 1 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ] ,
116
+ [ 0.0 , 5.0 , 10.0 , 25.0 , 50.0 , 75.0 , 100.0 , 250.0 , 500.0 , 750.0 , 1000.0 , 2500.0 , 5000.0 , 7500.0 , 10000.0 ] , [ ] , 0 , 1 , 1 } ] )
117
+ ) }
118
+
119
+ Histogram . record ( :histogram_a , 10 )
120
+
121
+ :otel_meter_server . force_flush ( )
122
+
123
+ assert_receive { :metric ,
124
+ metric (
125
+ name: :histogram_a ,
126
+ data: histogram ( aggregation_temporality: :temporality_cumulative ,
127
+ datapoints: [ { :histogram_datapoint , % { } , _ , _ , 2 , 11 , [ 0 , 1 , 1 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ] ,
128
+ [ 0.0 , 5.0 , 10.0 , 25.0 , 50.0 , 75.0 , 100.0 , 250.0 , 500.0 , 750.0 , 1000.0 , 2500.0 , 5000.0 , 7500.0 , 10000.0 ] , [ ] , 0 , 1 , 10 } ] )
129
+ ) }
130
+ end
131
+
100
132
end
0 commit comments