@@ -6,83 +6,84 @@ use crate::{error::OTelSdkResult, Resource};
6
6
use std:: { fmt:: Debug , slice:: Iter , time:: Duration } ;
7
7
8
8
use super :: {
9
- data:: { Metric , ResourceMetrics , ScopeMetrics } ,
9
+ data:: Metric ,
10
+ reader:: { ResourceMetricsData , ScopeMetricsData } ,
10
11
Temporality ,
11
12
} ;
12
13
13
14
/// A collection of [`BatchScopeMetrics`] and the associated [Resource] that created them.
14
15
#[ derive( Debug ) ]
15
- pub struct ResourceMetricsRef < ' a > {
16
+ pub struct ResourceMetrics < ' a > {
16
17
/// The entity that collected the metrics.
17
18
pub resource : & ' a Resource ,
18
19
/// The collection of metrics with unique [InstrumentationScope]s.
19
- pub scope_metrics : BatchScopeMetrics < ' a > ,
20
+ pub scope_metrics : ScopeMetricsLendingIter < ' a > ,
20
21
}
21
22
22
23
/// Iterator over libraries instrumentation scopes ([`InstrumentationScope`]) together with metrics.
23
- pub struct BatchScopeMetrics < ' a > {
24
- iter : Iter < ' a , ScopeMetrics > ,
24
+ /// Doesn't implement standard [`Iterator`], because it returns borrowed items. AKA "LendingIterator".
25
+ pub struct ScopeMetricsLendingIter < ' a > {
26
+ iter : Iter < ' a , ScopeMetricsData > ,
25
27
}
26
28
27
29
/// A collection of metrics produced by a [`InstrumentationScope`] meter.
28
30
#[ derive( Debug ) ]
29
- pub struct ScopeMetricsRef < ' a > {
31
+ pub struct ScopeMetrics < ' a > {
30
32
/// The [InstrumentationScope] that the meter was created with.
31
33
pub scope : & ' a InstrumentationScope ,
32
34
/// The list of aggregations created by the meter.
33
- pub metrics : BatchMetrics < ' a > ,
35
+ pub metrics : MetricsLendingIter < ' a > ,
34
36
}
35
37
36
38
/// Iterator over aggregations created by the meter.
37
- pub struct BatchMetrics < ' a > {
39
+ /// Doesn't implement standard [`Iterator`], because it returns borrowed items. AKA "LendingIterator".
40
+ pub struct MetricsLendingIter < ' a > {
38
41
iter : Iter < ' a , Metric > ,
39
42
}
40
43
41
- impl < ' a > ResourceMetricsRef < ' a > {
42
- pub ( crate ) fn new ( rm : & ' a ResourceMetrics ) -> Self {
44
+ impl < ' a > ResourceMetrics < ' a > {
45
+ pub ( crate ) fn new ( rm : & ' a ResourceMetricsData ) -> Self {
43
46
Self {
44
47
resource : & rm. resource ,
45
- scope_metrics : BatchScopeMetrics {
48
+ scope_metrics : ScopeMetricsLendingIter {
46
49
iter : rm. scope_metrics . iter ( ) ,
47
50
} ,
48
51
}
49
52
}
50
53
}
51
54
52
- impl < ' a > ScopeMetricsRef < ' a > {
53
- fn new ( sm : & ' a ScopeMetrics ) -> Self {
55
+ impl < ' a > ScopeMetrics < ' a > {
56
+ fn new ( sm : & ' a ScopeMetricsData ) -> Self {
54
57
Self {
55
58
scope : & sm. scope ,
56
- metrics : BatchMetrics {
59
+ metrics : MetricsLendingIter {
57
60
iter : sm. metrics . iter ( ) ,
58
61
} ,
59
62
}
60
63
}
61
64
}
62
65
63
- impl Debug for BatchScopeMetrics < ' _ > {
66
+ impl Debug for ScopeMetricsLendingIter < ' _ > {
64
67
fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
65
68
f. debug_struct ( "BatchScopeMetrics" ) . finish ( )
66
69
}
67
70
}
68
71
69
- impl < ' a > Iterator for BatchScopeMetrics < ' a > {
70
- type Item = ScopeMetricsRef < ' a > ;
71
-
72
- fn next ( & mut self ) -> Option < Self :: Item > {
73
- self . iter . next ( ) . map ( ScopeMetricsRef :: new)
72
+ impl ScopeMetricsLendingIter < ' _ > {
73
+ /// Advances the iterator and returns the next value.
74
+ pub fn next ( & mut self ) -> Option < ScopeMetrics < ' _ > > {
75
+ self . iter . next ( ) . map ( ScopeMetrics :: new)
74
76
}
75
77
}
76
78
77
- impl < ' a > Iterator for BatchMetrics < ' a > {
78
- type Item = & ' a Metric ;
79
-
80
- fn next ( & mut self ) -> Option < Self :: Item > {
79
+ impl MetricsLendingIter < ' _ > {
80
+ /// Advances the iterator and returns the next value.
81
+ pub fn next ( & mut self ) -> Option < & Metric > {
81
82
self . iter . next ( )
82
83
}
83
84
}
84
85
85
- impl Debug for BatchMetrics < ' _ > {
86
+ impl Debug for MetricsLendingIter < ' _ > {
86
87
fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
87
88
f. debug_struct ( "BatchMetrics" ) . finish ( )
88
89
}
@@ -99,7 +100,7 @@ pub trait PushMetricExporter: Send + Sync + 'static {
99
100
/// considered unrecoverable and will be logged.
100
101
fn export (
101
102
& self ,
102
- metrics : ResourceMetricsRef < ' _ > ,
103
+ metrics : ResourceMetrics < ' _ > ,
103
104
) -> impl std:: future:: Future < Output = OTelSdkResult > + Send ;
104
105
105
106
/// Flushes any metric data held by an exporter.
0 commit comments