opentelemetry_sdk/metrics/
exporter.rs

1//! Interfaces for exporting metrics
2
3use crate::error::OTelSdkResult;
4use std::time::Duration;
5
6use crate::metrics::data::ResourceMetrics;
7
8use super::Temporality;
9
10/// Exporter handles the delivery of metric data to external receivers.
11///
12/// This is the final component in the metric push pipeline.
13pub trait PushMetricExporter: Send + Sync + 'static {
14    /// Export serializes and transmits metric data to a receiver.
15    ///
16    /// All retry logic must be contained in this function. The SDK does not
17    /// implement any retry logic. All errors returned by this function are
18    /// considered unrecoverable and will be logged.
19    fn export(
20        &self,
21        metrics: &ResourceMetrics,
22    ) -> impl std::future::Future<Output = OTelSdkResult> + Send;
23
24    /// Flushes any metric data held by an exporter.
25    fn force_flush(&self) -> OTelSdkResult;
26
27    /// Releases any held computational resources.
28    ///
29    /// After Shutdown is called, calls to Export will perform no operation and
30    /// instead will return an error indicating the shutdown state.
31    fn shutdown_with_timeout(&self, timeout: Duration) -> OTelSdkResult;
32
33    /// Shutdown with the default timeout of 5 seconds.
34    fn shutdown(&self) -> OTelSdkResult {
35        self.shutdown_with_timeout(Duration::from_secs(5))
36    }
37
38    /// Access the [Temporality] of the MetricExporter.
39    fn temporality(&self) -> Temporality;
40}