Trait opentelemetry_sdk::metrics::reader::MetricReader
source · pub trait MetricReader:
AggregationSelector
+ TemporalitySelector
+ Debug
+ Send
+ Sync
+ 'static {
// Required methods
fn register_pipeline(&self, pipeline: Weak<Pipeline>);
fn collect(&self, rm: &mut ResourceMetrics) -> Result<()>;
fn force_flush(&self) -> Result<()>;
fn shutdown(&self) -> Result<()>;
}
Expand description
The interface used between the SDK and an exporter.
Control flow is bi-directional through the MetricReader
, since the SDK
initiates force_flush
and shutdown
while the reader initiates
collection. The register_pipeline
method here informs the metric reader
that it can begin reading, signaling the start of bi-directional control
flow.
Typically, push-based exporters that are periodic will implement
MetricExporter
themselves and construct a PeriodicReader
to satisfy this
interface.
Pull-based exporters will typically implement MetricReader
themselves,
since they read on demand.
Required Methods§
sourcefn register_pipeline(&self, pipeline: Weak<Pipeline>)
fn register_pipeline(&self, pipeline: Weak<Pipeline>)
Registers a MetricReader with a [Pipeline].
The pipeline argument allows the MetricReader
to signal the sdk to collect
and send aggregated metric measurements.
sourcefn collect(&self, rm: &mut ResourceMetrics) -> Result<()>
fn collect(&self, rm: &mut ResourceMetrics) -> Result<()>
Gathers and returns all metric data related to the MetricReader from the SDK and stores it in the provided ResourceMetrics reference.
An error is returned if this is called after shutdown.
sourcefn force_flush(&self) -> Result<()>
fn force_flush(&self) -> Result<()>
Flushes all metric measurements held in an export pipeline.
There is no guaranteed that all telemetry be flushed or all resources have been released on error.
sourcefn shutdown(&self) -> Result<()>
fn shutdown(&self) -> Result<()>
Flushes all metric measurements held in an export pipeline and releases any held computational resources.
There is no guaranteed that all telemetry be flushed or all resources have been released on error.
After shutdown
is called, calls to collect
will perform no operation and
instead will return an error indicating the shutdown state.