Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .changelog/5461.fixed
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Reject views with `ExponentialBucketHistogramAggregation` for asynchronous
instruments instead of silently producing no data
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
Aggregation,
AggregationTemporality,
ExplicitBucketHistogramAggregation,
ExponentialBucketHistogramAggregation,
_DropAggregation,
_ExplicitBucketHistogramAggregation,
_ExponentialBucketHistogramAggregation,
Expand Down Expand Up @@ -293,7 +294,11 @@ def _check_view_instrument_compatibility(

# pylint: disable=protected-access
if isinstance(instrument, Asynchronous) and isinstance(
view._aggregation, ExplicitBucketHistogramAggregation
view._aggregation,
(
ExplicitBucketHistogramAggregation,
ExponentialBucketHistogramAggregation,
),
):
_logger.warning(
"View %s and instrument %s will produce "
Expand Down
40 changes: 40 additions & 0 deletions opentelemetry-sdk/tests/metrics/test_metric_reader_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
DefaultAggregation,
DropAggregation,
ExplicitBucketHistogramAggregation,
ExponentialBucketHistogramAggregation,
SumAggregation,
View,
)
Expand Down Expand Up @@ -453,6 +454,45 @@ def test_conflicting_view_configuration(self):
_DEFAULT_VIEW,
)

def test_conflicting_view_configuration_exponential_histogram(self):
observable_counter = _ObservableCounter(
"observable_counter",
Mock(),
[Mock()],
unit="unit",
description="description",
)
metric_reader_storage = MetricReaderStorage(
SdkConfiguration(
exemplar_filter=Mock(),
resource=Mock(),
views=(
View(
instrument_name="observable_counter",
aggregation=ExponentialBucketHistogramAggregation(),
),
),
),
MagicMock(
**{
"__getitem__.return_value": AggregationTemporality.CUMULATIVE
}
),
MagicMock(**{"__getitem__.return_value": DefaultAggregation()}),
)

with self.assertLogs(level=WARNING):
metric_reader_storage.consume_measurement(
Measurement(1, time_ns(), observable_counter, Context())
)

self.assertIs(
metric_reader_storage._instrument_view_instrument_matches[
observable_counter
][0]._view,
_DEFAULT_VIEW,
)

def test_view_instrument_match_conflict_0(self):
# There is a conflict between views and instruments.

Expand Down
Loading