Skip to content

Commit e17c397

Browse files
authored
opentelemetry-test-utils: assert explicit bucket boundaries in histogram metrics (#4595)
* opentelemetry-test-utils: assert explicit bucket boundaries in histogram metrics * Add changelog
1 parent b85775c commit e17c397

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1818
([#4333](https://github.com/open-telemetry/opentelemetry-python/pull/4333))
1919
- opentelemetry-api: allow importlib-metadata 8.7.0
2020
([#4593](https://github.com/open-telemetry/opentelemetry-python/pull/4593))
21+
- opentelemetry-test-utils: assert explicit bucket boundaries in histogram metrics
22+
([#4595](https://github.com/open-telemetry/opentelemetry-python/pull/4595))
2123

2224
## Version 1.33.0/0.54b0 (2025-05-09)
2325

tests/opentelemetry-test-utils/src/opentelemetry/test/test_base.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
from opentelemetry import metrics as metrics_api
2121
from opentelemetry import trace as trace_api
2222
from opentelemetry.sdk.metrics import MeterProvider
23+
from opentelemetry.sdk.metrics._internal.aggregation import (
24+
_DEFAULT_EXPLICIT_BUCKET_HISTOGRAM_AGGREGATION_BOUNDARIES,
25+
)
2326
from opentelemetry.sdk.metrics._internal.point import Metric
2427
from opentelemetry.sdk.metrics.export import (
2528
DataPointT,
@@ -204,6 +207,12 @@ def is_data_points_equal(
204207
):
205208
return False
206209

210+
if (
211+
expected_data_point.explicit_bounds
212+
!= data_point.explicit_bounds
213+
):
214+
return False
215+
207216
return (
208217
values_diff <= est_value_delta
209218
and expected_data_point.attributes == dict(data_point.attributes)
@@ -239,7 +248,12 @@ def create_number_data_point(value, attributes):
239248

240249
@staticmethod
241250
def create_histogram_data_point(
242-
sum_data_point, count, max_data_point, min_data_point, attributes
251+
sum_data_point,
252+
count,
253+
max_data_point,
254+
min_data_point,
255+
attributes,
256+
explicit_bounds=None,
243257
):
244258
return HistogramDataPoint(
245259
count=count,
@@ -250,7 +264,9 @@ def create_histogram_data_point(
250264
start_time_unix_nano=0,
251265
time_unix_nano=0,
252266
bucket_counts=[],
253-
explicit_bounds=[],
267+
explicit_bounds=explicit_bounds
268+
if explicit_bounds is not None
269+
else _DEFAULT_EXPLICIT_BUCKET_HISTOGRAM_AGGREGATION_BOUNDARIES,
254270
)
255271

256272

0 commit comments

Comments
 (0)