Skip to main content

TelemetryProvider

Trait TelemetryProvider 

Source
pub trait TelemetryProvider:
    Send
    + Sync
    + 'static {
    // Required method
    fn init(&self, service_name: &str) -> Result<()>;

    // Provided method
    fn on_shutdown(&self) -> Pin<Box<dyn Future<Output = ()> + Send>> { ... }
}
Expand description

Extension point for telemetry initialisation.

Wrapper crates supply a concrete implementation; socle calls init at the start of serve() and registers on_shutdown as a drain hook after the HTTP server stops.

use std::future::Future;
use std::pin::Pin;
use socle::ports::telemetry::TelemetryProvider;
use socle::Result;

struct MyOtelProvider;

impl TelemetryProvider for MyOtelProvider {
    fn init(&self, service_name: &str) -> Result<()> {
        // wire up the OTel SDK …
        Ok(())
    }

    fn on_shutdown(&self) -> Pin<Box<dyn Future<Output = ()> + Send>> {
        Box::pin(async {
            // flush spans and metrics …
        })
    }
}

Required Methods§

Source

fn init(&self, service_name: &str) -> Result<()>

Initialise telemetry for service_name. Called once before the HTTP server starts. Return an error to abort startup.

Provided Methods§

Source

fn on_shutdown(&self) -> Pin<Box<dyn Future<Output = ()> + Send>>

Async drain to run after the HTTP server stops (flush spans, metrics, etc.). Default is a no-op.

Implementors§