@@ -23,7 +23,7 @@ use crate::{
2323
2424use self :: internal:: AggregateFns ;
2525
26- use super :: Aggregation ;
26+ use super :: { Aggregation , Temporality } ;
2727
2828/// Connects all of the instruments created by a meter provider to a [MetricReader].
2929///
@@ -488,9 +488,20 @@ fn aggregate_fn<T: Number>(
488488 match agg {
489489 Aggregation :: Default => aggregate_fn ( b, & default_aggregation_selector ( kind) , kind) ,
490490 Aggregation :: Drop => Ok ( None ) ,
491- Aggregation :: LastValue => Ok ( Some ( b. last_value ( ) ) ) ,
491+ Aggregation :: LastValue => {
492+ match kind {
493+ InstrumentKind :: Gauge => Ok ( Some ( b. last_value ( None ) ) ) ,
494+ // temporality for LastValue only affects how data points are reported, so we can always use
495+ // delta temporality, because observable instruments should report data points only since previous collection
496+ InstrumentKind :: ObservableGauge => Ok ( Some ( b. last_value ( Some ( Temporality :: Delta ) ) ) ) ,
497+ _ => Err ( MetricError :: Other ( format ! ( "LastValue aggregation is only available for Gauge or ObservableGauge, but not for {kind:?}" ) ) )
498+ }
499+ }
492500 Aggregation :: Sum => {
493501 let fns = match kind {
502+ // TODO implement: observable instruments should not report data points on every collect
503+ // from SDK: For asynchronous instruments with Delta or Cumulative aggregation temporality,
504+ // MetricReader.Collect MUST only receive data points with measurements recorded since the previous collection
494505 InstrumentKind :: ObservableCounter => b. precomputed_sum ( true ) ,
495506 InstrumentKind :: ObservableUpDownCounter => b. precomputed_sum ( false ) ,
496507 InstrumentKind :: Counter | InstrumentKind :: Histogram => b. sum ( true ) ,
@@ -508,6 +519,9 @@ fn aggregate_fn<T: Number>(
508519 | InstrumentKind :: ObservableUpDownCounter
509520 | InstrumentKind :: ObservableGauge
510521 ) ;
522+ // TODO implement: observable instruments should not report data points on every collect
523+ // from SDK: For asynchronous instruments with Delta or Cumulative aggregation temporality,
524+ // MetricReader.Collect MUST only receive data points with measurements recorded since the previous collection
511525 Ok ( Some ( b. explicit_bucket_histogram (
512526 boundaries. to_vec ( ) ,
513527 * record_min_max,
0 commit comments