make tokio-console and the normal logging work together

This commit is contained in:
Bryan Stitt 2023-10-12 14:12:46 -07:00
parent 06cd1cc3dd
commit 75da1b8070
6 changed files with 34 additions and 27 deletions

@ -5,5 +5,8 @@
"rust-analyzer.checkOnSave.extraArgs": [ "rust-analyzer.checkOnSave.extraArgs": [
"--target-dir", "--target-dir",
"target/rust-analyzer" "target/rust-analyzer"
],
"rust-analyzer.cargo.features": [
"tokio-console"
] ]
} }

8
Cargo.lock generated

@ -4476,9 +4476,9 @@ dependencies = [
[[package]] [[package]]
name = "rustix" name = "rustix"
version = "0.38.18" version = "0.38.19"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5a74ee2d7c2581cd139b42447d7d9389b889bdaad3a73f1ebb16f2a3237bb19c" checksum = "745ecfa778e66b2b63c88a61cb36e0eea109e803b0b86bf9879fbc77c70e86ed"
dependencies = [ dependencies = [
"bitflags 2.4.0", "bitflags 2.4.0",
"errno", "errno",
@ -6587,7 +6587,6 @@ dependencies = [
"base64 0.21.4", "base64 0.21.4",
"bytes", "bytes",
"chrono", "chrono",
"console-subscriber",
"deduped_broadcast", "deduped_broadcast",
"deferred-rate-limiter", "deferred-rate-limiter",
"derivative", "derivative",
@ -6638,7 +6637,6 @@ dependencies = [
"test-log", "test-log",
"time", "time",
"tokio", "tokio",
"tokio-console",
"tokio-stream", "tokio-stream",
"toml 0.8.2", "toml 0.8.2",
"tower-http", "tower-http",
@ -6653,6 +6651,7 @@ dependencies = [
name = "web3_proxy_cli" name = "web3_proxy_cli"
version = "1.43.41" version = "1.43.41"
dependencies = [ dependencies = [
"console-subscriber",
"env_logger", "env_logger",
"parking_lot", "parking_lot",
"prettytable", "prettytable",
@ -6660,6 +6659,7 @@ dependencies = [
"serde_json", "serde_json",
"test-log", "test-log",
"tokio", "tokio",
"tokio-console",
"tracing", "tracing",
"tracing-subscriber", "tracing-subscriber",
"web3_proxy", "web3_proxy",

@ -81,7 +81,7 @@ RUN --mount=type=cache,target=/root/.cargo/git \
FROM rust as rust_with_env FROM rust as rust_with_env
# changing our features doesn't change any of the steps above # 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 the app
COPY . . COPY . .

@ -12,7 +12,6 @@ mimalloc = ["dep:mimalloc"]
rdkafka-src = ["rdkafka/cmake-build", "rdkafka/ssl-vendored"] rdkafka-src = ["rdkafka/cmake-build", "rdkafka/ssl-vendored"]
stripe = ["dep:async-stripe"] stripe = ["dep:async-stripe"]
tests-needing-docker = [] tests-needing-docker = []
tokio-console = ["dep:tokio-console", "dep:console-subscriber"]
[dependencies] [dependencies]
deduped_broadcast = { path = "../deduped_broadcast" } deduped_broadcast = { path = "../deduped_broadcast" }
@ -48,7 +47,6 @@ axum-macros = "0.3.8"
base64 = "0.21.4" base64 = "0.21.4"
bytes = "1.5.0" bytes = "1.5.0"
chrono = { version = "0.4.31" } chrono = { version = "0.4.31" }
console-subscriber = { version = "0.2.0", features = ["env-filter", "parking_lot"], optional = true }
derivative = "2.2.0" derivative = "2.2.0"
derive_more = { version = "0.99.17", features = ["nightly"] } derive_more = { version = "0.99.17", features = ["nightly"] }
ethers = { version = "2.0.10", default-features = false, features = ["rustls", "ws"] } 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"] } strum = { version = "0.25.0", features = ["derive"] }
time = { version = "0.3" } time = { version = "0.3" }
tokio = { version = "1.33.0", features = ["full", "tracing"] } tokio = { version = "1.33.0", features = ["full", "tracing"] }
tokio-console = { version = "0.1.10", optional = true }
tokio-stream = { version = "0.1.14", features = ["sync"] } tokio-stream = { version = "0.1.14", features = ["sync"] }
toml = "0.8.2" toml = "0.8.2"
tower-http = { version = "0.4.4", features = ["cors", "normalize-path", "sensitive-headers", "trace"] } tower-http = { version = "0.4.4", features = ["cors", "normalize-path", "sensitive-headers", "trace"] }

@ -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 # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[features] [features]
default = [] default = ["tokio-console"]
deadlock_detection = ["parking_lot/deadlock_detection"] deadlock_detection = ["parking_lot/deadlock_detection"]
mimalloc = ["web3_proxy/mimalloc"] mimalloc = ["web3_proxy/mimalloc"]
stripe = ["web3_proxy/stripe"] stripe = ["web3_proxy/stripe"]
rdkafka-src = ["web3_proxy/rdkafka-src"] rdkafka-src = ["web3_proxy/rdkafka-src"]
tests-needing-docker = ["web3_proxy/tests-needing-docker"] tests-needing-docker = ["web3_proxy/tests-needing-docker"]
tokio-console = ["web3_proxy/tokio-console"] tokio-console = ["dep:tokio-console", "dep:console-subscriber"]
[dependencies] [dependencies]
web3_proxy = { path = "../web3_proxy" } 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"] } parking_lot = { version = "0.12.1", features = ["arc_lock", "nightly"] }
prettytable = { version = "0.10.0", default-features = false } prettytable = { version = "0.10.0", default-features = false }
serde = { version = "1.0.188" } serde = { version = "1.0.188" }
serde_json = { version = "1.0.107", default-features = false, features = ["raw_value"] } serde_json = { version = "1.0.107", default-features = false, features = ["raw_value"] }
tokio-console = { version = "0.1.10", optional = true }
tracing = "0.1" tracing = "0.1"
tracing-subscriber = { version = "0.3", features = ["env-filter"] } tracing-subscriber = { version = "0.3", features = ["env-filter"] }

@ -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 // if RUST_LOG isn't set, configure a default
#[cfg(not(feature = "tokio_console"))]
let mut rust_log = match std::env::var("RUST_LOG") { let mut rust_log = match std::env::var("RUST_LOG") {
Ok(x) => x, Ok(x) => x,
Err(_) => match std::env::var("WEB3_PROXY_TRACE").map(|x| x == "true") { Err(_) => match std::env::var("WEB3_PROXY_TRACE").map(|x| x == "true") {
@ -233,19 +228,29 @@ fn main() -> anyhow::Result<()> {
} }
}); });
tracing_subscriber::fmt() let env_filter = EnvFilter::builder().parse(&rust_log)?;
// create a subscriber that uses the RUST_LOG env var for filtering levels let fmt_layer = tracing_subscriber::fmt::layer()
.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
.pretty() .pretty()
// the root subscriber is ready .with_filter(env_filter);
.finish()
// attach tracing layer. let env_filter = EnvFilter::builder().parse(rust_log)?;
.with(sentry_tracing::layer()) let sentry_layer = sentry_tracing::layer().with_filter(env_filter);
// register as the default global subscriber
.init(); // 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); info!(%APP_USER_AGENT);