@@ -10,6 +10,7 @@ use opentelemetry_sdk::{
1010 HistogramDataPoint , ResourceMetrics , ScopeMetrics , Sum , SumDataPoint ,
1111 } ,
1212 exporter:: PushMetricExporter ,
13+ HistogramAggregation ,
1314 } ,
1415} ;
1516use std:: fmt:: Debug ;
@@ -20,6 +21,7 @@ use std::time::Duration;
2021pub struct MetricExporter {
2122 is_shutdown : atomic:: AtomicBool ,
2223 temporality : Temporality ,
24+ histogram_aggregation : HistogramAggregation ,
2325}
2426
2527impl 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
8288fn 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 ) ]
355361pub struct MetricExporterBuilder {
356362 temporality : Option < Temporality > ,
363+ histogram_aggregation : Option < HistogramAggregation > ,
357364}
358365
359366impl 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