@@ -18,12 +18,13 @@ use crate::Resource;
1818use super :: {
1919 exporter:: PushMetricExporter , meter:: SdkMeter , noop:: NoopMeter ,
2020 periodic_reader:: PeriodicReader , pipeline:: Pipelines , reader:: MetricReader , view:: View ,
21+ Instrument , Stream ,
2122} ;
2223
2324/// Handles the creation and coordination of [Meter]s.
2425///
2526/// All `Meter`s created by a `MeterProvider` will be associated with the same
26- /// [Resource], have the same [View]s applied to them, and have their produced
27+ /// [Resource], have the same views applied to them, and have their produced
2728/// metric telemetry passed to the configured [MetricReader]s. This is a
2829/// clonable handle to the MeterProvider implementation itself, and cloning it
2930/// will create a new reference, not a new instance of a MeterProvider. Dropping
@@ -287,14 +288,14 @@ impl MeterProviderBuilder {
287288 self
288289 }
289290
290- /// Adds a [View] to the [MeterProvider].
291+ /// Adds a view to the [MeterProvider].
291292 ///
292293 /// Views allow you to customize how metrics are aggregated, renamed, or
293294 /// otherwise transformed before export, without modifying instrument
294295 /// definitions in your application or library code.
295296 ///
296- /// You can pass any type implementing the [`View`] trait, including
297- /// closures matching the pattern `Fn(&Instrument) -> Option<Stream>`. The
297+ /// You can pass any function or closure matching the signature
298+ /// `Fn(&Instrument) -> Option<Stream> + Send + Sync + 'static `. The
298299 /// function receives a reference to the [`Instrument`] and can return an
299300 /// [`Option`] of [`Stream`] to specify how matching instruments should be
300301 /// exported. Returning `None` means the view does not apply to the given
@@ -348,7 +349,7 @@ impl MeterProviderBuilder {
348349 /// // By calling `.ok()`, any such error is ignored and treated as if the view does not match
349350 /// // the instrument.
350351 /// // If this is not the desired behavior, consider handling the error explicitly.
351- /// Stream::builder().with_cardinality_limit(100 ).build().ok()
352+ /// Stream::builder().with_cardinality_limit(0 ).build().ok()
352353 /// } else {
353354 /// None
354355 /// }
@@ -361,10 +362,12 @@ impl MeterProviderBuilder {
361362 /// If no views are added, the [MeterProvider] uses the default view.
362363 ///
363364 /// [`Instrument`]: crate::metrics::Instrument
364- /// [`View`]: crate::metrics::View
365365 /// [`Stream`]: crate::metrics::Stream
366366 /// [`Option`]: core::option::Option
367- pub fn with_view < T : View > ( mut self , view : T ) -> Self {
367+ pub fn with_view < T > ( mut self , view : T ) -> Self
368+ where
369+ T : Fn ( & Instrument ) -> Option < Stream > + Send + Sync + ' static ,
370+ {
368371 self . views . push ( Arc :: new ( view) ) ;
369372 self
370373 }
0 commit comments