Trait Sink

Source
pub trait Sink: Send + Sync {
    // Required methods
    fn name(&self) -> &str;
    fn emit<'life0, 'life1, 'async_trait>(
        &'life0 self,
        event: &'life1 SinkEvent,
    ) -> Pin<Box<dyn Future<Output = Result<(), SinkError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;

    // Provided methods
    fn flush<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = Result<(), SinkError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait { ... }
    fn shutdown<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = Result<(), SinkError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait { ... }
}
Expand description

Sink for telemetry events.

Implementations should be cheap to clone (typically Arc<Sink>) and must be safe to call from multiple threads concurrently.

§Why async_trait

Rust’s native async fn in traits doesn’t support dyn Sink without BoxFuture wrappers, and adding the bound requires lifetime gymnastics at every call site. The async_trait macro gives object safety for the cost of one Box<dyn Future> per call. The Sink trait is consumed in only a handful of hot paths; if/when those migrate to generics we can drop async_trait.

Required Methods§

Source

fn name(&self) -> &str

Stable identifier for this sink (e.g. "jsonl", "stdout", "otlp").

Source

fn emit<'life0, 'life1, 'async_trait>( &'life0 self, event: &'life1 SinkEvent, ) -> Pin<Box<dyn Future<Output = Result<(), SinkError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Emit one event. Implementations should be non-blocking when possible.

Provided Methods§

Source

fn flush<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<(), SinkError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Flush any buffered events. Default is no-op.

Source

fn shutdown<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<(), SinkError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Release resources (close file handles, flush OTLP exporter, etc). Default is no-op.

Implementors§