From 53e892a2ca9f831fb09752f9ce223e26836163af Mon Sep 17 00:00:00 2001 From: Cijo Thomas Date: Tue, 26 Nov 2024 17:55:06 -0800 Subject: [PATCH] Nit fix by avoiding bound validation unless View feature is enabled (#2355) --- opentelemetry-sdk/src/metrics/internal/histogram.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/opentelemetry-sdk/src/metrics/internal/histogram.rs b/opentelemetry-sdk/src/metrics/internal/histogram.rs index f4690850a3..ac4a6806b7 100644 --- a/opentelemetry-sdk/src/metrics/internal/histogram.rs +++ b/opentelemetry-sdk/src/metrics/internal/histogram.rs @@ -74,9 +74,15 @@ pub(crate) struct Histogram { } impl Histogram { + #[allow(unused_mut)] pub(crate) fn new(mut bounds: Vec, record_min_max: bool, record_sum: bool) -> Self { - bounds.retain(|v| !v.is_nan()); - bounds.sort_by(|a, b| a.partial_cmp(b).expect("NaNs filtered out")); + #[cfg(feature = "spec_unstable_metrics_views")] + { + // TODO: When views are used, validate this upfront + bounds.retain(|v| !v.is_nan()); + bounds.sort_by(|a, b| a.partial_cmp(b).expect("NaNs filtered out")); + } + let buckets_count = bounds.len() + 1; Histogram { value_map: ValueMap::new(buckets_count),