pub trait MetricReader: AggregationSelector + TemporalitySelector + Debug + Send + Sync + 'static {
    // Required methods
    fn register_pipeline(&self, pipeline: Weak<Pipeline, Global>);
    fn register_producer(&self, producer: Box<dyn MetricProducer, Global>);
    fn collect(&self, rm: &mut ResourceMetrics) -> Result<(), MetricsError>;
    fn force_flush(&self, cx: &Context) -> Result<(), MetricsError>;
    fn shutdown(&self) -> Result<(), MetricsError>;
}
Available on crate feature metrics only.
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§

source

fn register_pipeline(&self, pipeline: Weak<Pipeline, Global>)

Registers a MetricReader with a [Pipeline].

The pipeline argument allows the MetricReader to signal the sdk to collect and send aggregated metric measurements.

source

fn register_producer(&self, producer: Box<dyn MetricProducer, Global>)

Registers a an external Producer with this MetricReader.

The MetricProducer is used as a source of aggregated metric data which is incorporated into metrics collected from the SDK.

source

fn collect(&self, rm: &mut ResourceMetrics) -> Result<(), MetricsError>

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.

source

fn force_flush(&self, cx: &Context) -> Result<(), MetricsError>

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.

source

fn shutdown(&self) -> Result<(), MetricsError>

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.

Implementors§