From d41044b2e498b98b76315eb54047d1042179fd02 Mon Sep 17 00:00:00 2001 From: Cijo Thomas Date: Thu, 22 May 2025 14:10:02 -0700 Subject: [PATCH 01/13] Remove pub fields and replace with getter method consistently across metrics --- opentelemetry-sdk/src/metrics/data/mod.rs | 220 +++++++++++++++++++--- 1 file changed, 195 insertions(+), 25 deletions(-) diff --git a/opentelemetry-sdk/src/metrics/data/mod.rs b/opentelemetry-sdk/src/metrics/data/mod.rs index 10899cfed6..3cefca5383 100644 --- a/opentelemetry-sdk/src/metrics/data/mod.rs +++ b/opentelemetry-sdk/src/metrics/data/mod.rs @@ -184,6 +184,11 @@ impl GaugeDataPoint { pub fn exemplars(&self) -> impl Iterator> { self.exemplars.iter() } + + /// Returns the value of this data point. + pub fn value(&self) -> &T { + &self.value + } } /// A measurement of the current value of an instrument. @@ -202,6 +207,16 @@ impl Gauge { pub fn data_points(&self) -> impl Iterator> { self.data_points.iter() } + + /// Returns the time when the time series was started. + pub fn start_time(&self) -> Option { + self.start_time + } + + /// Returns the time when the time series was recorded. + pub fn time(&self) -> SystemTime { + self.time + } } /// DataPoint is a single data point in a time series. @@ -226,6 +241,11 @@ impl SumDataPoint { pub fn exemplars(&self) -> impl Iterator> { self.exemplars.iter() } + + /// Returns the value of this data point. + pub fn value(&self) -> &T { + &self.value + } } /// Represents the sum of all measurements of values from an instrument. @@ -234,14 +254,14 @@ pub struct Sum { /// Represents individual aggregated measurements with unique attributes. pub(crate) data_points: Vec>, /// The time when the time series was started. - pub start_time: SystemTime, + pub(crate) start_time: SystemTime, /// The time when the time series was recorded. - pub time: SystemTime, + pub(crate) time: SystemTime, /// Describes if the aggregation is reported as the change from the last report /// time, or the cumulative changes since a fixed start time. - pub temporality: Temporality, + pub(crate) temporality: Temporality, /// Whether this aggregation only increases or decreases. - pub is_monotonic: bool, + pub(crate) is_monotonic: bool, } impl Sum { @@ -249,6 +269,27 @@ impl Sum { pub fn data_points(&self) -> impl Iterator> { self.data_points.iter() } + + /// Returns the time when the time series was started. + pub fn start_time(&self) -> SystemTime { + self.start_time + } + + /// Returns the time when the time series was recorded. + pub fn time(&self) -> SystemTime { + self.time + } + + /// Returns the temporality describing if the aggregation is reported as the change + /// from the last report time, or the cumulative changes since a fixed start time. + pub fn temporality(&self) -> Temporality { + self.temporality + } + + /// Returns whether this aggregation only increases or decreases. + pub fn is_monotonic(&self) -> bool { + self.is_monotonic + } } /// Represents the histogram of all measurements of values from an instrument. @@ -257,12 +298,12 @@ pub struct Histogram { /// Individual aggregated measurements with unique attributes. pub(crate) data_points: Vec>, /// The time when the time series was started. - pub start_time: SystemTime, + pub(crate) start_time: SystemTime, /// The time when the time series was recorded. - pub time: SystemTime, + pub(crate) time: SystemTime, /// Describes if the aggregation is reported as the change from the last report /// time, or the cumulative changes since a fixed start time. - pub temporality: Temporality, + pub(crate) temporality: Temporality, } impl Histogram { @@ -270,6 +311,22 @@ impl Histogram { pub fn data_points(&self) -> impl Iterator> { self.data_points.iter() } + + /// Returns the time when the time series was started. + pub fn start_time(&self) -> SystemTime { + self.start_time + } + + /// Returns the time when the time series was recorded. + pub fn time(&self) -> SystemTime { + self.time + } + + /// Returns the temporality describing if the aggregation is reported as the change + /// from the last report time, or the cumulative changes since a fixed start time. + pub fn temporality(&self) -> Temporality { + self.temporality + } } /// A single histogram data point in a time series. @@ -278,7 +335,7 @@ pub struct HistogramDataPoint { /// The set of key value pairs that uniquely identify the time series. pub(crate) attributes: Vec, /// The number of updates this histogram has been calculated with. - pub count: u64, + pub(crate) count: u64, /// The upper bounds of the buckets of the histogram. /// /// Because the last boundary is +infinity this one is implied. @@ -287,11 +344,11 @@ pub struct HistogramDataPoint { pub(crate) bucket_counts: Vec, /// The minimum value recorded. - pub min: Option, + pub(crate) min: Option, /// The maximum value recorded. - pub max: Option, + pub(crate) max: Option, /// The sum of the values recorded. - pub sum: T, + pub(crate) sum: T, /// The sampled [Exemplar]s collected during the time series. pub(crate) exemplars: Vec>, @@ -317,6 +374,26 @@ impl HistogramDataPoint { pub fn bucket_counts(&self) -> impl Iterator + '_ { self.bucket_counts.iter().copied() } + + /// Returns the number of updates this histogram has been calculated with. + pub fn count(&self) -> u64 { + self.count + } + + /// Returns the minimum value recorded. + pub fn min(&self) -> Option<&T> { + self.min.as_ref() + } + + /// Returns the maximum value recorded. + pub fn max(&self) -> Option<&T> { + self.max.as_ref() + } + + /// Returns the sum of the values recorded. + pub fn sum(&self) -> &T { + &self.sum + } } /// The histogram of all measurements of values from an instrument. @@ -325,12 +402,12 @@ pub struct ExponentialHistogram { /// The individual aggregated measurements with unique attributes. pub(crate) data_points: Vec>, /// When the time series was started. - pub start_time: SystemTime, + pub(crate) start_time: SystemTime, /// The time when the time series was recorded. - pub time: SystemTime, + pub(crate) time: SystemTime, /// Describes if the aggregation is reported as the change from the last report /// time, or the cumulative changes since a fixed start time. - pub temporality: Temporality, + pub(crate) temporality: Temporality, } impl ExponentialHistogram { @@ -338,6 +415,22 @@ impl ExponentialHistogram { pub fn data_points(&self) -> impl Iterator> { self.data_points.iter() } + + /// Returns the time when the time series was started. + pub fn start_time(&self) -> SystemTime { + self.start_time + } + + /// Returns the time when the time series was recorded. + pub fn time(&self) -> SystemTime { + self.time + } + + /// Returns the temporality describing if the aggregation is reported as the change + /// from the last report time, or the cumulative changes since a fixed start time. + pub fn temporality(&self) -> Temporality { + self.temporality + } } /// A single exponential histogram data point in a time series. @@ -347,20 +440,20 @@ pub struct ExponentialHistogramDataPoint { pub(crate) attributes: Vec, /// The number of updates this histogram has been calculated with. - pub count: usize, + pub(crate) count: usize, /// The minimum value recorded. - pub min: Option, + pub(crate) min: Option, /// The maximum value recorded. - pub max: Option, + pub(crate) max: Option, /// The sum of the values recorded. - pub sum: T, + pub(crate) sum: T, /// Describes the resolution of the histogram. /// /// Boundaries are located at powers of the base, where: /// /// base = 2 ^ (2 ^ -scale) - pub scale: i8, + pub(crate) scale: i8, /// The number of values whose absolute value is less than or equal to /// `zero_threshold`. @@ -368,18 +461,18 @@ pub struct ExponentialHistogramDataPoint { /// When `zero_threshold` is `0`, this is the number of values that cannot be /// expressed using the standard exponential formula as well as values that have /// been rounded to zero. - pub zero_count: u64, + pub(crate) zero_count: u64, /// The range of positive value bucket counts. - pub positive_bucket: ExponentialBucket, + pub(crate) positive_bucket: ExponentialBucket, /// The range of negative value bucket counts. - pub negative_bucket: ExponentialBucket, + pub(crate) negative_bucket: ExponentialBucket, /// The width of the zero region. /// /// Where the zero region is defined as the closed interval /// [-zero_threshold, zero_threshold]. - pub zero_threshold: f64, + pub(crate) zero_threshold: f64, /// The sampled exemplars collected during the time series. pub(crate) exemplars: Vec>, @@ -395,19 +488,76 @@ impl ExponentialHistogramDataPoint { pub fn exemplars(&self) -> impl Iterator> { self.exemplars.iter() } + + /// Returns the number of updates this histogram has been calculated with. + pub fn count(&self) -> usize { + self.count + } + + /// Returns the minimum value recorded. + pub fn min(&self) -> Option<&T> { + self.min.as_ref() + } + + /// Returns the maximum value recorded. + pub fn max(&self) -> Option<&T> { + self.max.as_ref() + } + + /// Returns the sum of the values recorded. + pub fn sum(&self) -> &T { + &self.sum + } + + /// Returns the resolution of the histogram. + pub fn scale(&self) -> i8 { + self.scale + } + + /// Returns the number of values whose absolute value is less than or equal to zero_threshold. + pub fn zero_count(&self) -> u64 { + self.zero_count + } + + /// Returns the range of positive value bucket counts. + pub fn positive_bucket(&self) -> &ExponentialBucket { + &self.positive_bucket + } + + /// Returns the range of negative value bucket counts. + pub fn negative_bucket(&self) -> &ExponentialBucket { + &self.negative_bucket + } + + /// Returns the width of the zero region. + pub fn zero_threshold(&self) -> f64 { + self.zero_threshold + } } /// A set of bucket counts, encoded in a contiguous array of counts. #[derive(Debug, Clone, PartialEq)] pub struct ExponentialBucket { /// The bucket index of the first entry in the `counts` vec. - pub offset: i32, + pub(crate) offset: i32, /// A vec where `counts[i]` carries the count of the bucket at index `offset + i`. /// /// `counts[i]` is the count of values greater than base^(offset+i) and less than /// or equal to base^(offset+i+1). - pub counts: Vec, + pub(crate) counts: Vec, +} + +impl ExponentialBucket { + /// Returns the bucket index of the first entry in the counts vec. + pub fn offset(&self) -> i32 { + self.offset + } + + /// Returns a reference to the counts vec. + pub fn counts(&self) -> &[u64] { + &self.counts + } } /// A measurement sampled from a time series providing a typical example. @@ -435,6 +585,26 @@ impl Exemplar { pub fn filtered_attributes(&self) -> impl Iterator { self.filtered_attributes.iter() } + + /// Returns the time when the measurement was recorded. + pub fn time(&self) -> SystemTime { + self.time + } + + /// Returns the measured value. + pub fn value(&self) -> &T { + &self.value + } + + /// Returns the ID of the span that was active during the measurement. + pub fn span_id(&self) -> &[u8; 8] { + &self.span_id + } + + /// Returns the ID of the trace the active span belonged to during the measurement. + pub fn trace_id(&self) -> &[u8; 16] { + &self.trace_id + } } #[cfg(test)] From 02dee0f5747f8ae9f73b362df073d35a4ca9b9db Mon Sep 17 00:00:00 2001 From: Cijo Thomas Date: Thu, 22 May 2025 14:13:35 -0700 Subject: [PATCH 02/13] gauge --- opentelemetry-sdk/src/metrics/data/mod.rs | 58 +++++++++++------------ 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/opentelemetry-sdk/src/metrics/data/mod.rs b/opentelemetry-sdk/src/metrics/data/mod.rs index 3cefca5383..ac26699af0 100644 --- a/opentelemetry-sdk/src/metrics/data/mod.rs +++ b/opentelemetry-sdk/src/metrics/data/mod.rs @@ -169,7 +169,7 @@ pub struct GaugeDataPoint { /// time series. pub(crate) attributes: Vec, /// The value of this data point. - pub value: T, + pub(crate) value: T, /// The sampled [Exemplar]s collected during the time series. pub(crate) exemplars: Vec>, } @@ -226,7 +226,7 @@ pub struct SumDataPoint { /// time series. pub(crate) attributes: Vec, /// The value of this data point. - pub value: T, + pub(crate) value: T, /// The sampled [Exemplar]s collected during the time series. pub(crate) exemplars: Vec>, } @@ -269,23 +269,23 @@ impl Sum { pub fn data_points(&self) -> impl Iterator> { self.data_points.iter() } - + /// Returns the time when the time series was started. pub fn start_time(&self) -> SystemTime { self.start_time } - + /// Returns the time when the time series was recorded. pub fn time(&self) -> SystemTime { self.time } - - /// Returns the temporality describing if the aggregation is reported as the change + + /// Returns the temporality describing if the aggregation is reported as the change /// from the last report time, or the cumulative changes since a fixed start time. pub fn temporality(&self) -> Temporality { self.temporality } - + /// Returns whether this aggregation only increases or decreases. pub fn is_monotonic(&self) -> bool { self.is_monotonic @@ -311,18 +311,18 @@ impl Histogram { pub fn data_points(&self) -> impl Iterator> { self.data_points.iter() } - + /// Returns the time when the time series was started. pub fn start_time(&self) -> SystemTime { self.start_time } - + /// Returns the time when the time series was recorded. pub fn time(&self) -> SystemTime { self.time } - - /// Returns the temporality describing if the aggregation is reported as the change + + /// Returns the temporality describing if the aggregation is reported as the change /// from the last report time, or the cumulative changes since a fixed start time. pub fn temporality(&self) -> Temporality { self.temporality @@ -374,22 +374,22 @@ impl HistogramDataPoint { pub fn bucket_counts(&self) -> impl Iterator + '_ { self.bucket_counts.iter().copied() } - + /// Returns the number of updates this histogram has been calculated with. pub fn count(&self) -> u64 { self.count } - + /// Returns the minimum value recorded. pub fn min(&self) -> Option<&T> { self.min.as_ref() } - + /// Returns the maximum value recorded. pub fn max(&self) -> Option<&T> { self.max.as_ref() } - + /// Returns the sum of the values recorded. pub fn sum(&self) -> &T { &self.sum @@ -415,18 +415,18 @@ impl ExponentialHistogram { pub fn data_points(&self) -> impl Iterator> { self.data_points.iter() } - + /// Returns the time when the time series was started. pub fn start_time(&self) -> SystemTime { self.start_time } - + /// Returns the time when the time series was recorded. pub fn time(&self) -> SystemTime { self.time } - - /// Returns the temporality describing if the aggregation is reported as the change + + /// Returns the temporality describing if the aggregation is reported as the change /// from the last report time, or the cumulative changes since a fixed start time. pub fn temporality(&self) -> Temporality { self.temporality @@ -488,47 +488,47 @@ impl ExponentialHistogramDataPoint { pub fn exemplars(&self) -> impl Iterator> { self.exemplars.iter() } - + /// Returns the number of updates this histogram has been calculated with. pub fn count(&self) -> usize { self.count } - + /// Returns the minimum value recorded. pub fn min(&self) -> Option<&T> { self.min.as_ref() } - + /// Returns the maximum value recorded. pub fn max(&self) -> Option<&T> { self.max.as_ref() } - + /// Returns the sum of the values recorded. pub fn sum(&self) -> &T { &self.sum } - + /// Returns the resolution of the histogram. pub fn scale(&self) -> i8 { self.scale } - + /// Returns the number of values whose absolute value is less than or equal to zero_threshold. pub fn zero_count(&self) -> u64 { self.zero_count } - + /// Returns the range of positive value bucket counts. pub fn positive_bucket(&self) -> &ExponentialBucket { &self.positive_bucket } - + /// Returns the range of negative value bucket counts. pub fn negative_bucket(&self) -> &ExponentialBucket { &self.negative_bucket } - + /// Returns the width of the zero region. pub fn zero_threshold(&self) -> f64 { self.zero_threshold @@ -553,7 +553,7 @@ impl ExponentialBucket { pub fn offset(&self) -> i32 { self.offset } - + /// Returns a reference to the counts vec. pub fn counts(&self) -> &[u64] { &self.counts From 49d389b3cd905cc8c7bada066cd325c721dc8ddc Mon Sep 17 00:00:00 2001 From: Cijo Thomas Date: Thu, 22 May 2025 14:17:20 -0700 Subject: [PATCH 03/13] few more --- opentelemetry-sdk/src/metrics/data/mod.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/opentelemetry-sdk/src/metrics/data/mod.rs b/opentelemetry-sdk/src/metrics/data/mod.rs index ac26699af0..ab8a3adb6f 100644 --- a/opentelemetry-sdk/src/metrics/data/mod.rs +++ b/opentelemetry-sdk/src/metrics/data/mod.rs @@ -197,9 +197,9 @@ pub struct Gauge { /// Represents individual aggregated measurements with unique attributes. pub(crate) data_points: Vec>, /// The time when the time series was started. - pub start_time: Option, + pub(crate) start_time: Option, /// The time when the time series was recorded. - pub time: SystemTime, + pub(crate) time: SystemTime, } impl Gauge { @@ -567,17 +567,17 @@ pub struct Exemplar { /// time series' aggregated data. pub(crate) filtered_attributes: Vec, /// The time when the measurement was recorded. - pub time: SystemTime, + pub(crate) time: SystemTime, /// The measured value. - pub value: T, + pub(crate) value: T, /// The ID of the span that was active during the measurement. /// /// If no span was active or the span was not sampled this will be empty. - pub span_id: [u8; 8], + pub(crate) span_id: [u8; 8], /// The ID of the trace the active span belonged to during the measurement. /// /// If no span was active or the span was not sampled this will be empty. - pub trace_id: [u8; 16], + pub(crate) trace_id: [u8; 16], } impl Exemplar { From 10f4f8c0ff9ace3298c271d70b120abff6f73188 Mon Sep 17 00:00:00 2001 From: Cijo Thomas Date: Thu, 22 May 2025 14:22:17 -0700 Subject: [PATCH 04/13] fix stdout --- opentelemetry-stdout/src/metrics/exporter.rs | 30 ++++++++++---------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/opentelemetry-stdout/src/metrics/exporter.rs b/opentelemetry-stdout/src/metrics/exporter.rs index 995d883e45..d1623e9f10 100644 --- a/opentelemetry-stdout/src/metrics/exporter.rs +++ b/opentelemetry-stdout/src/metrics/exporter.rs @@ -137,18 +137,18 @@ fn print_metrics<'a>(metrics: impl Iterator) { fn print_sum(sum: &Sum) { println!("\t\tSum DataPoints"); - println!("\t\tMonotonic : {}", sum.is_monotonic); - if sum.temporality == Temporality::Cumulative { + println!("\t\tMonotonic : {}", sum.is_monotonic()); + if sum.temporality() == Temporality::Cumulative { println!("\t\tTemporality : Cumulative"); } else { println!("\t\tTemporality : Delta"); } - let datetime: DateTime = sum.start_time.into(); + let datetime: DateTime = sum.start_time().into(); println!( "\t\tStartTime : {}", datetime.format("%Y-%m-%d %H:%M:%S%.6f") ); - let datetime: DateTime = sum.time.into(); + let datetime: DateTime = sum.time().into(); println!( "\t\tEndTime : {}", datetime.format("%Y-%m-%d %H:%M:%S%.6f") @@ -158,14 +158,14 @@ fn print_sum(sum: &Sum) { fn print_gauge(gauge: &Gauge) { println!("\t\tGauge DataPoints"); - if let Some(start_time) = gauge.start_time { + if let Some(start_time) = gauge.start_time() { let datetime: DateTime = start_time.into(); println!( "\t\tStartTime : {}", datetime.format("%Y-%m-%d %H:%M:%S%.6f") ); } - let datetime: DateTime = gauge.time.into(); + let datetime: DateTime = gauge.time().into(); println!( "\t\tEndTime : {}", datetime.format("%Y-%m-%d %H:%M:%S%.6f") @@ -174,17 +174,17 @@ fn print_gauge(gauge: &Gauge) { } fn print_histogram(histogram: &Histogram) { - if histogram.temporality == Temporality::Cumulative { + if histogram.temporality() == Temporality::Cumulative { println!("\t\tTemporality : Cumulative"); } else { println!("\t\tTemporality : Delta"); } - let datetime: DateTime = histogram.start_time.into(); + let datetime: DateTime = histogram.start_time().into(); println!( "\t\tStartTime : {}", datetime.format("%Y-%m-%d %H:%M:%S%.6f") ); - let datetime: DateTime = histogram.time.into(); + let datetime: DateTime = histogram.time().into(); println!( "\t\tEndTime : {}", datetime.format("%Y-%m-%d %H:%M:%S%.6f") @@ -198,7 +198,7 @@ fn print_sum_data_points<'a, T: Debug + 'a>( ) { for (i, data_point) in data_points.enumerate() { println!("\t\tDataPoint #{}", i); - println!("\t\t\tValue : {:#?}", data_point.value); + println!("\t\t\tValue : {:#?}", data_point.value()); println!("\t\t\tAttributes :"); for kv in data_point.attributes() { println!("\t\t\t\t -> {}: {}", kv.key, kv.value.as_str()); @@ -211,7 +211,7 @@ fn print_gauge_data_points<'a, T: Debug + 'a>( ) { for (i, data_point) in data_points.enumerate() { println!("\t\tDataPoint #{}", i); - println!("\t\t\tValue : {:#?}", data_point.value); + println!("\t\t\tValue : {:#?}", data_point.value()); println!("\t\t\tAttributes :"); for kv in data_point.attributes() { println!("\t\t\t\t -> {}: {}", kv.key, kv.value.as_str()); @@ -224,13 +224,13 @@ fn print_hist_data_points<'a, T: Debug + 'a>( ) { for (i, data_point) in data_points.enumerate() { println!("\t\tDataPoint #{}", i); - println!("\t\t\tCount : {}", data_point.count); - println!("\t\t\tSum : {:?}", data_point.sum); - if let Some(min) = &data_point.min { + println!("\t\t\tCount : {}", data_point.count()); + println!("\t\t\tSum : {:?}", data_point.sum()); + if let Some(min) = data_point.min() { println!("\t\t\tMin : {:?}", min); } - if let Some(max) = &data_point.max { + if let Some(max) = data_point.max() { println!("\t\t\tMax : {:?}", max); } From 402351adf64615d761e5429fdf5a1bcef7985256 Mon Sep 17 00:00:00 2001 From: Cijo Thomas Date: Thu, 22 May 2025 15:05:37 -0700 Subject: [PATCH 05/13] revert simple nums --- opentelemetry-proto/src/transform/metrics.rs | 52 ++++++++++---------- opentelemetry-sdk/src/metrics/data/mod.rs | 49 +++--------------- opentelemetry-stdout/src/metrics/exporter.rs | 8 +-- 3 files changed, 37 insertions(+), 72 deletions(-) diff --git a/opentelemetry-proto/src/transform/metrics.rs b/opentelemetry-proto/src/transform/metrics.rs index 391cb031d9..a97bc5f040 100644 --- a/opentelemetry-proto/src/transform/metrics.rs +++ b/opentelemetry-proto/src/transform/metrics.rs @@ -215,10 +215,10 @@ pub mod tonic { .data_points() .map(|dp| TonicHistogramDataPoint { attributes: dp.attributes().map(Into::into).collect(), - start_time_unix_nano: to_nanos(hist.start_time), - time_unix_nano: to_nanos(hist.time), - count: dp.count, - sum: Some(dp.sum.into_f64()), + start_time_unix_nano: to_nanos(hist.start_time()), + time_unix_nano: to_nanos(hist.time()), + count: dp.count(), + sum: Some(dp.sum().into_f64()), bucket_counts: dp.bucket_counts().collect(), explicit_bounds: dp.bounds().collect(), exemplars: dp.exemplars().map(Into::into).collect(), @@ -227,7 +227,7 @@ pub mod tonic { max: dp.max.map(Numeric::into_f64), }) .collect(), - aggregation_temporality: TonicTemporality::from(hist.temporality).into(), + aggregation_temporality: TonicTemporality::from(hist.temporality()).into(), } } } @@ -242,28 +242,28 @@ pub mod tonic { .data_points() .map(|dp| TonicExponentialHistogramDataPoint { attributes: dp.attributes().map(Into::into).collect(), - start_time_unix_nano: to_nanos(hist.start_time), - time_unix_nano: to_nanos(hist.time), - count: dp.count as u64, - sum: Some(dp.sum.into_f64()), - scale: dp.scale.into(), - zero_count: dp.zero_count, + start_time_unix_nano: to_nanos(hist.start_time()), + time_unix_nano: to_nanos(hist.time()), + count: dp.count() as u64, + sum: Some(dp.sum().into_f64()), + scale: dp.scale().into(), + zero_count: dp.zero_count(), positive: Some(TonicBuckets { - offset: dp.positive_bucket.offset, - bucket_counts: dp.positive_bucket.counts.clone(), + offset: dp.positive_bucket().offset(), + bucket_counts: dp.positive_bucket().counts().iter().copied().collect(), }), negative: Some(TonicBuckets { - offset: dp.negative_bucket.offset, - bucket_counts: dp.negative_bucket.counts.clone(), + offset: dp.negative_bucket().offset(), + bucket_counts: dp.negative_bucket().counts().iter().copied().collect(), }), flags: TonicDataPointFlags::default() as u32, exemplars: dp.exemplars().map(Into::into).collect(), min: dp.min.map(Numeric::into_f64), max: dp.max.map(Numeric::into_f64), - zero_threshold: dp.zero_threshold, + zero_threshold: dp.zero_threshold(), }) .collect(), - aggregation_temporality: TonicTemporality::from(hist.temporality).into(), + aggregation_temporality: TonicTemporality::from(hist.temporality()).into(), } } } @@ -278,15 +278,15 @@ pub mod tonic { .data_points() .map(|dp| TonicNumberDataPoint { attributes: dp.attributes().map(Into::into).collect(), - start_time_unix_nano: to_nanos(sum.start_time), - time_unix_nano: to_nanos(sum.time), + start_time_unix_nano: to_nanos(sum.start_time()), + time_unix_nano: to_nanos(sum.time()), exemplars: dp.exemplars().map(Into::into).collect(), flags: TonicDataPointFlags::default() as u32, value: Some(dp.value.into()), }) .collect(), - aggregation_temporality: TonicTemporality::from(sum.temporality).into(), - is_monotonic: sum.is_monotonic, + aggregation_temporality: TonicTemporality::from(sum.temporality()).into(), + is_monotonic: sum.is_monotonic(), } } } @@ -301,8 +301,8 @@ pub mod tonic { .data_points() .map(|dp| TonicNumberDataPoint { attributes: dp.attributes().map(Into::into).collect(), - start_time_unix_nano: gauge.start_time.map(to_nanos).unwrap_or_default(), - time_unix_nano: to_nanos(gauge.time), + start_time_unix_nano: gauge.start_time().map(to_nanos).unwrap_or_default(), + time_unix_nano: to_nanos(gauge.time()), exemplars: dp.exemplars().map(Into::into).collect(), flags: TonicDataPointFlags::default() as u32, value: Some(dp.value.into()), @@ -322,9 +322,9 @@ pub mod tonic { .filtered_attributes() .map(|kv| (&kv.key, &kv.value).into()) .collect(), - time_unix_nano: to_nanos(ex.time), - span_id: ex.span_id.into(), - trace_id: ex.trace_id.into(), + time_unix_nano: to_nanos(ex.time()), + span_id: ex.span_id().into(), + trace_id: ex.trace_id().into(), value: Some(ex.value.into()), } } diff --git a/opentelemetry-sdk/src/metrics/data/mod.rs b/opentelemetry-sdk/src/metrics/data/mod.rs index ab8a3adb6f..a64bd114a5 100644 --- a/opentelemetry-sdk/src/metrics/data/mod.rs +++ b/opentelemetry-sdk/src/metrics/data/mod.rs @@ -169,7 +169,7 @@ pub struct GaugeDataPoint { /// time series. pub(crate) attributes: Vec, /// The value of this data point. - pub(crate) value: T, + pub value: T, /// The sampled [Exemplar]s collected during the time series. pub(crate) exemplars: Vec>, } @@ -184,11 +184,6 @@ impl GaugeDataPoint { pub fn exemplars(&self) -> impl Iterator> { self.exemplars.iter() } - - /// Returns the value of this data point. - pub fn value(&self) -> &T { - &self.value - } } /// A measurement of the current value of an instrument. @@ -226,7 +221,7 @@ pub struct SumDataPoint { /// time series. pub(crate) attributes: Vec, /// The value of this data point. - pub(crate) value: T, + pub value: T, /// The sampled [Exemplar]s collected during the time series. pub(crate) exemplars: Vec>, } @@ -241,11 +236,6 @@ impl SumDataPoint { pub fn exemplars(&self) -> impl Iterator> { self.exemplars.iter() } - - /// Returns the value of this data point. - pub fn value(&self) -> &T { - &self.value - } } /// Represents the sum of all measurements of values from an instrument. @@ -344,9 +334,9 @@ pub struct HistogramDataPoint { pub(crate) bucket_counts: Vec, /// The minimum value recorded. - pub(crate) min: Option, + pub min: Option, /// The maximum value recorded. - pub(crate) max: Option, + pub max: Option, /// The sum of the values recorded. pub(crate) sum: T, @@ -380,16 +370,6 @@ impl HistogramDataPoint { self.count } - /// Returns the minimum value recorded. - pub fn min(&self) -> Option<&T> { - self.min.as_ref() - } - - /// Returns the maximum value recorded. - pub fn max(&self) -> Option<&T> { - self.max.as_ref() - } - /// Returns the sum of the values recorded. pub fn sum(&self) -> &T { &self.sum @@ -442,9 +422,9 @@ pub struct ExponentialHistogramDataPoint { /// The number of updates this histogram has been calculated with. pub(crate) count: usize, /// The minimum value recorded. - pub(crate) min: Option, + pub min: Option, /// The maximum value recorded. - pub(crate) max: Option, + pub max: Option, /// The sum of the values recorded. pub(crate) sum: T, @@ -494,16 +474,6 @@ impl ExponentialHistogramDataPoint { self.count } - /// Returns the minimum value recorded. - pub fn min(&self) -> Option<&T> { - self.min.as_ref() - } - - /// Returns the maximum value recorded. - pub fn max(&self) -> Option<&T> { - self.max.as_ref() - } - /// Returns the sum of the values recorded. pub fn sum(&self) -> &T { &self.sum @@ -569,7 +539,7 @@ pub struct Exemplar { /// The time when the measurement was recorded. pub(crate) time: SystemTime, /// The measured value. - pub(crate) value: T, + pub value: T, /// The ID of the span that was active during the measurement. /// /// If no span was active or the span was not sampled this will be empty. @@ -591,11 +561,6 @@ impl Exemplar { self.time } - /// Returns the measured value. - pub fn value(&self) -> &T { - &self.value - } - /// Returns the ID of the span that was active during the measurement. pub fn span_id(&self) -> &[u8; 8] { &self.span_id diff --git a/opentelemetry-stdout/src/metrics/exporter.rs b/opentelemetry-stdout/src/metrics/exporter.rs index d1623e9f10..3e52bccf2d 100644 --- a/opentelemetry-stdout/src/metrics/exporter.rs +++ b/opentelemetry-stdout/src/metrics/exporter.rs @@ -198,7 +198,7 @@ fn print_sum_data_points<'a, T: Debug + 'a>( ) { for (i, data_point) in data_points.enumerate() { println!("\t\tDataPoint #{}", i); - println!("\t\t\tValue : {:#?}", data_point.value()); + println!("\t\t\tValue : {:#?}", data_point.value); println!("\t\t\tAttributes :"); for kv in data_point.attributes() { println!("\t\t\t\t -> {}: {}", kv.key, kv.value.as_str()); @@ -211,7 +211,7 @@ fn print_gauge_data_points<'a, T: Debug + 'a>( ) { for (i, data_point) in data_points.enumerate() { println!("\t\tDataPoint #{}", i); - println!("\t\t\tValue : {:#?}", data_point.value()); + println!("\t\t\tValue : {:#?}", data_point.value); println!("\t\t\tAttributes :"); for kv in data_point.attributes() { println!("\t\t\t\t -> {}: {}", kv.key, kv.value.as_str()); @@ -226,11 +226,11 @@ fn print_hist_data_points<'a, T: Debug + 'a>( println!("\t\tDataPoint #{}", i); println!("\t\t\tCount : {}", data_point.count()); println!("\t\t\tSum : {:?}", data_point.sum()); - if let Some(min) = data_point.min() { + if let Some(min) = &data_point.min { println!("\t\t\tMin : {:?}", min); } - if let Some(max) = data_point.max() { + if let Some(max) = &data_point.max { println!("\t\t\tMax : {:?}", max); } From eb1999d5a3e1daeba3b40ab5a6d72d63fd56ffbd Mon Sep 17 00:00:00 2001 From: Cijo Thomas Date: Thu, 22 May 2025 15:11:44 -0700 Subject: [PATCH 06/13] to vec f --- opentelemetry-proto/src/transform/metrics.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/opentelemetry-proto/src/transform/metrics.rs b/opentelemetry-proto/src/transform/metrics.rs index a97bc5f040..fa55588b73 100644 --- a/opentelemetry-proto/src/transform/metrics.rs +++ b/opentelemetry-proto/src/transform/metrics.rs @@ -250,11 +250,11 @@ pub mod tonic { zero_count: dp.zero_count(), positive: Some(TonicBuckets { offset: dp.positive_bucket().offset(), - bucket_counts: dp.positive_bucket().counts().iter().copied().collect(), + bucket_counts: dp.positive_bucket().counts().to_vec(), }), negative: Some(TonicBuckets { offset: dp.negative_bucket().offset(), - bucket_counts: dp.negative_bucket().counts().iter().copied().collect(), + bucket_counts: dp.negative_bucket().counts().to_vec(), }), flags: TonicDataPointFlags::default() as u32, exemplars: dp.exemplars().map(Into::into).collect(), From bcbff6330c7e6b3a12fe0c7d39ed5f55412f1816 Mon Sep 17 00:00:00 2001 From: Cijo Thomas Date: Thu, 22 May 2025 17:24:55 -0700 Subject: [PATCH 07/13] fix min and max and value --- opentelemetry-proto/src/transform/metrics.rs | 4 +-- opentelemetry-sdk/src/metrics/data/mod.rs | 32 ++++++++++++++++++-- opentelemetry-stdout/src/metrics/exporter.rs | 16 +++++----- 3 files changed, 39 insertions(+), 13 deletions(-) diff --git a/opentelemetry-proto/src/transform/metrics.rs b/opentelemetry-proto/src/transform/metrics.rs index fa55588b73..5aedc06380 100644 --- a/opentelemetry-proto/src/transform/metrics.rs +++ b/opentelemetry-proto/src/transform/metrics.rs @@ -282,7 +282,7 @@ pub mod tonic { time_unix_nano: to_nanos(sum.time()), exemplars: dp.exemplars().map(Into::into).collect(), flags: TonicDataPointFlags::default() as u32, - value: Some(dp.value.into()), + value: Some(dp.value().into()), }) .collect(), aggregation_temporality: TonicTemporality::from(sum.temporality()).into(), @@ -305,7 +305,7 @@ pub mod tonic { time_unix_nano: to_nanos(gauge.time()), exemplars: dp.exemplars().map(Into::into).collect(), flags: TonicDataPointFlags::default() as u32, - value: Some(dp.value.into()), + value: Some(dp.value().into()), }) .collect(), } diff --git a/opentelemetry-sdk/src/metrics/data/mod.rs b/opentelemetry-sdk/src/metrics/data/mod.rs index a64bd114a5..3a2389eddb 100644 --- a/opentelemetry-sdk/src/metrics/data/mod.rs +++ b/opentelemetry-sdk/src/metrics/data/mod.rs @@ -169,7 +169,7 @@ pub struct GaugeDataPoint { /// time series. pub(crate) attributes: Vec, /// The value of this data point. - pub value: T, + pub(crate) value: T, /// The sampled [Exemplar]s collected during the time series. pub(crate) exemplars: Vec>, } @@ -186,6 +186,13 @@ impl GaugeDataPoint { } } +impl GaugeDataPoint { + /// Returns the value of this data point. + pub fn value(&self) -> T { + self.value + } +} + /// A measurement of the current value of an instrument. #[derive(Debug, Clone)] pub struct Gauge { @@ -238,6 +245,13 @@ impl SumDataPoint { } } +impl SumDataPoint { + /// Returns the value of this data point. + pub fn value(&self) -> T { + self.value + } +} + /// Represents the sum of all measurements of values from an instrument. #[derive(Debug, Clone)] pub struct Sum { @@ -334,9 +348,9 @@ pub struct HistogramDataPoint { pub(crate) bucket_counts: Vec, /// The minimum value recorded. - pub min: Option, + pub(crate) min: Option, /// The maximum value recorded. - pub max: Option, + pub(crate) max: Option, /// The sum of the values recorded. pub(crate) sum: T, @@ -376,6 +390,18 @@ impl HistogramDataPoint { } } +impl HistogramDataPoint { + /// Returns the minimum value recorded. + pub fn min(&self) -> Option { + self.min + } + + /// Returns the maximum value recorded. + pub fn max(&self) -> Option { + self.max + } +} + /// The histogram of all measurements of values from an instrument. #[derive(Debug, Clone)] pub struct ExponentialHistogram { diff --git a/opentelemetry-stdout/src/metrics/exporter.rs b/opentelemetry-stdout/src/metrics/exporter.rs index 3e52bccf2d..87db7f1ca4 100644 --- a/opentelemetry-stdout/src/metrics/exporter.rs +++ b/opentelemetry-stdout/src/metrics/exporter.rs @@ -105,7 +105,7 @@ fn print_metrics<'a>(metrics: impl Iterator) { fn print_info(data: &MetricData) where - T: Debug, + T: Debug + Copy, { match data { MetricData::Gauge(gauge) => { @@ -156,7 +156,7 @@ fn print_sum(sum: &Sum) { print_sum_data_points(sum.data_points()); } -fn print_gauge(gauge: &Gauge) { +fn print_gauge(gauge: &Gauge) { println!("\t\tGauge DataPoints"); if let Some(start_time) = gauge.start_time() { let datetime: DateTime = start_time.into(); @@ -173,7 +173,7 @@ fn print_gauge(gauge: &Gauge) { print_gauge_data_points(gauge.data_points()); } -fn print_histogram(histogram: &Histogram) { +fn print_histogram(histogram: &Histogram) { if histogram.temporality() == Temporality::Cumulative { println!("\t\tTemporality : Cumulative"); } else { @@ -206,12 +206,12 @@ fn print_sum_data_points<'a, T: Debug + 'a>( } } -fn print_gauge_data_points<'a, T: Debug + 'a>( +fn print_gauge_data_points<'a, T: Debug + Copy + 'a>( data_points: impl Iterator>, ) { for (i, data_point) in data_points.enumerate() { println!("\t\tDataPoint #{}", i); - println!("\t\t\tValue : {:#?}", data_point.value); + println!("\t\t\tValue : {:#?}", data_point.value()); println!("\t\t\tAttributes :"); for kv in data_point.attributes() { println!("\t\t\t\t -> {}: {}", kv.key, kv.value.as_str()); @@ -219,18 +219,18 @@ fn print_gauge_data_points<'a, T: Debug + 'a>( } } -fn print_hist_data_points<'a, T: Debug + 'a>( +fn print_hist_data_points<'a, T: Debug + Copy + 'a>( data_points: impl Iterator>, ) { for (i, data_point) in data_points.enumerate() { println!("\t\tDataPoint #{}", i); println!("\t\t\tCount : {}", data_point.count()); println!("\t\t\tSum : {:?}", data_point.sum()); - if let Some(min) = &data_point.min { + if let Some(min) = &data_point.min() { println!("\t\t\tMin : {:?}", min); } - if let Some(max) = &data_point.max { + if let Some(max) = &data_point.max() { println!("\t\t\tMax : {:?}", max); } From 0813ad811052f251ccc63333a299b17adf0fe7db Mon Sep 17 00:00:00 2001 From: Cijo Thomas Date: Thu, 22 May 2025 17:25:25 -0700 Subject: [PATCH 08/13] use getter --- opentelemetry-proto/src/transform/metrics.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/opentelemetry-proto/src/transform/metrics.rs b/opentelemetry-proto/src/transform/metrics.rs index 5aedc06380..bc009d2c01 100644 --- a/opentelemetry-proto/src/transform/metrics.rs +++ b/opentelemetry-proto/src/transform/metrics.rs @@ -223,8 +223,8 @@ pub mod tonic { explicit_bounds: dp.bounds().collect(), exemplars: dp.exemplars().map(Into::into).collect(), flags: TonicDataPointFlags::default() as u32, - min: dp.min.map(Numeric::into_f64), - max: dp.max.map(Numeric::into_f64), + min: dp.min().map(Numeric::into_f64), + max: dp.max().map(Numeric::into_f64), }) .collect(), aggregation_temporality: TonicTemporality::from(hist.temporality()).into(), From c111744bc7c552958a0542d865dff896859b095d Mon Sep 17 00:00:00 2001 From: Cijo Thomas Date: Thu, 22 May 2025 17:26:52 -0700 Subject: [PATCH 09/13] exponentrial --- opentelemetry-proto/src/transform/metrics.rs | 4 ++-- opentelemetry-sdk/src/metrics/data/mod.rs | 16 ++++++++++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/opentelemetry-proto/src/transform/metrics.rs b/opentelemetry-proto/src/transform/metrics.rs index bc009d2c01..22e2a1206b 100644 --- a/opentelemetry-proto/src/transform/metrics.rs +++ b/opentelemetry-proto/src/transform/metrics.rs @@ -258,8 +258,8 @@ pub mod tonic { }), flags: TonicDataPointFlags::default() as u32, exemplars: dp.exemplars().map(Into::into).collect(), - min: dp.min.map(Numeric::into_f64), - max: dp.max.map(Numeric::into_f64), + min: dp.min().map(Numeric::into_f64), + max: dp.max().map(Numeric::into_f64), zero_threshold: dp.zero_threshold(), }) .collect(), diff --git a/opentelemetry-sdk/src/metrics/data/mod.rs b/opentelemetry-sdk/src/metrics/data/mod.rs index 3a2389eddb..a5387be039 100644 --- a/opentelemetry-sdk/src/metrics/data/mod.rs +++ b/opentelemetry-sdk/src/metrics/data/mod.rs @@ -448,9 +448,9 @@ pub struct ExponentialHistogramDataPoint { /// The number of updates this histogram has been calculated with. pub(crate) count: usize, /// The minimum value recorded. - pub min: Option, + pub(crate) min: Option, /// The maximum value recorded. - pub max: Option, + pub(crate) max: Option, /// The sum of the values recorded. pub(crate) sum: T, @@ -531,6 +531,18 @@ impl ExponentialHistogramDataPoint { } } +impl ExponentialHistogramDataPoint { + /// Returns the minimum value recorded. + pub fn min(&self) -> Option { + self.min + } + + /// Returns the maximum value recorded. + pub fn max(&self) -> Option { + self.max + } +} + /// A set of bucket counts, encoded in a contiguous array of counts. #[derive(Debug, Clone, PartialEq)] pub struct ExponentialBucket { From 4631eaef4e4ee6e4d950b98a274570afa4afd043 Mon Sep 17 00:00:00 2001 From: Cijo Thomas Date: Thu, 22 May 2025 17:29:16 -0700 Subject: [PATCH 10/13] sum --- opentelemetry-sdk/src/metrics/data/mod.rs | 2 +- opentelemetry-stdout/src/metrics/exporter.rs | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/opentelemetry-sdk/src/metrics/data/mod.rs b/opentelemetry-sdk/src/metrics/data/mod.rs index a5387be039..ecdfc7d56c 100644 --- a/opentelemetry-sdk/src/metrics/data/mod.rs +++ b/opentelemetry-sdk/src/metrics/data/mod.rs @@ -228,7 +228,7 @@ pub struct SumDataPoint { /// time series. pub(crate) attributes: Vec, /// The value of this data point. - pub value: T, + pub(crate) value: T, /// The sampled [Exemplar]s collected during the time series. pub(crate) exemplars: Vec>, } diff --git a/opentelemetry-stdout/src/metrics/exporter.rs b/opentelemetry-stdout/src/metrics/exporter.rs index 87db7f1ca4..ad0df9cdf1 100644 --- a/opentelemetry-stdout/src/metrics/exporter.rs +++ b/opentelemetry-stdout/src/metrics/exporter.rs @@ -135,7 +135,7 @@ fn print_metrics<'a>(metrics: impl Iterator) { } } -fn print_sum(sum: &Sum) { +fn print_sum(sum: &Sum) { println!("\t\tSum DataPoints"); println!("\t\tMonotonic : {}", sum.is_monotonic()); if sum.temporality() == Temporality::Cumulative { @@ -193,12 +193,12 @@ fn print_histogram(histogram: &Histogram) { print_hist_data_points(histogram.data_points()); } -fn print_sum_data_points<'a, T: Debug + 'a>( +fn print_sum_data_points<'a, T: Debug + Copy + 'a>( data_points: impl Iterator>, ) { for (i, data_point) in data_points.enumerate() { println!("\t\tDataPoint #{}", i); - println!("\t\t\tValue : {:#?}", data_point.value); + println!("\t\t\tValue : {:#?}", data_point.value()); println!("\t\t\tAttributes :"); for kv in data_point.attributes() { println!("\t\t\t\t -> {}: {}", kv.key, kv.value.as_str()); From 2e3c885a12e33110b79716cdfb338dcae9cc95e8 Mon Sep 17 00:00:00 2001 From: Cijo Thomas Date: Thu, 22 May 2025 17:29:38 -0700 Subject: [PATCH 11/13] space --- opentelemetry-sdk/src/metrics/data/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/opentelemetry-sdk/src/metrics/data/mod.rs b/opentelemetry-sdk/src/metrics/data/mod.rs index ecdfc7d56c..95399f9642 100644 --- a/opentelemetry-sdk/src/metrics/data/mod.rs +++ b/opentelemetry-sdk/src/metrics/data/mod.rs @@ -531,7 +531,7 @@ impl ExponentialHistogramDataPoint { } } -impl ExponentialHistogramDataPoint { +impl ExponentialHistogramDataPoint { /// Returns the minimum value recorded. pub fn min(&self) -> Option { self.min From 5a9ece3dbdc3d4282873493751185c36321d1038 Mon Sep 17 00:00:00 2001 From: Cijo Thomas Date: Thu, 22 May 2025 18:20:44 -0700 Subject: [PATCH 12/13] use owned instead of refd --- opentelemetry-sdk/src/metrics/data/mod.rs | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/opentelemetry-sdk/src/metrics/data/mod.rs b/opentelemetry-sdk/src/metrics/data/mod.rs index 95399f9642..e19b44e796 100644 --- a/opentelemetry-sdk/src/metrics/data/mod.rs +++ b/opentelemetry-sdk/src/metrics/data/mod.rs @@ -383,11 +383,6 @@ impl HistogramDataPoint { pub fn count(&self) -> u64 { self.count } - - /// Returns the sum of the values recorded. - pub fn sum(&self) -> &T { - &self.sum - } } impl HistogramDataPoint { @@ -400,6 +395,11 @@ impl HistogramDataPoint { pub fn max(&self) -> Option { self.max } + + /// Returns the sum of the values recorded. + pub fn sum(&self) -> T { + self.sum + } } /// The histogram of all measurements of values from an instrument. @@ -500,11 +500,6 @@ impl ExponentialHistogramDataPoint { self.count } - /// Returns the sum of the values recorded. - pub fn sum(&self) -> &T { - &self.sum - } - /// Returns the resolution of the histogram. pub fn scale(&self) -> i8 { self.scale @@ -541,6 +536,11 @@ impl ExponentialHistogramDataPoint { pub fn max(&self) -> Option { self.max } + + /// Returns the sum of the values recorded. + pub fn sum(&self) -> T { + self.sum + } } /// A set of bucket counts, encoded in a contiguous array of counts. From 45708abfe65074542a430d88e8750f55428bfff7 Mon Sep 17 00:00:00 2001 From: Cijo Thomas Date: Thu, 22 May 2025 18:22:05 -0700 Subject: [PATCH 13/13] use iterator --- opentelemetry-proto/src/transform/metrics.rs | 4 ++-- opentelemetry-sdk/src/metrics/data/mod.rs | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/opentelemetry-proto/src/transform/metrics.rs b/opentelemetry-proto/src/transform/metrics.rs index 22e2a1206b..a9370d3d80 100644 --- a/opentelemetry-proto/src/transform/metrics.rs +++ b/opentelemetry-proto/src/transform/metrics.rs @@ -250,11 +250,11 @@ pub mod tonic { zero_count: dp.zero_count(), positive: Some(TonicBuckets { offset: dp.positive_bucket().offset(), - bucket_counts: dp.positive_bucket().counts().to_vec(), + bucket_counts: dp.positive_bucket().counts().collect(), }), negative: Some(TonicBuckets { offset: dp.negative_bucket().offset(), - bucket_counts: dp.negative_bucket().counts().to_vec(), + bucket_counts: dp.negative_bucket().counts().collect(), }), flags: TonicDataPointFlags::default() as u32, exemplars: dp.exemplars().map(Into::into).collect(), diff --git a/opentelemetry-sdk/src/metrics/data/mod.rs b/opentelemetry-sdk/src/metrics/data/mod.rs index e19b44e796..9c63c9ada8 100644 --- a/opentelemetry-sdk/src/metrics/data/mod.rs +++ b/opentelemetry-sdk/src/metrics/data/mod.rs @@ -562,9 +562,9 @@ impl ExponentialBucket { self.offset } - /// Returns a reference to the counts vec. - pub fn counts(&self) -> &[u64] { - &self.counts + /// Returns an iterator over the counts. + pub fn counts(&self) -> impl Iterator + '_ { + self.counts.iter().copied() } }