Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(pathfinder): add tokio-console non-default feature #179

Merged
merged 1 commit into from
Mar 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions crates/pathfinder/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,17 @@ license = "MIT OR Apache-2.0"
name = "pathfinder_lib"
path = "src/lib.rs"

[features]
tokio-console = ["console-subscriber", "tokio/tracing"]

[dependencies]
anyhow = "1.0.44"
async-trait = "0.1.52"
# paritys scale codec locks us here
bitvec = "0.20.4"
bytes = "1.1.0"
clap = "2.33.3"
console-subscriber = { version = "0.1.3", optional = true }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't the tracing feature be enabled for tokio too?

enum-iterator = "0.7.0"
futures = { version = "0.3", default-features = false, features = ["std"] }
hex = "0.4.3"
Expand Down
36 changes: 31 additions & 5 deletions crates/pathfinder/src/bin/pathfinder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,8 @@ async fn main() -> anyhow::Result<()> {
if std::env::var_os("RUST_LOG").is_none() {
std::env::set_var("RUST_LOG", "info");
}
tracing_subscriber::fmt()
.with_env_filter(tracing_subscriber::EnvFilter::from_default_env())
.with_target(false)
.compact()
.init();

setup_tracing();

let config =
config::Configuration::parse_cmd_line_and_cfg_file().context("Parsing configuration")?;
Expand Down Expand Up @@ -93,3 +90,32 @@ async fn ethereum_transport(config: EthereumConfig) -> anyhow::Result<Web3<Http>

Ok(Web3::new(client))
}

#[cfg(feature = "tokio-console")]
fn setup_tracing() {
use tracing_subscriber::prelude::*;

// EnvFilter isn't really a Filter, so this we need this ugly workaround for filtering with it.
// See https://github.com/tokio-rs/tracing/issues/1868 for more details.
let env_filter = Arc::new(tracing_subscriber::EnvFilter::from_default_env());
let fmt_layer = tracing_subscriber::fmt::layer()
.with_target(false)
.compact()
.with_filter(tracing_subscriber::filter::dynamic_filter_fn(
move |m, c| env_filter.enabled(m, c.clone()),
));
let console_layer = console_subscriber::spawn();
tracing_subscriber::registry()
.with(fmt_layer)
.with(console_layer)
.init();
}

#[cfg(not(feature = "tokio-console"))]
fn setup_tracing() {
tracing_subscriber::fmt()
.with_env_filter(tracing_subscriber::EnvFilter::from_default_env())
.with_target(false)
.compact()
.init();
}