diff --git a/src/main.rs b/src/main.rs index 256a6ee..a6d75e2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,16 +1,18 @@ use hoc::{config::Settings, telemetry}; use std::net::TcpListener; -fn init() { +fn init() -> opentelemetry_jaeger::Uninstall { dotenv::dotenv().ok(); openssl_probe::init_ssl_cert_env_vars(); - telemetry::init_subscriber(telemetry::get_subscriber("hoc", "info")) + let (subscriber, uninstall) = telemetry::get_subscriber("hoc", "info"); + telemetry::init_subscriber(subscriber); + uninstall } #[actix_rt::main] async fn main() -> std::io::Result<()> { - init(); + let _uninstall = init(); // TODO: error handling let settings = Settings::load().expect("Cannot load config"); diff --git a/src/telemetry.rs b/src/telemetry.rs index c5f9954..b47c0b5 100644 --- a/src/telemetry.rs +++ b/src/telemetry.rs @@ -1,27 +1,32 @@ use opentelemetry::global; +use opentelemetry_jaeger::Uninstall; use tracing::{subscriber::set_global_default, Subscriber}; use tracing_bunyan_formatter::{BunyanFormattingLayer, JsonStorageLayer}; use tracing_log::LogTracer; use tracing_subscriber::{layer::SubscriberExt, EnvFilter, Registry}; -pub fn get_subscriber(name: &str, env_filter: &str) -> impl Subscriber + Send + Sync { +// TODO: don't pass `Uninstall` around... +pub fn get_subscriber(name: &str, env_filter: &str) -> (impl Subscriber + Send + Sync, Uninstall) { let env_filter = EnvFilter::try_from_default_env().unwrap_or_else(|_| EnvFilter::new(env_filter)); let formatting_layer = BunyanFormattingLayer::new(name.to_string(), std::io::stdout); global::set_text_map_propagator(opentelemetry_jaeger::Propagator::new()); - let (tracer, _) = opentelemetry_jaeger::new_pipeline() + let (tracer, uninstall) = opentelemetry_jaeger::new_pipeline() .with_service_name(name) .install() .expect("cannot install jaeger pipeline"); let telemetry = tracing_opentelemetry::layer().with_tracer(tracer); - Registry::default() - .with(telemetry) - .with(env_filter) - .with(JsonStorageLayer) - .with(formatting_layer) + ( + Registry::default() + .with(telemetry) + .with(env_filter) + .with(JsonStorageLayer) + .with(formatting_layer), + uninstall, + ) } pub fn init_subscriber(subscriber: impl Subscriber + Send + Sync) {