@@ -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,11 @@ 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 ,
21
+ from_lib: "opentelemetry_experimental/include/otel_metrics.hrl"
22
+ )
23
+ Record . defrecordp ( :histogram , @ fields )
24
+
19
25
setup do
20
26
Application . load ( :opentelemetry_experimental )
21
27
Application . load ( :opentelemetry )
@@ -34,7 +40,7 @@ defmodule OtelMetricTests do
34
40
observable_counter: :temporality_cumulative ,
35
41
updown_counter: :temporality_delta ,
36
42
observable_updowncounter: :temporality_cumulative ,
37
- histogram: :temporality_delta ,
43
+ histogram: :temporality_cumulative ,
38
44
observable_gauge: :temporality_cumulative
39
45
}
40
46
}
@@ -97,4 +103,75 @@ defmodule OtelMetricTests do
97
103
data: sum ( datapoints: [ datapoint ( value: 9 ) ] )
98
104
) }
99
105
end
106
+
107
+ test "create Histogram with macros" do
108
+ Histogram . create ( :histogram_a , % { unit: "1" , description: "some histogram_a" } )
109
+ Histogram . record ( :histogram_a , 1 )
110
+
111
+ :otel_meter_server . force_flush ( )
112
+
113
+ assert_receive { :metric ,
114
+ metric (
115
+ name: :histogram_a ,
116
+ data:
117
+ histogram (
118
+ aggregation_temporality: :temporality_cumulative ,
119
+ datapoints: [
120
+ { :histogram_datapoint , % { } , _ , _ , 1 , 1 ,
121
+ [ 0 , 1 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ] ,
122
+ [
123
+ 0.0 ,
124
+ 5.0 ,
125
+ 10.0 ,
126
+ 25.0 ,
127
+ 50.0 ,
128
+ 75.0 ,
129
+ 100.0 ,
130
+ 250.0 ,
131
+ 500.0 ,
132
+ 750.0 ,
133
+ 1000.0 ,
134
+ 2500.0 ,
135
+ 5000.0 ,
136
+ 7500.0 ,
137
+ 10000.0
138
+ ] , [ ] , 0 , 1 , 1 }
139
+ ]
140
+ )
141
+ ) }
142
+
143
+ Histogram . record ( :histogram_a , 10 )
144
+
145
+ :otel_meter_server . force_flush ( )
146
+
147
+ assert_receive { :metric ,
148
+ metric (
149
+ name: :histogram_a ,
150
+ data:
151
+ histogram (
152
+ aggregation_temporality: :temporality_cumulative ,
153
+ datapoints: [
154
+ { :histogram_datapoint , % { } , _ , _ , 2 , 11 ,
155
+ [ 0 , 1 , 1 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ] ,
156
+ [
157
+ 0.0 ,
158
+ 5.0 ,
159
+ 10.0 ,
160
+ 25.0 ,
161
+ 50.0 ,
162
+ 75.0 ,
163
+ 100.0 ,
164
+ 250.0 ,
165
+ 500.0 ,
166
+ 750.0 ,
167
+ 1000.0 ,
168
+ 2500.0 ,
169
+ 5000.0 ,
170
+ 7500.0 ,
171
+ 10000.0
172
+ ] , [ ] , 0 , 1 , 10 }
173
+ ]
174
+ )
175
+ ) }
176
+ end
100
177
end
0 commit comments