make tracing reload handles into a named map

Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
Jason Volk 2024-07-10 22:28:56 +00:00
parent db3c718ddc
commit 0023b09f5b
3 changed files with 40 additions and 25 deletions

View file

@ -4,7 +4,7 @@ use conduit::{
config,
config::Config,
debug_warn,
log::{capture, LogLevelReloadHandles, ReloadHandle},
log::{capture, LogLevelReloadHandles},
};
use tracing_subscriber::{layer::SubscriberExt, reload, EnvFilter, Layer, Registry};
@ -15,6 +15,8 @@ pub(crate) type TracingFlameGuard = ();
#[allow(clippy::redundant_clone)]
pub(crate) fn init(config: &Config) -> (LogLevelReloadHandles, TracingFlameGuard, Arc<capture::State>) {
let reload_handles = LogLevelReloadHandles::default();
let fmt_layer = tracing_subscriber::fmt::Layer::new();
let filter_layer = match EnvFilter::try_new(&config.log) {
Ok(s) => s,
@ -24,9 +26,8 @@ pub(crate) fn init(config: &Config) -> (LogLevelReloadHandles, TracingFlameGuard
},
};
let mut reload_handles = Vec::<Box<dyn ReloadHandle<EnvFilter> + Send + Sync>>::new();
let (fmt_reload_filter, fmt_reload_handle) = reload::Layer::new(filter_layer.clone());
reload_handles.push(Box::new(fmt_reload_handle));
reload_handles.add("format", Box::new(fmt_reload_handle));
let subscriber = Registry::default().with(fmt_layer.with_filter(fmt_reload_filter));
@ -38,7 +39,7 @@ pub(crate) fn init(config: &Config) -> (LogLevelReloadHandles, TracingFlameGuard
let subscriber = {
let sentry_layer = sentry_tracing::layer();
let (sentry_reload_filter, sentry_reload_handle) = reload::Layer::new(filter_layer.clone());
reload_handles.push(Box::new(sentry_reload_handle));
reload_handles.add("sentry", Box::new(sentry_reload_handle));
subscriber.with(sentry_layer.with_filter(sentry_reload_filter))
};
@ -73,7 +74,7 @@ pub(crate) fn init(config: &Config) -> (LogLevelReloadHandles, TracingFlameGuard
let telemetry = tracing_opentelemetry::layer().with_tracer(tracer);
let (jaeger_reload_filter, jaeger_reload_handle) = reload::Layer::new(filter_layer.clone());
reload_handles.push(Box::new(jaeger_reload_handle));
reload_handles.add("jaeger", Box::new(jaeger_reload_handle));
Some(telemetry.with_filter(jaeger_reload_filter))
} else {
None
@ -87,7 +88,7 @@ pub(crate) fn init(config: &Config) -> (LogLevelReloadHandles, TracingFlameGuard
#[cfg_attr(not(feature = "perf_measurements"), allow(clippy::let_unit_value))]
let flame_guard = ();
let ret = (LogLevelReloadHandles::new(reload_handles), flame_guard, cap_state);
let ret = (reload_handles, flame_guard, cap_state);
// Enable the tokio console. This is slightly kludgy because we're judggling
// compile-time and runtime conditions to elide it, each of those changing the