@@ -23,7 +23,7 @@ use crate::{
2323
2424use self :: internal:: AggregateFns ;
2525
26- use super :: { aggregation:: Aggregation , Temporality } ;
26+ use super :: { aggregation:: Aggregation , HistogramAggregation , Temporality } ;
2727
2828/// Connects all of the instruments created by a meter provider to a [MetricReader].
2929///
@@ -378,14 +378,15 @@ where
378378 // TODO: Create a separate pub (crate) Stream struct for the pipeline,
379379 // as Stream will not have any optional fields as None at this point and
380380 // new struct can better reflect this.
381+ let histogram_agg = self . pipeline . reader . default_histogram_aggregation ( ) ;
381382 let mut agg = stream
382383 . aggregation
383384 . take ( )
384- . unwrap_or_else ( || default_aggregation_selector ( kind) ) ;
385+ . unwrap_or_else ( || default_aggregation_selector ( kind, histogram_agg ) ) ;
385386
386387 // Apply default if stream or reader aggregation returns default
387388 if matches ! ( agg, aggregation:: Aggregation :: Default ) {
388- agg = default_aggregation_selector ( kind) ;
389+ agg = default_aggregation_selector ( kind, histogram_agg ) ;
389390 }
390391
391392 if let Err ( err) = is_aggregator_compatible ( & kind, & agg) {
@@ -421,7 +422,8 @@ where
421422 filter,
422423 cardinality_limit,
423424 ) ;
424- let AggregateFns { measure, collect } = match aggregate_fn ( b, & agg, kind) {
425+ let AggregateFns { measure, collect } = match aggregate_fn ( b, & agg, kind, histogram_agg)
426+ {
425427 Ok ( Some ( inst) ) => inst,
426428 other => return other. map ( |fs| fs. map ( |inst| inst. measure ) ) , // Drop aggregator or error
427429 } ;
@@ -497,23 +499,35 @@ where
497499/// * Observable UpDownCounter ⇨ Sum
498500/// * Gauge ⇨ LastValue
499501/// * Observable Gauge ⇨ LastValue
500- /// * Histogram ⇨ ExplicitBucketHistogram
502+ /// * Histogram ⇨ determined by `histogram_agg`
501503///
502504/// [the spec]: https://github.com/open-telemetry/opentelemetry-specification/blob/v1.19.0/specification/metrics/sdk.md#default-aggregation
503- fn default_aggregation_selector ( kind : InstrumentKind ) -> Aggregation {
505+ fn default_aggregation_selector (
506+ kind : InstrumentKind ,
507+ histogram_agg : HistogramAggregation ,
508+ ) -> Aggregation {
504509 match kind {
505510 InstrumentKind :: Counter
506511 | InstrumentKind :: UpDownCounter
507512 | InstrumentKind :: ObservableCounter
508513 | InstrumentKind :: ObservableUpDownCounter => Aggregation :: Sum ,
509514 InstrumentKind :: Gauge => Aggregation :: LastValue ,
510515 InstrumentKind :: ObservableGauge => Aggregation :: LastValue ,
511- InstrumentKind :: Histogram => Aggregation :: ExplicitBucketHistogram {
512- boundaries : vec ! [
513- 0.0 , 5.0 , 10.0 , 25.0 , 50.0 , 75.0 , 100.0 , 250.0 , 500.0 , 750.0 , 1000.0 , 2500.0 ,
514- 5000.0 , 7500.0 , 10000.0 ,
515- ] ,
516- record_min_max : true ,
516+ InstrumentKind :: Histogram => match histogram_agg {
517+ HistogramAggregation :: ExplicitBucketHistogram => Aggregation :: ExplicitBucketHistogram {
518+ boundaries : vec ! [
519+ 0.0 , 5.0 , 10.0 , 25.0 , 50.0 , 75.0 , 100.0 , 250.0 , 500.0 , 750.0 , 1000.0 , 2500.0 ,
520+ 5000.0 , 7500.0 , 10000.0 ,
521+ ] ,
522+ record_min_max : true ,
523+ } ,
524+ HistogramAggregation :: Base2ExponentialBucketHistogram => {
525+ Aggregation :: Base2ExponentialHistogram {
526+ max_size : 160 ,
527+ max_scale : 20 ,
528+ record_min_max : true ,
529+ }
530+ }
517531 } ,
518532 }
519533}
@@ -525,9 +539,15 @@ fn aggregate_fn<T: Number>(
525539 b : AggregateBuilder < T > ,
526540 agg : & aggregation:: Aggregation ,
527541 kind : InstrumentKind ,
542+ histogram_agg : HistogramAggregation ,
528543) -> MetricResult < Option < AggregateFns < T > > > {
529544 match agg {
530- Aggregation :: Default => aggregate_fn ( b, & default_aggregation_selector ( kind) , kind) ,
545+ Aggregation :: Default => aggregate_fn (
546+ b,
547+ & default_aggregation_selector ( kind, histogram_agg) ,
548+ kind,
549+ histogram_agg,
550+ ) ,
531551 Aggregation :: Drop => Ok ( None ) ,
532552 Aggregation :: LastValue => {
533553 match kind {
0 commit comments