Skip to content

Commit 7c3c32b

Browse files
author
Samuel Shen
committed
[BugFix] Fix test_l2 crash on HistogramDataPoint without .value
_read_counters() iterates all metrics from the InMemoryMetricReader, not just counters. When another library registers a histogram on the same MeterProvider, the reader returns HistogramDataPoint objects which lack .value (they have .sum/.count instead). Guard with hasattr. Signed-off-by: Samuel Shen <slshen@uchciago.edu>
1 parent 65df38f commit 7c3c32b

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

  • tests/v1/mp_observability/subscribers/metrics

tests/v1/mp_observability/subscribers/metrics/test_l2.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,11 @@ def _read_counters() -> dict[str, int]:
5353
for scope_metrics in resource_metrics.scope_metrics:
5454
for metric in scope_metrics.metrics:
5555
for dp in metric.data.data_points:
56-
result[metric.name] = int(dp.value)
56+
# Only counter/sum data points have .value;
57+
# skip histograms and other types that may be
58+
# registered on the same MeterProvider.
59+
if hasattr(dp, "value"):
60+
result[metric.name] = int(dp.value)
5761
return result
5862

5963

0 commit comments

Comments
 (0)