@@ -23,7 +23,7 @@ use crate::{
23
23
24
24
use self :: internal:: AggregateFns ;
25
25
26
- use super :: Aggregation ;
26
+ use super :: { Aggregation , Temporality } ;
27
27
28
28
/// Connects all of the instruments created by a meter provider to a [MetricReader].
29
29
///
@@ -488,9 +488,20 @@ fn aggregate_fn<T: Number>(
488
488
match agg {
489
489
Aggregation :: Default => aggregate_fn ( b, & default_aggregation_selector ( kind) , kind) ,
490
490
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
+ }
492
500
Aggregation :: Sum => {
493
501
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
494
505
InstrumentKind :: ObservableCounter => b. precomputed_sum ( true ) ,
495
506
InstrumentKind :: ObservableUpDownCounter => b. precomputed_sum ( false ) ,
496
507
InstrumentKind :: Counter | InstrumentKind :: Histogram => b. sum ( true ) ,
@@ -508,6 +519,9 @@ fn aggregate_fn<T: Number>(
508
519
| InstrumentKind :: ObservableUpDownCounter
509
520
| InstrumentKind :: ObservableGauge
510
521
) ;
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
511
525
Ok ( Some ( b. explicit_bucket_histogram (
512
526
boundaries. to_vec ( ) ,
513
527
* record_min_max,
0 commit comments