Skip to content

Commit 35d1bdc

Browse files
feat(opentelemetry-stdout): support histogram aggregation
1 parent 4203559 commit 35d1bdc

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

opentelemetry-stdout/src/metrics/exporter.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use opentelemetry_sdk::{
1010
HistogramDataPoint, ResourceMetrics, ScopeMetrics, Sum, SumDataPoint,
1111
},
1212
exporter::PushMetricExporter,
13+
HistogramAggregation,
1314
},
1415
};
1516
use std::fmt::Debug;
@@ -20,6 +21,7 @@ use std::time::Duration;
2021
pub struct MetricExporter {
2122
is_shutdown: atomic::AtomicBool,
2223
temporality: Temporality,
24+
histogram_aggregation: HistogramAggregation,
2325
}
2426

2527
impl MetricExporter {
@@ -77,6 +79,10 @@ impl PushMetricExporter for MetricExporter {
7779
fn temporality(&self) -> Temporality {
7880
self.temporality
7981
}
82+
83+
fn default_histogram_aggregation(&self) -> HistogramAggregation {
84+
self.histogram_aggregation
85+
}
8086
}
8187

8288
fn print_metrics<'a>(metrics: impl Iterator<Item = &'a ScopeMetrics>) {
@@ -354,6 +360,7 @@ fn print_exponential_hist_data_points<'a, T: Debug + Copy + 'a>(
354360
#[derive(Default)]
355361
pub struct MetricExporterBuilder {
356362
temporality: Option<Temporality>,
363+
histogram_aggregation: Option<HistogramAggregation>,
357364
}
358365

359366
impl MetricExporterBuilder {
@@ -363,10 +370,20 @@ impl MetricExporterBuilder {
363370
self
364371
}
365372

373+
/// Set the default histogram aggregation of the exporter.
374+
pub fn with_histogram_aggregation(
375+
mut self,
376+
histogram_aggregation: HistogramAggregation,
377+
) -> Self {
378+
self.histogram_aggregation = Some(histogram_aggregation);
379+
self
380+
}
381+
366382
/// Create a metrics exporter with the current configuration
367383
pub fn build(self) -> MetricExporter {
368384
MetricExporter {
369385
temporality: self.temporality.unwrap_or_default(),
386+
histogram_aggregation: self.histogram_aggregation.unwrap_or_default(),
370387
is_shutdown: atomic::AtomicBool::new(false),
371388
}
372389
}

0 commit comments

Comments
 (0)