1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
//! Interfaces for exporting metrics
use async_trait::async_trait;

use opentelemetry::metrics::Result;

use crate::metrics::{
    data::ResourceMetrics,
    reader::{AggregationSelector, TemporalitySelector},
};

/// Exporter handles the delivery of metric data to external receivers.
///
/// This is the final component in the metric push pipeline.
#[async_trait]
pub trait PushMetricsExporter:
    AggregationSelector + TemporalitySelector + Send + Sync + 'static
{
    /// Export serializes and transmits metric data to a receiver.
    ///
    /// All retry logic must be contained in this function. The SDK does not
    /// implement any retry logic. All errors returned by this function are
    /// considered unrecoverable and will be reported to a configured error
    /// Handler.
    async fn export(&self, metrics: &mut ResourceMetrics) -> Result<()>;

    /// Flushes any metric data held by an exporter.
    async fn force_flush(&self) -> Result<()>;

    /// Releases any held computational resources.
    ///
    /// After Shutdown is called, calls to Export will perform no operation and
    /// instead will return an error indicating the shutdown state.
    fn shutdown(&self) -> Result<()>;
}