Struct PeriodicReader
pub struct PeriodicReader<E>where
E: PushMetricExporter,{ /* private fields */ }
Expand description
A MetricReader
that periodically collects and exports metrics at a configurable interval.
By default, PeriodicReader
collects and exports metrics every 60 seconds.
The time taken for export is not included in the interval. Use PeriodicReaderBuilder
to customize the interval.
PeriodicReader
spawns a background thread to handle metric collection and export.
This thread remains active until shutdown()
is called.
§Collection Process
“Collection” refers to gathering aggregated metrics from the SDK’s internal storage. During this phase, callbacks from observable instruments are also triggered.
PeriodicReader
does not enforce a timeout for collection. If an
observable callback takes too long, it may delay the next collection cycle.
If a callback never returns, it will stall all metric collection (and exports)
indefinitely.
§Exporter Compatibility
When used with the OTLP Exporter
, the following
transport options are supported:
grpc-tonic
: RequiresMeterProvider
to be initialized within atokio
runtime.reqwest-blocking-client
: Works with both a standard (main
) function andtokio::main
.
PeriodicReader
does not enforce a timeout for exports either. Instead,
the configured exporter is responsible for enforcing timeouts. If an export operation
never returns, PeriodicReader
will stop exporting new metrics, stalling
metric collection.
§Manual Export & Shutdown
Users can manually trigger an export via force_flush()
. Calling shutdown()
exports any remaining metrics and should be done before application exit to ensure
all data is sent.
Warning: If using tokio’s current-thread runtime, calling shutdown()
from the main thread may cause a deadlock. To prevent this, call shutdown()
from a separate thread or use tokio’s spawn_blocking
.
§Example
use opentelemetry_sdk::metrics::PeriodicReader;
let exporter = get_exporter(); // set up a push exporter
let reader = PeriodicReader::builder(exporter).build();
Implementations§
§impl<E> PeriodicReader<E>where
E: PushMetricExporter,
impl<E> PeriodicReader<E>where
E: PushMetricExporter,
pub fn builder(exporter: E) -> PeriodicReaderBuilder<E>
pub fn builder(exporter: E) -> PeriodicReaderBuilder<E>
Configuration options for a periodic reader with own thread
Trait Implementations§
§impl<E> Clone for PeriodicReader<E>where
E: PushMetricExporter,
impl<E> Clone for PeriodicReader<E>where
E: PushMetricExporter,
§fn clone(&self) -> PeriodicReader<E>
fn clone(&self) -> PeriodicReader<E>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreAuto Trait Implementations§
impl<E> Freeze for PeriodicReader<E>
impl<E> RefUnwindSafe for PeriodicReader<E>where
E: RefUnwindSafe,
impl<E> Send for PeriodicReader<E>
impl<E> Sync for PeriodicReader<E>
impl<E> Unpin for PeriodicReader<E>
impl<E> UnwindSafe for PeriodicReader<E>where
E: RefUnwindSafe,
Blanket Implementations§
§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
§fn with_current_context(self) -> WithContext<Self> ⓘ
fn with_current_context(self) -> WithContext<Self> ⓘ
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more§impl<T> Pointable for T
impl<T> Pointable for T
§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
§fn and<P, B, E>(self, other: P) -> And<T, P>
fn and<P, B, E>(self, other: P) -> And<T, P>
Policy
that returns Action::Follow
only if self
and other
return
Action::Follow
. Read more