From 144fdd961c15fcdf0fa64f3a40eded6cc373dedd Mon Sep 17 00:00:00 2001 From: Cijo Thomas Date: Tue, 28 Jan 2025 12:09:20 -0800 Subject: [PATCH] Print histogram bucket info in stdout exporter (#2569) --- opentelemetry-stdout/src/metrics/exporter.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/opentelemetry-stdout/src/metrics/exporter.rs b/opentelemetry-stdout/src/metrics/exporter.rs index 839784755c..0981f939c4 100644 --- a/opentelemetry-stdout/src/metrics/exporter.rs +++ b/opentelemetry-stdout/src/metrics/exporter.rs @@ -234,6 +234,20 @@ fn print_hist_data_points(data_points: &[HistogramDataPoint]) { for kv in data_point.attributes.iter() { println!("\t\t\t\t -> {}: {}", kv.key, kv.value.as_str()); } + + println!("\t\t\tBuckets"); + let mut lower_bound = f64::NEG_INFINITY; + for (i, &upper_bound) in data_point.bounds.iter().enumerate() { + let count = data_point.bucket_counts.get(i).unwrap_or(&0); + println!("\t\t\t\t {} to {} : {}", lower_bound, upper_bound, count); + lower_bound = upper_bound; + } + + let last_count = data_point + .bucket_counts + .get(data_point.bounds.len()) + .unwrap_or(&0); + println!("\t\t\t\t{} to +Infinity : {}", lower_bound, last_count); } }