diff --git a/Cargo.lock b/Cargo.lock index b5f5da5..09d568f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1578,6 +1578,15 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "matchers" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d1525a2a28c7f4fa0fc98bb91ae755d1e2d1505079e05539e35bc876b5d65ae9" +dependencies = [ + "regex-automata", +] + [[package]] name = "matchit" version = "0.8.4" @@ -3740,10 +3749,14 @@ version = "0.3.23" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cb7f578e5945fb242538965c2d0b04418d38ec25c79d160cd279bf0731c8d319" dependencies = [ + "matchers", "nu-ansi-term", + "once_cell", + "regex-automata", "sharded-slab", "smallvec", "thread_local", + "tracing", "tracing-core", "tracing-log", ] diff --git a/rnex-server/Cargo.toml b/rnex-server/Cargo.toml index efb991d..00ad54d 100644 --- a/rnex-server/Cargo.toml +++ b/rnex-server/Cargo.toml @@ -13,7 +13,7 @@ rnex-util = { path = "../rnex-util" } sentry = { version = "0.48.4", features = ["tracing"] } tokio = { version = "1.52.3", features = ["net"] } tracing = "0.1.44" -tracing-subscriber = "0.3.23" +tracing-subscriber = { version = "0.3.23", features = ["env-filter"] } [features] splatoon = ["v3-5-0"] diff --git a/rnex-server/src/lib.rs b/rnex-server/src/lib.rs index 8dfab52..c1003d7 100644 --- a/rnex-server/src/lib.rs +++ b/rnex-server/src/lib.rs @@ -22,6 +22,7 @@ pub use rnex_util as util; pub use tokio; pub use tracing; use tracing::{Instrument, Level, error, instrument, span}; +use tracing_subscriber::Layer; use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt}; #[derive(Debug, PartialEq, Eq, RmcSerialize)] @@ -32,7 +33,7 @@ pub struct ConnectionInitData { } #[derive(Debug, Default)] pub struct ModuleHolder { - modules: HashMap>, + modules: HashMap>, } // invariant: the [`OnceLock`] inside of the Arc MUST be initialized, @@ -80,11 +81,11 @@ impl WeakPassthroughInitModule { } impl ModuleHolder { - pub fn get_ref(&self) -> Option>> { - let module = self.modules.get(&TypeId::of::())?; - let Some(module) = module.downcast_ref::>>() else { - let type_name = type_name::(); - error!(type_name, "module type inconsistency"); + pub fn get_ref(&self) -> Option>> { + let module = self.modules.get(&TypeId::of::())?.clone(); + let Ok(module) = module.downcast::>() else { + let expected_type = type_name::(); + error!(expected_type, "module type inconsistency"); return None; }; @@ -96,10 +97,10 @@ impl ModuleHolder { /// this object which invokes the deref() or as_ref() method until /// AFTER the object has been initialized inside the module holder. /// Doing so will result in a panic. - pub fn get_ref_init_pt(&self) -> Option> { + pub fn get_ref_init_pt(&self) -> Option> { self.get_ref::().map(PassthroughInitModule) } - pub fn create_empty_module_slot(&mut self) { + pub fn create_empty_module_slot(&mut self) { self.modules .insert(TypeId::of::(), Arc::new(OnceLock::::new())); } @@ -113,7 +114,10 @@ impl ModuleHolder { /// `Ok(_)` on success containing the wrapped value or /// `Err(_)` on failiure to set containing the value you passed in #[instrument] - pub fn init_slot(&self, val: T) -> Result, T> { + pub fn init_slot( + &self, + val: T, + ) -> Result, T> { let Some(slot) = self.get_ref() else { return Err(val); }; @@ -221,7 +225,7 @@ macro_rules! launch_rnex_module_server { ); $(#[$($tt)*])* let $crate::paste::paste!{[]} = holder - .init_slot( + .init_slot::<<$module_type as $crate::RnexModule>::Manager>( <$module_type as $crate::RnexModule>::create_manager(&holder).await?, ) .expect("initialized manager twice"); @@ -346,7 +350,13 @@ pub async fn with_setup(f: impl AsyncFnOnce() -> anyhow::Result<()>) { None }; tracing_subscriber::registry() - .with(tracing_subscriber::fmt::layer()) + .with(tracing_subscriber::fmt::layer().with_filter( + tracing_subscriber::filter::FilterFn::new(|m| { + !m.module_path().is_some_and(|m| { + (m.starts_with("h2") | m.starts_with("reqwest") | m.starts_with("hyper_util")) + }) || (*m.level() <= Level::INFO) + }), + )) .with(sentry::integrations::tracing::layer()) .try_init() .expect("failed to init tracing subscriber"); @@ -464,3 +474,16 @@ pub static SERVER_PORT: LazyLock = LazyLock::new(|| { .and_then(|s| s.parse().ok()) .unwrap_or(10000) }); + +#[cfg(test)] +mod test { + use crate::ModuleHolder; + + #[test] + fn test_type_consistenct() { + let mut man = ModuleHolder::default(); + + man.create_empty_module_slot::(); + man.get_ref::(); + } +}