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 …
})
}
}