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,22 @@ 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
+
103
122
cls .sum_0 = Sum (
104
123
data_points = [cls .number_data_point_0 , cls .number_data_point_1 ],
105
124
aggregation_temporality = AggregationTemporality .DELTA ,
@@ -121,6 +140,14 @@ def setUpClass(cls):
121
140
)
122
141
cls .histogram_0_str = f'{{"data_points": [{ cls .histogram_data_point_0_str } , { cls .histogram_data_point_1_str } ], "aggregation_temporality": 1}}'
123
142
143
+ cls .exp_histogram_0 = ExponentialHistogram (
144
+ data_points = [
145
+ cls .exp_histogram_data_point_0 ,
146
+ ],
147
+ aggregation_temporality = AggregationTemporality .CUMULATIVE ,
148
+ )
149
+ cls .exp_histogram_0_str = f'{{"data_points": [{ cls .exp_histogram_data_point_0_str } ], "aggregation_temporality": 2}}'
150
+
124
151
cls .metric_0 = Metric (
125
152
name = "metric_0" ,
126
153
description = "description_0" ,
@@ -209,6 +236,15 @@ def test_histogram_data_point(self):
209
236
self .histogram_data_point_1_str ,
210
237
)
211
238
239
+ def test_exp_histogram_data_point (self ):
240
+
241
+ self .maxDiff = None
242
+
243
+ self .assertEqual (
244
+ self .exp_histogram_data_point_0 .to_json (indent = None ),
245
+ self .exp_histogram_data_point_0_str ,
246
+ )
247
+
212
248
def test_sum (self ):
213
249
214
250
self .assertEqual (self .sum_0 .to_json (indent = None ), self .sum_0_str )
@@ -225,6 +261,14 @@ def test_histogram(self):
225
261
self .histogram_0 .to_json (indent = None ), self .histogram_0_str
226
262
)
227
263
264
+ def test_exp_histogram (self ):
265
+
266
+ self .maxDiff = None
267
+
268
+ self .assertEqual (
269
+ self .exp_histogram_0 .to_json (indent = None ), self .exp_histogram_0_str
270
+ )
271
+
228
272
def test_metric (self ):
229
273
230
274
self .assertEqual (self .metric_0 .to_json (indent = None ), self .metric_0_str )
0 commit comments