From 75da1b8070184b84b6c27cfdd757f554e6f3f8df Mon Sep 17 00:00:00 2001 From: Bryan Stitt Date: Thu, 12 Oct 2023 14:12:46 -0700 Subject: [PATCH] make tokio-console and the normal logging work together --- .vscode/settings.json | 3 +++ Cargo.lock | 8 ++++---- Dockerfile | 2 +- web3_proxy/Cargo.toml | 3 --- web3_proxy_cli/Cargo.toml | 6 ++++-- web3_proxy_cli/src/main.rs | 39 +++++++++++++++++++++----------------- 6 files changed, 34 insertions(+), 27 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 77c613c7..147a8719 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -5,5 +5,8 @@ "rust-analyzer.checkOnSave.extraArgs": [ "--target-dir", "target/rust-analyzer" + ], + "rust-analyzer.cargo.features": [ + "tokio-console" ] } \ No newline at end of file diff --git a/Cargo.lock b/Cargo.lock index 05d3cc12..889246b3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4476,9 +4476,9 @@ dependencies = [ [[package]] name = "rustix" -version = "0.38.18" +version = "0.38.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a74ee2d7c2581cd139b42447d7d9389b889bdaad3a73f1ebb16f2a3237bb19c" +checksum = "745ecfa778e66b2b63c88a61cb36e0eea109e803b0b86bf9879fbc77c70e86ed" dependencies = [ "bitflags 2.4.0", "errno", @@ -6587,7 +6587,6 @@ dependencies = [ "base64 0.21.4", "bytes", "chrono", - "console-subscriber", "deduped_broadcast", "deferred-rate-limiter", "derivative", @@ -6638,7 +6637,6 @@ dependencies = [ "test-log", "time", "tokio", - "tokio-console", "tokio-stream", "toml 0.8.2", "tower-http", @@ -6653,6 +6651,7 @@ dependencies = [ name = "web3_proxy_cli" version = "1.43.41" dependencies = [ + "console-subscriber", "env_logger", "parking_lot", "prettytable", @@ -6660,6 +6659,7 @@ dependencies = [ "serde_json", "test-log", "tokio", + "tokio-console", "tracing", "tracing-subscriber", "web3_proxy", diff --git a/Dockerfile b/Dockerfile index 113dab26..443f41fb 100644 --- a/Dockerfile +++ b/Dockerfile @@ -81,7 +81,7 @@ RUN --mount=type=cache,target=/root/.cargo/git \ FROM rust as rust_with_env # changing our features doesn't change any of the steps above -ENV WEB3_PROXY_FEATURES "deadlock_detection,stripe" +ENV WEB3_PROXY_FEATURES "deadlock_detection,stripe,tokio-console" # copy the app COPY . . diff --git a/web3_proxy/Cargo.toml b/web3_proxy/Cargo.toml index 447b6925..98dfcf52 100644 --- a/web3_proxy/Cargo.toml +++ b/web3_proxy/Cargo.toml @@ -12,7 +12,6 @@ mimalloc = ["dep:mimalloc"] rdkafka-src = ["rdkafka/cmake-build", "rdkafka/ssl-vendored"] stripe = ["dep:async-stripe"] tests-needing-docker = [] -tokio-console = ["dep:tokio-console", "dep:console-subscriber"] [dependencies] deduped_broadcast = { path = "../deduped_broadcast" } @@ -48,7 +47,6 @@ axum-macros = "0.3.8" base64 = "0.21.4" bytes = "1.5.0" chrono = { version = "0.4.31" } -console-subscriber = { version = "0.2.0", features = ["env-filter", "parking_lot"], optional = true } derivative = "2.2.0" derive_more = { version = "0.99.17", features = ["nightly"] } ethers = { version = "2.0.10", default-features = false, features = ["rustls", "ws"] } @@ -87,7 +85,6 @@ serde_prometheus = "0.2.4" strum = { version = "0.25.0", features = ["derive"] } time = { version = "0.3" } tokio = { version = "1.33.0", features = ["full", "tracing"] } -tokio-console = { version = "0.1.10", optional = true } tokio-stream = { version = "0.1.14", features = ["sync"] } toml = "0.8.2" tower-http = { version = "0.4.4", features = ["cors", "normalize-path", "sensitive-headers", "trace"] } diff --git a/web3_proxy_cli/Cargo.toml b/web3_proxy_cli/Cargo.toml index f57b6d32..5cd93c0f 100644 --- a/web3_proxy_cli/Cargo.toml +++ b/web3_proxy_cli/Cargo.toml @@ -7,22 +7,24 @@ default-run = "web3_proxy_cli" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [features] -default = [] +default = ["tokio-console"] deadlock_detection = ["parking_lot/deadlock_detection"] mimalloc = ["web3_proxy/mimalloc"] stripe = ["web3_proxy/stripe"] rdkafka-src = ["web3_proxy/rdkafka-src"] tests-needing-docker = ["web3_proxy/tests-needing-docker"] -tokio-console = ["web3_proxy/tokio-console"] +tokio-console = ["dep:tokio-console", "dep:console-subscriber"] [dependencies] web3_proxy = { path = "../web3_proxy" } +console-subscriber = { version = "0.2.0", features = ["env-filter", "parking_lot"], optional = true } parking_lot = { version = "0.12.1", features = ["arc_lock", "nightly"] } prettytable = { version = "0.10.0", default-features = false } serde = { version = "1.0.188" } serde_json = { version = "1.0.107", default-features = false, features = ["raw_value"] } +tokio-console = { version = "0.1.10", optional = true } tracing = "0.1" tracing-subscriber = { version = "0.3", features = ["env-filter"] } diff --git a/web3_proxy_cli/src/main.rs b/web3_proxy_cli/src/main.rs index d2e9713c..d2b63f43 100644 --- a/web3_proxy_cli/src/main.rs +++ b/web3_proxy_cli/src/main.rs @@ -115,12 +115,7 @@ fn main() -> anyhow::Result<()> { }); } - // TODO: can we run tokio_console and have our normal logs? - #[cfg(feature = "tokio_console")] - console_subscriber::init(); - // if RUST_LOG isn't set, configure a default - #[cfg(not(feature = "tokio_console"))] let mut rust_log = match std::env::var("RUST_LOG") { Ok(x) => x, Err(_) => match std::env::var("WEB3_PROXY_TRACE").map(|x| x == "true") { @@ -233,19 +228,29 @@ fn main() -> anyhow::Result<()> { } }); - tracing_subscriber::fmt() - // create a subscriber that uses the RUST_LOG env var for filtering levels - .with_env_filter(EnvFilter::builder().parse(rust_log)?) - // .with_env_filter(EnvFilter::from_default_env()) - // print a pretty output to the terminal - // TODO: this might be too verbose. have a config setting for this, too + let env_filter = EnvFilter::builder().parse(&rust_log)?; + let fmt_layer = tracing_subscriber::fmt::layer() .pretty() - // the root subscriber is ready - .finish() - // attach tracing layer. - .with(sentry_tracing::layer()) - // register as the default global subscriber - .init(); + .with_filter(env_filter); + + let env_filter = EnvFilter::builder().parse(rust_log)?; + let sentry_layer = sentry_tracing::layer().with_filter(env_filter); + + // build a `Subscriber` by combining layers + let tracing_registry = tracing_subscriber::registry(); + + #[cfg(feature = "tokio-console")] + { + let console_layer = console_subscriber::spawn(); + + tracing_registry + .with(console_layer) + .with(fmt_layer) + .with(sentry_layer) + .init(); + } + #[cfg(not(feature = "tokio-console"))] + tracing_registry.with(fmt_layer).with(sentry_layer).init(); info!(%APP_USER_AGENT);