@@ -19,7 +19,8 @@ use crate::{
19
19
} ;
20
20
21
21
use super :: {
22
- meter:: SdkMeter , noop:: NoopMeter , pipeline:: Pipelines , reader:: MetricReader , view:: View ,
22
+ exporter:: PushMetricExporter , meter:: SdkMeter , noop:: NoopMeter , pipeline:: Pipelines ,
23
+ reader:: MetricReader , view:: View , PeriodicReader ,
23
24
} ;
24
25
25
26
/// Handles the creation and coordination of [Meter]s.
@@ -244,14 +245,37 @@ impl MeterProviderBuilder {
244
245
}
245
246
246
247
/// Associates a [MetricReader] with a [MeterProvider].
248
+ /// [`MeterProviderBuilder::with_periodic_exporter()] can be used to add a PeriodicReader which is
249
+ /// the most common use case.
247
250
///
248
- /// By default, if this option is not used, the [MeterProvider] will perform no
249
- /// operations; no data will be exported without a [MetricReader] .
251
+ /// A [MeterProvider] will export no metrics without [MetricReader]
252
+ /// added .
250
253
pub fn with_reader < T : MetricReader > ( mut self , reader : T ) -> Self {
251
254
self . readers . push ( Box :: new ( reader) ) ;
252
255
self
253
256
}
254
257
258
+ /// Adds a [`PushMetricExporter`] to the [`MeterProvider`] and configures it
259
+ /// to export metrics at **fixed** intervals (60 seconds) using a
260
+ /// [`PeriodicReader`].
261
+ ///
262
+ /// To customize the export interval, set the
263
+ /// **"OTEL_METRIC_EXPORT_INTERVAL"** environment variable (in
264
+ /// milliseconds).
265
+ ///
266
+ /// Most users should use this method to attach an exporter. Advanced users
267
+ /// who need finer control over the export process can use
268
+ /// [`crate::metrics::PeriodicReaderBuilder`] to configure a custom reader and attach it
269
+ /// using [`MeterProviderBuilder::with_reader()`].
270
+ pub fn with_periodic_exporter < T > ( mut self , exporter : T ) -> Self
271
+ where
272
+ T : PushMetricExporter ,
273
+ {
274
+ let reader = PeriodicReader :: builder ( exporter) . build ( ) ;
275
+ self . readers . push ( Box :: new ( reader) ) ;
276
+ self
277
+ }
278
+
255
279
#[ cfg( feature = "spec_unstable_metrics_views" ) ]
256
280
/// Associates a [View] with a [MeterProvider].
257
281
///
0 commit comments