From 70023dfa1ce834188ea3d97f1075cb86b83e09df Mon Sep 17 00:00:00 2001 From: Miguel Fernandez Date: Tue, 17 Jan 2023 14:24:17 +0100 Subject: [PATCH] Only filter when an explicit level is provided --- query-engine/core/src/telemetry/helpers.rs | 39 ++++++++-------------- 1 file changed, 13 insertions(+), 26 deletions(-) diff --git a/query-engine/core/src/telemetry/helpers.rs b/query-engine/core/src/telemetry/helpers.rs index 5ac5e84e381e..2c94fe5775f7 100644 --- a/query-engine/core/src/telemetry/helpers.rs +++ b/query-engine/core/src/telemetry/helpers.rs @@ -56,18 +56,15 @@ pub enum QueryEngineLogLevel { } impl QueryEngineLogLevel { - fn level(self) -> String { + fn level(self) -> Option { match self { - Self::FromEnv => match std::env::var("QE_LOG_LEVEL") { - Ok(l) => l, - _ => "error".to_string(), - }, - Self::Override(l) => l, + Self::FromEnv => std::env::var("QE_LOG_LEVEL").ok(), + Self::Override(l) => Some(l), } } } -#[rustfmt::skip] +#[cfg_attr(rustfmt, rustfmt_skip)] pub fn env_filter(log_queries: bool, qe_log_level: QueryEngineLogLevel) -> EnvFilter { let mut filter = EnvFilter::from_default_env() .add_directive("tide=error".parse().unwrap()) @@ -76,14 +73,14 @@ pub fn env_filter(log_queries: bool, qe_log_level: QueryEngineLogLevel) -> EnvFi .add_directive("hyper=error".parse().unwrap()) .add_directive("tower=error".parse().unwrap()); - let level = qe_log_level.level(); - - filter = filter - .add_directive(format!("query_engine={}", &level).parse().unwrap()) - .add_directive(format!("query_core={}", &level).parse().unwrap()) - .add_directive(format!("query_connector={}", &level).parse().unwrap()) - .add_directive(format!("sql_query_connector={}", &level).parse().unwrap()) - .add_directive(format!("mongodb_query_connector={}", &level).parse().unwrap()); + if let Some(level) = qe_log_level.level() { + filter = filter + .add_directive(format!("query_engine={}", &level).parse().unwrap()) + .add_directive(format!("query_core={}", &level).parse().unwrap()) + .add_directive(format!("query_connector={}", &level).parse().unwrap()) + .add_directive(format!("sql_query_connector={}", &level).parse().unwrap()) + .add_directive(format!("mongodb_query_connector={}", &level).parse().unwrap()); + } if log_queries { filter = filter @@ -111,15 +108,5 @@ pub fn user_facing_filter(meta: &Metadata) -> bool { return true; } - // a quaint query event is always user facing - if meta.target() == "quaint::connector::metrics" && meta.name() == "quaint:query" { - return true; - } - - // a mongo query event is always user facing - if meta.target() == "mongodb_query_connector::query" { - return true; - } - - false + meta.target() == "quaint::connector::metrics" && meta.name() == "quaint:query" }