@@ -14,8 +14,7 @@ use opentelemetry_sdk::{
1414 metrics:: {
1515 data:: { ResourceMetrics , Temporality } ,
1616 exporter:: PushMetricsExporter ,
17- reader:: { DefaultTemporalitySelector , DeltaTemporalitySelector , TemporalitySelector } ,
18- InstrumentKind , PeriodicReader , SdkMeterProvider ,
17+ PeriodicReader , SdkMeterProvider ,
1918 } ,
2019 runtime:: Runtime ,
2120 Resource ,
@@ -47,7 +46,7 @@ impl OtlpPipeline {
4746 {
4847 OtlpMetricPipeline {
4948 rt,
50- temporality_selector : None ,
49+ temporality : None ,
5150 exporter_pipeline : NoExporterConfig ( ( ) ) ,
5251 resource : None ,
5352 period : None ,
@@ -75,22 +74,15 @@ pub enum MetricsExporterBuilder {
7574
7675impl MetricsExporterBuilder {
7776 /// Build a OTLP metrics exporter with given configuration.
78- pub fn build_metrics_exporter (
79- self ,
80- temporality_selector : Box < dyn TemporalitySelector > ,
81- ) -> Result < MetricsExporter > {
77+ pub fn build_metrics_exporter ( self , temporality : Temporality ) -> Result < MetricsExporter > {
8278 match self {
8379 #[ cfg( feature = "grpc-tonic" ) ]
84- MetricsExporterBuilder :: Tonic ( builder) => {
85- builder. build_metrics_exporter ( temporality_selector)
86- }
80+ MetricsExporterBuilder :: Tonic ( builder) => builder. build_metrics_exporter ( temporality) ,
8781 #[ cfg( feature = "http-proto" ) ]
88- MetricsExporterBuilder :: Http ( builder) => {
89- builder. build_metrics_exporter ( temporality_selector)
90- }
82+ MetricsExporterBuilder :: Http ( builder) => builder. build_metrics_exporter ( temporality) ,
9183 #[ cfg( not( any( feature = "http-proto" , feature = "grpc-tonic" ) ) ) ]
9284 MetricsExporterBuilder :: Unconfigured => {
93- drop ( temporality_selector ) ;
85+ let _ = temporality ;
9486 Err ( opentelemetry:: metrics:: MetricsError :: Other (
9587 "no configured metrics exporter, enable `http-proto` or `grpc-tonic` feature to configure a metrics exporter" . into ( ) ,
9688 ) )
@@ -119,7 +111,7 @@ impl From<HttpExporterBuilder> for MetricsExporterBuilder {
119111/// runtime.
120112pub struct OtlpMetricPipeline < RT , EB > {
121113 rt : RT ,
122- temporality_selector : Option < Box < dyn TemporalitySelector > > ,
114+ temporality : Option < Temporality > ,
123115 exporter_pipeline : EB ,
124116 resource : Option < Resource > ,
125117 period : Option < time:: Duration > ,
@@ -154,23 +146,13 @@ where
154146 }
155147 }
156148
157- /// Build with the given temporality selector
158- pub fn with_temporality_selector < T : TemporalitySelector + ' static > ( self , selector : T ) -> Self {
149+ /// Set the [Temporality] of the exporter.
150+ pub fn with_temporality ( self , temporality : Temporality ) -> Self {
159151 OtlpMetricPipeline {
160- temporality_selector : Some ( Box :: new ( selector ) ) ,
152+ temporality : Some ( temporality ) ,
161153 ..self
162154 }
163155 }
164-
165- /// Build with delta temporality selector.
166- ///
167- /// This temporality selector is equivalent to OTLP Metrics Exporter's
168- /// `Delta` temporality preference (see [its documentation][exporter-docs]).
169- ///
170- /// [exporter-docs]: https://github.com/open-telemetry/opentelemetry-specification/blob/a1c13d59bb7d0fb086df2b3e1eaec9df9efef6cc/specification/metrics/sdk_exporters/otlp.md#additional-configuration
171- pub fn with_delta_temporality ( self ) -> Self {
172- self . with_temporality_selector ( DeltaTemporalitySelector :: new ( ) )
173- }
174156}
175157
176158impl < RT > OtlpMetricPipeline < RT , NoExporterConfig >
@@ -185,7 +167,7 @@ where
185167 OtlpMetricPipeline {
186168 exporter_pipeline : pipeline. into ( ) ,
187169 rt : self . rt ,
188- temporality_selector : self . temporality_selector ,
170+ temporality : self . temporality ,
189171 resource : self . resource ,
190172 period : self . period ,
191173 timeout : self . timeout ,
@@ -199,10 +181,9 @@ where
199181{
200182 /// Build MeterProvider
201183 pub fn build ( self ) -> Result < SdkMeterProvider > {
202- let exporter = self . exporter_pipeline . build_metrics_exporter (
203- self . temporality_selector
204- . unwrap_or_else ( || Box :: new ( DefaultTemporalitySelector :: new ( ) ) ) ,
205- ) ?;
184+ let exporter = self
185+ . exporter_pipeline
186+ . build_metrics_exporter ( self . temporality . unwrap_or_default ( ) ) ?;
206187
207188 let mut builder = PeriodicReader :: builder ( exporter, self . rt ) ;
208189
@@ -247,7 +228,7 @@ pub trait MetricsClient: fmt::Debug + Send + Sync + 'static {
247228/// Export metrics in OTEL format.
248229pub struct MetricsExporter {
249230 client : Box < dyn MetricsClient > ,
250- temporality_selector : Box < dyn TemporalitySelector > ,
231+ temporality : Temporality ,
251232}
252233
253234impl Debug for MetricsExporter {
@@ -256,12 +237,6 @@ impl Debug for MetricsExporter {
256237 }
257238}
258239
259- impl TemporalitySelector for MetricsExporter {
260- fn temporality ( & self , kind : InstrumentKind ) -> Temporality {
261- self . temporality_selector . temporality ( kind)
262- }
263- }
264-
265240#[ async_trait]
266241impl PushMetricsExporter for MetricsExporter {
267242 async fn export ( & self , metrics : & mut ResourceMetrics ) -> Result < ( ) > {
@@ -276,17 +251,18 @@ impl PushMetricsExporter for MetricsExporter {
276251 fn shutdown ( & self ) -> Result < ( ) > {
277252 self . client . shutdown ( )
278253 }
254+
255+ fn temporality ( & self ) -> Temporality {
256+ self . temporality
257+ }
279258}
280259
281260impl MetricsExporter {
282261 /// Create a new metrics exporter
283- pub fn new (
284- client : impl MetricsClient ,
285- temporality_selector : Box < dyn TemporalitySelector > ,
286- ) -> MetricsExporter {
262+ pub fn new ( client : impl MetricsClient , temporality : Temporality ) -> MetricsExporter {
287263 MetricsExporter {
288264 client : Box :: new ( client) ,
289- temporality_selector ,
265+ temporality ,
290266 }
291267 }
292268}
0 commit comments