From b13a24790a6b67975c8bdae39db857d1b40c9c9c Mon Sep 17 00:00:00 2001 From: jonaro00 <54029719+jonaro00@users.noreply.github.com> Date: Wed, 31 May 2023 11:55:23 +0200 Subject: [PATCH 1/7] fix: Ignore span logs below WARN --- runtime/src/logger.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/runtime/src/logger.rs b/runtime/src/logger.rs index b51521f8f..1129df6dc 100644 --- a/runtime/src/logger.rs +++ b/runtime/src/logger.rs @@ -45,8 +45,16 @@ where format!("[span] {}", metadata.name()).into(), ); + let level = LogLevel::from(metadata.level()) as i32; + + // Ignore span logs from the default level for #[instrument] (INFO) and below. + // TODO: make this configurable + if level < LogLevel::Warn as i32 { + return; + } + LogItem { - level: LogLevel::from(metadata.level()) as i32, + level, timestamp: Some(Timestamp::from(SystemTime::from(datetime))), file: visitor.file.or_else(|| metadata.file().map(str::to_string)), line: visitor.line.or_else(|| metadata.line()), From 4a77cf5b5c80ab9d3ada6ac6f594df1e008c5589 Mon Sep 17 00:00:00 2001 From: jonaro00 <54029719+jonaro00@users.noreply.github.com> Date: Wed, 31 May 2023 12:14:22 +0200 Subject: [PATCH 2/7] modify test --- runtime/src/logger.rs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/runtime/src/logger.rs b/runtime/src/logger.rs index 1129df6dc..138bf665b 100644 --- a/runtime/src/logger.rs +++ b/runtime/src/logger.rs @@ -112,25 +112,28 @@ mod tests { let _guard = tracing_subscriber::registry().with(logger).set_default(); - let span = tracing::debug_span!("this is a span"); + let span = tracing::warn_span!("this is a warn span"); span.in_scope(|| { tracing::debug!("this is"); tracing::info!("hi"); + }); + let span = tracing::info_span!("this is an info span"); + span.in_scope(|| { tracing::warn!("from"); tracing::error!("logger"); }); assert_eq!( r.blocking_recv().map(to_tuple), - Some(("[span] this is a span".to_string(), LogLevel::Debug as i32)) + Some(("this is".to_string(), LogLevel::Debug as i32)) ); assert_eq!( r.blocking_recv().map(to_tuple), - Some(("this is".to_string(), LogLevel::Debug as i32)) + Some(("hi".to_string(), LogLevel::Info as i32)) ); assert_eq!( r.blocking_recv().map(to_tuple), - Some(("hi".to_string(), LogLevel::Info as i32)) + Some(("[span] this is an info span".to_string(), LogLevel::Debug as i32)) ); assert_eq!( r.blocking_recv().map(to_tuple), From 736e7269cedddef7341a48972a1ff2d6b7aef44d Mon Sep 17 00:00:00 2001 From: jonaro00 <54029719+jonaro00@users.noreply.github.com> Date: Wed, 31 May 2023 12:19:33 +0200 Subject: [PATCH 3/7] fmt --- runtime/src/logger.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/runtime/src/logger.rs b/runtime/src/logger.rs index 138bf665b..7e447e13f 100644 --- a/runtime/src/logger.rs +++ b/runtime/src/logger.rs @@ -133,7 +133,10 @@ mod tests { ); assert_eq!( r.blocking_recv().map(to_tuple), - Some(("[span] this is an info span".to_string(), LogLevel::Debug as i32)) + Some(( + "[span] this is an info span".to_string(), + LogLevel::Debug as i32 + )) ); assert_eq!( r.blocking_recv().map(to_tuple), From bd77905ec08bd65b2293018f5b03f15eb7527d77 Mon Sep 17 00:00:00 2001 From: jonaro00 <54029719+jonaro00@users.noreply.github.com> Date: Wed, 31 May 2023 16:39:45 +0200 Subject: [PATCH 4/7] move to before JsonVisitor, fix test --- runtime/src/logger.rs | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/runtime/src/logger.rs b/runtime/src/logger.rs index 7e447e13f..91711133a 100644 --- a/runtime/src/logger.rs +++ b/runtime/src/logger.rs @@ -35,15 +35,6 @@ where let item = { let metadata = attrs.metadata(); - let mut visitor = JsonVisitor::default(); - - attrs.record(&mut visitor); - - // Make the span name the log message - visitor.fields.insert( - "message".to_string(), - format!("[span] {}", metadata.name()).into(), - ); let level = LogLevel::from(metadata.level()) as i32; @@ -53,6 +44,15 @@ where return; } + let mut visitor = JsonVisitor::default(); + attrs.record(&mut visitor); + + // Make the span name the log message + visitor.fields.insert( + "message".to_string(), + format!("[span] {}", metadata.name()).into(), + ); + LogItem { level, timestamp: Some(Timestamp::from(SystemTime::from(datetime))), @@ -112,12 +112,12 @@ mod tests { let _guard = tracing_subscriber::registry().with(logger).set_default(); - let span = tracing::warn_span!("this is a warn span"); + let span = tracing::info_span!("this is an info span"); span.in_scope(|| { tracing::debug!("this is"); tracing::info!("hi"); }); - let span = tracing::info_span!("this is an info span"); + let span = tracing::warn_span!("this is a warn span"); span.in_scope(|| { tracing::warn!("from"); tracing::error!("logger"); @@ -134,8 +134,8 @@ mod tests { assert_eq!( r.blocking_recv().map(to_tuple), Some(( - "[span] this is an info span".to_string(), - LogLevel::Debug as i32 + "[span] this is a warn span".to_string(), + LogLevel::Warn as i32 )) ); assert_eq!( From 7cab7fdb6a8ffb3ca81b645f137467840b85f424 Mon Sep 17 00:00:00 2001 From: jonaro00 <54029719+jonaro00@users.noreply.github.com> Date: Thu, 1 Jun 2023 14:19:37 +0200 Subject: [PATCH 5/7] Convert later --- runtime/src/logger.rs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/runtime/src/logger.rs b/runtime/src/logger.rs index 91711133a..7d6dd7f95 100644 --- a/runtime/src/logger.rs +++ b/runtime/src/logger.rs @@ -7,7 +7,7 @@ use shuttle_proto::runtime::{LogItem, LogLevel}; use tokio::sync::mpsc::UnboundedSender; use tracing::{ span::{Attributes, Id}, - Subscriber, + Subscriber, Level, }; use tracing_subscriber::Layer; @@ -35,12 +35,11 @@ where let item = { let metadata = attrs.metadata(); - - let level = LogLevel::from(metadata.level()) as i32; + let level = metadata.level(); // Ignore span logs from the default level for #[instrument] (INFO) and below. // TODO: make this configurable - if level < LogLevel::Warn as i32 { + if level < &Level::WARN { return; } @@ -54,7 +53,7 @@ where ); LogItem { - level, + level: LogLevel::from(level) as i32, timestamp: Some(Timestamp::from(SystemTime::from(datetime))), file: visitor.file.or_else(|| metadata.file().map(str::to_string)), line: visitor.line.or_else(|| metadata.line()), From c4a3cc5eb30947e229a0d40e17e5fcd0304ef8bf Mon Sep 17 00:00:00 2001 From: jonaro00 <54029719+jonaro00@users.noreply.github.com> Date: Thu, 1 Jun 2023 14:22:30 +0200 Subject: [PATCH 6/7] fmt --- runtime/src/logger.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/src/logger.rs b/runtime/src/logger.rs index 7d6dd7f95..1e89f967f 100644 --- a/runtime/src/logger.rs +++ b/runtime/src/logger.rs @@ -7,7 +7,7 @@ use shuttle_proto::runtime::{LogItem, LogLevel}; use tokio::sync::mpsc::UnboundedSender; use tracing::{ span::{Attributes, Id}, - Subscriber, Level, + Level, Subscriber, }; use tracing_subscriber::Layer; From 2622f96d201867028d27370ffb8aa22abab15181 Mon Sep 17 00:00:00 2001 From: jonaro00 <54029719+jonaro00@users.noreply.github.com> Date: Thu, 1 Jun 2023 16:58:44 +0200 Subject: [PATCH 7/7] Flip the comparison like a burger --- runtime/src/logger.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/runtime/src/logger.rs b/runtime/src/logger.rs index 1e89f967f..4320a61a0 100644 --- a/runtime/src/logger.rs +++ b/runtime/src/logger.rs @@ -37,9 +37,9 @@ where let metadata = attrs.metadata(); let level = metadata.level(); - // Ignore span logs from the default level for #[instrument] (INFO) and below. + // Ignore span logs from the default level for #[instrument] (INFO) and below (greater than). // TODO: make this configurable - if level < &Level::WARN { + if level >= &Level::INFO { return; }