16
16
17
17
from opentelemetry .sdk .metrics .export import (
18
18
AggregationTemporality ,
19
+ Buckets ,
20
+ ExponentialHistogram ,
21
+ ExponentialHistogramDataPoint ,
19
22
Gauge ,
20
23
Histogram ,
21
24
HistogramDataPoint ,
@@ -100,6 +103,23 @@ def setUpClass(cls):
100
103
)
101
104
cls .histogram_data_point_1_str = f'{{"attributes": { cls .attributes_1_str } , "start_time_unix_nano": 2, "time_unix_nano": 3, "count": 4, "sum": 4.4, "bucket_counts": [2, 1, 1], "explicit_bounds": [1.2, 2.3, 3.4, 4.5], "min": 0.3, "max": 4.4}}'
102
105
106
+ cls .exp_histogram_data_point_0 = ExponentialHistogramDataPoint (
107
+ attributes = cls .attributes_0 ,
108
+ start_time_unix_nano = 1 ,
109
+ time_unix_nano = 2 ,
110
+ count = 1 ,
111
+ sum = 10 ,
112
+ scale = 1 ,
113
+ zero_count = 0 ,
114
+ positive = Buckets (offset = 0 , bucket_counts = [1 ]),
115
+ negative = Buckets (offset = 0 , bucket_counts = [0 ]),
116
+ flags = 0 ,
117
+ min = 10 ,
118
+ max = 10 ,
119
+ )
120
+ cls .exp_histogram_data_point_0_str = f'{{"attributes": { cls .attributes_0_str } , "start_time_unix_nano": 1, "time_unix_nano": 2, "count": 1, "sum": 10, "scale": 1, "zero_count": 0, "positive": {{"offset": 0, "bucket_counts": [1]}}, "negative": {{"offset": 0, "bucket_counts": [0]}}, "flags": 0, "min": 10, "max": 10}}'
121
+
122
+
103
123
cls .sum_0 = Sum (
104
124
data_points = [cls .number_data_point_0 , cls .number_data_point_1 ],
105
125
aggregation_temporality = AggregationTemporality .DELTA ,
@@ -121,6 +141,15 @@ def setUpClass(cls):
121
141
)
122
142
cls .histogram_0_str = f'{{"data_points": [{ cls .histogram_data_point_0_str } , { cls .histogram_data_point_1_str } ], "aggregation_temporality": 1}}'
123
143
144
+ cls .exp_histogram_0 = ExponentialHistogram (
145
+ data_points = [
146
+ cls .exp_histogram_data_point_0 ,
147
+ ],
148
+ aggregation_temporality = AggregationTemporality .CUMULATIVE ,
149
+ )
150
+ cls .exp_histogram_0_str = f'{{"data_points": [{ cls .exp_histogram_data_point_0_str } ], "aggregation_temporality": 2}}'
151
+
152
+
124
153
cls .metric_0 = Metric (
125
154
name = "metric_0" ,
126
155
description = "description_0" ,
@@ -209,6 +238,15 @@ def test_histogram_data_point(self):
209
238
self .histogram_data_point_1_str ,
210
239
)
211
240
241
+ def test_exp_histogram_data_point (self ):
242
+
243
+ self .maxDiff = None
244
+
245
+ self .assertEqual (
246
+ self .exp_histogram_data_point_0 .to_json (indent = None ),
247
+ self .exp_histogram_data_point_0_str ,
248
+ )
249
+
212
250
def test_sum (self ):
213
251
214
252
self .assertEqual (self .sum_0 .to_json (indent = None ), self .sum_0_str )
@@ -225,6 +263,14 @@ def test_histogram(self):
225
263
self .histogram_0 .to_json (indent = None ), self .histogram_0_str
226
264
)
227
265
266
+ def test_exp_histogram (self ):
267
+
268
+ self .maxDiff = None
269
+
270
+ self .assertEqual (
271
+ self .exp_histogram_0 .to_json (indent = None ), self .exp_histogram_0_str
272
+ )
273
+
228
274
def test_metric (self ):
229
275
230
276
self .assertEqual (self .metric_0 .to_json (indent = None ), self .metric_0_str )
0 commit comments