From a37323851c3f09a116430a0a37000d41842d578f Mon Sep 17 00:00:00 2001 From: Arpad Borsos Date: Tue, 20 Feb 2024 10:03:59 +0100 Subject: [PATCH 1/2] Move `tracing` init into its own file Also consolidates all the usage sites and removes unused feature flags --- Cargo.lock | 14 +------ Cargo.toml | 1 - crates/symbolicator-service/Cargo.toml | 1 + crates/symbolicator-service/src/lib.rs | 1 + crates/symbolicator-service/src/logging.rs | 24 +++++++++++ crates/symbolicator-stress/Cargo.toml | 1 - crates/symbolicator-stress/src/logging.rs | 47 ++++------------------ crates/symbolicator-test/Cargo.toml | 2 +- crates/symbolicator/Cargo.toml | 1 - crates/symbolicator/src/logging.rs | 14 ++----- crates/symbolicli/Cargo.toml | 2 +- 11 files changed, 39 insertions(+), 69 deletions(-) create mode 100644 crates/symbolicator-service/src/logging.rs diff --git a/Cargo.lock b/Cargo.lock index 02d07091c..942606744 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2653,15 +2653,6 @@ dependencies = [ "libc", ] -[[package]] -name = "num_threads" -version = "0.1.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c7398b9c8b70908f6371f47ed36737907c87c52af34c268fed0bf0ceb92ead9" -dependencies = [ - "libc", -] - [[package]] name = "object" version = "0.32.2" @@ -4395,7 +4386,6 @@ dependencies = [ "tower-layer", "tower-service", "tracing", - "tracing-subscriber", "url", "uuid", ] @@ -4519,6 +4509,7 @@ dependencies = [ "tokio", "tokio-util", "tracing", + "tracing-subscriber", "url", "uuid", "zip", @@ -4561,7 +4552,6 @@ dependencies = [ "symbolicator-test", "tempfile", "tokio", - "tracing-subscriber", ] [[package]] @@ -4774,9 +4764,7 @@ checksum = "c8248b6521bb14bc45b4067159b9b6ad792e2d6d754d6c41fb50e29fefe38749" dependencies = [ "deranged", "itoa", - "libc", "num-conv", - "num_threads", "powerfmt", "serde", "time-core", diff --git a/Cargo.toml b/Cargo.toml index 9ef520ac6..35c36bfea 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -43,7 +43,6 @@ reqwest = { git = "https://github.com/getsentry/reqwest", branch = "restricted-c # This patch adds limited "templated lambdas" demangling support cpp_demangle = { git = "https://github.com/getsentry/cpp_demangle", branch = "sentry-patches" } - # For local development: uncomment the following three lines (and adjust the path if necessary) # to use a local symbolic checkout everywhere. # This only works for the very specific crate listed here, and not for its dependency tree. diff --git a/crates/symbolicator-service/Cargo.toml b/crates/symbolicator-service/Cargo.toml index d2b24c759..a0de76119 100644 --- a/crates/symbolicator-service/Cargo.toml +++ b/crates/symbolicator-service/Cargo.toml @@ -41,6 +41,7 @@ thiserror = "1.0.31" tokio = { version = "1.24.2", features = ["rt", "macros", "fs"] } tokio-util = { version = "0.7.1", features = ["io"] } tracing = "0.1.34" +tracing-subscriber = { version = "0.3.17", features = ["env-filter", "time", "json"] } url = { version = "2.2.0", features = ["serde"] } uuid = { version = "1.0.0", features = ["v4", "serde"] } zip = { version = "0.6.4", default-features = false, features = ["deflate"] } diff --git a/crates/symbolicator-service/src/lib.rs b/crates/symbolicator-service/src/lib.rs index 0b58d4666..98d4f0ab3 100644 --- a/crates/symbolicator-service/src/lib.rs +++ b/crates/symbolicator-service/src/lib.rs @@ -8,6 +8,7 @@ pub mod caches; pub mod caching; pub mod config; pub mod download; +pub mod logging; pub mod objects; pub mod services; pub mod source_context; diff --git a/crates/symbolicator-service/src/logging.rs b/crates/symbolicator-service/src/logging.rs new file mode 100644 index 000000000..4a551e6f2 --- /dev/null +++ b/crates/symbolicator-service/src/logging.rs @@ -0,0 +1,24 @@ +use tracing_subscriber::fmt::time::UtcTime; +use tracing_subscriber::fmt::{fmt, MakeWriter}; +use tracing_subscriber::prelude::*; +use tracing_subscriber::util::SubscriberInitExt; + +pub fn init_json_logging(env_filter: &str, make_writer: W) +where + W: for<'writer> MakeWriter<'writer> + Send + Sync + 'static, +{ + fmt() + .with_timer(UtcTime::rfc_3339()) + .with_target(true) + .with_env_filter(env_filter) + .json() + .flatten_event(true) + .with_current_span(true) + .with_span_list(true) + .with_file(true) + .with_line_number(true) + .with_writer(make_writer) + .finish() + .with(sentry::integrations::tracing::layer()) + .init(); +} diff --git a/crates/symbolicator-stress/Cargo.toml b/crates/symbolicator-stress/Cargo.toml index 23c1c4e0b..90d12ee12 100644 --- a/crates/symbolicator-stress/Cargo.toml +++ b/crates/symbolicator-stress/Cargo.toml @@ -21,7 +21,6 @@ symbolicator-service = { path = "../symbolicator-service" } symbolicator-test = { path = "../symbolicator-test" } tempfile = "3.2.0" tokio = { version = "1.24.2", features = ["rt-multi-thread", "macros", "time", "sync"] } -tracing-subscriber = "0.3.17" [target.'cfg(not(target_env = "msvc"))'.dependencies] jemallocator = { version = "0.5", features = ["unprefixed_malloc_on_supported_platforms"] } diff --git a/crates/symbolicator-stress/src/logging.rs b/crates/symbolicator-stress/src/logging.rs index c5479b5c1..3c40807cd 100644 --- a/crates/symbolicator-stress/src/logging.rs +++ b/crates/symbolicator-stress/src/logging.rs @@ -1,14 +1,10 @@ use std::collections::BTreeMap; use std::env; use std::future::Future; -use std::io::Write; use std::net::{SocketAddr, TcpListener, UdpSocket}; use std::pin::Pin; -use symbolicator_service::metrics; -use tracing_subscriber::fmt::fmt; -use tracing_subscriber::fmt::time::UtcTime; -use tracing_subscriber::prelude::*; +use symbolicator_service::{logging, metrics}; #[derive(Debug, Default)] pub struct Config { @@ -61,27 +57,12 @@ pub fn init(config: Config) -> Guard { } if config.tracing { - let rust_log = "INFO"; - let subscriber = fmt() - .with_timer(UtcTime::rfc_3339()) - .with_target(true) - .with_env_filter(rust_log); - - // we want all the tracing machinery to be active, but not spam the console, - // so redirect everything into the void: - let subscriber = subscriber.with_writer(|| NoopWriter); - - // this should mimic the settings used in production: - subscriber - .json() - .flatten_event(true) - .with_current_span(true) - .with_span_list(true) - .with_file(true) - .with_line_number(true) - .finish() - .with(sentry::integrations::tracing::layer()) - .init(); + let env_filter = "INFO,\ + minidump=ERROR,\ + trust_dns_proto=WARN"; + // we want all the tracing machinery to be active and use the production JSON output, + // but not spam the console, so redirect everything into the void (`std::io::sink`): + logging::init_json_logging(env_filter, std::io::sink); } if config.metrics { @@ -111,17 +92,3 @@ pub fn init(config: Config) -> Guard { guard } - -struct NoopWriter; -impl Write for NoopWriter { - fn write(&mut self, buf: &[u8]) -> std::io::Result { - // try to prevent the compiler from optimizing away all the formatting code: - let buf = std::hint::black_box(buf); - - Ok(buf.len()) - } - - fn flush(&mut self) -> std::io::Result<()> { - Ok(()) - } -} diff --git a/crates/symbolicator-test/Cargo.toml b/crates/symbolicator-test/Cargo.toml index 4e757c092..691eea090 100644 --- a/crates/symbolicator-test/Cargo.toml +++ b/crates/symbolicator-test/Cargo.toml @@ -17,4 +17,4 @@ symbolicator-sources = { path = "../symbolicator-sources" } tempfile = "3.2.0" tokio = { version = "1.26.0", features = ["rt", "macros", "fs"] } tower-http = { version = "0.5.0", features = ["fs", "trace"] } -tracing-subscriber = { version = "0.3.17", features = ["tracing-log", "local-time", "env-filter", "json"] } +tracing-subscriber = { version = "0.3.17", features = ["env-filter"] } diff --git a/crates/symbolicator/Cargo.toml b/crates/symbolicator/Cargo.toml index 57f4dd247..f39e94cf8 100644 --- a/crates/symbolicator/Cargo.toml +++ b/crates/symbolicator/Cargo.toml @@ -36,7 +36,6 @@ tower = "0.4" tower-layer = "0.3" tower-service = "0.3" tracing = "0.1.34" -tracing-subscriber = { version = "0.3.17", features = ["tracing-log", "local-time", "env-filter", "json"] } url = { version = "2.2.0", features = ["serde"] } uuid = { version = "1.0.0", features = ["v4", "serde"] } diff --git a/crates/symbolicator/src/logging.rs b/crates/symbolicator/src/logging.rs index 85aa1f9e3..721d8294a 100644 --- a/crates/symbolicator/src/logging.rs +++ b/crates/symbolicator/src/logging.rs @@ -1,5 +1,6 @@ use std::env; +use symbolicator_service::logging::init_json_logging; use tracing::level_filters::LevelFilter; use tracing_subscriber::fmt::fmt; use tracing_subscriber::fmt::time::UtcTime; @@ -52,7 +53,7 @@ pub fn init_logging(config: &Config) { let subscriber = fmt() .with_timer(UtcTime::rfc_3339()) .with_target(true) - .with_env_filter(rust_log); + .with_env_filter(&rust_log); match (config.logging.format, console::user_attended()) { (LogFormat::Auto, true) | (LogFormat::Pretty, _) => subscriber @@ -66,16 +67,7 @@ pub fn init_logging(config: &Config) { .finish() .with(sentry::integrations::tracing::layer()) .init(), - (LogFormat::Json, _) => subscriber - .json() - .flatten_event(true) - .with_current_span(true) - .with_span_list(true) - .with_file(true) - .with_line_number(true) - .finish() - .with(sentry::integrations::tracing::layer()) - .init(), + (LogFormat::Json, _) => init_json_logging(&rust_log, std::io::stdout), } } diff --git a/crates/symbolicli/Cargo.toml b/crates/symbolicli/Cargo.toml index f7a2eb150..7072a2723 100644 --- a/crates/symbolicli/Cargo.toml +++ b/crates/symbolicli/Cargo.toml @@ -23,5 +23,5 @@ tempfile = "3.3.0" tokio = { version = "1.24.2", features = ["rt-multi-thread", "macros", "time", "sync"] } toml = "0.8.0" tracing = "0.1.37" -tracing-subscriber = { version = "0.3.17", features = ["tracing-log", "local-time", "env-filter", "json"] } +tracing-subscriber = { version = "0.3.17", features = ["env-filter"] } url = "2.3.1" From f7c141e5d031e0e2559c8e6d2d2a39473ff0f9e7 Mon Sep 17 00:00:00 2001 From: Arpad Borsos Date: Wed, 28 Feb 2024 11:03:37 +0100 Subject: [PATCH 2/2] fix broken imports --- Cargo.lock | 1 + crates/symbolicator/Cargo.toml | 1 + 2 files changed, 2 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index 942606744..c5ac388b1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4386,6 +4386,7 @@ dependencies = [ "tower-layer", "tower-service", "tracing", + "tracing-subscriber", "url", "uuid", ] diff --git a/crates/symbolicator/Cargo.toml b/crates/symbolicator/Cargo.toml index f39e94cf8..5be4d7cb0 100644 --- a/crates/symbolicator/Cargo.toml +++ b/crates/symbolicator/Cargo.toml @@ -36,6 +36,7 @@ tower = "0.4" tower-layer = "0.3" tower-service = "0.3" tracing = "0.1.34" +tracing-subscriber = { version = "0.3.17", features = ["env-filter", "time"] } url = { version = "2.2.0", features = ["serde"] } uuid = { version = "1.0.0", features = ["v4", "serde"] }