Integrate tracing (#6339)

Tracing Integration
- [reference](5bbf1859e9/projects/project-ideas.md (L297))


  - [x] replace slog & log with tracing throughout the codebase
- [x] implement custom crit log
- [x] make relevant changes in the formatter
- [x] replace sloggers
- [x] re-write SSE logging components

cc: @macladson @eserilev
This commit is contained in:
ThreeHrSleep
2025-03-13 04:01:05 +05:30
committed by GitHub
parent f23f984f85
commit d60c24ef1c
241 changed files with 9485 additions and 9328 deletions

View File

@@ -1,6 +1,5 @@
//! Creates a simple DISCV5 server which can be used to bootstrap an Eth2 network.
use clap::ArgMatches;
use slog::{o, Drain, Level, Logger};
use eth2_network_config::Eth2NetworkConfig;
mod cli;
@@ -8,10 +7,9 @@ pub mod config;
mod server;
pub use cli::cli_app;
use config::BootNodeConfig;
use tracing_subscriber::EnvFilter;
use types::{EthSpec, EthSpecId};
const LOG_CHANNEL_SIZE: usize = 2048;
/// Run the bootnode given the CLI configuration.
pub fn run(
lh_matches: &ArgMatches,
@@ -20,49 +18,27 @@ pub fn run(
eth2_network_config: &Eth2NetworkConfig,
debug_level: String,
) {
let debug_level = match debug_level.as_str() {
"trace" => log::Level::Trace,
"debug" => log::Level::Debug,
"info" => log::Level::Info,
"warn" => log::Level::Warn,
"error" => log::Level::Error,
"crit" => log::Level::Error,
_ => unreachable!(),
};
let filter_layer = EnvFilter::try_from_default_env()
.or_else(|_| EnvFilter::try_new(debug_level.to_string().to_lowercase()))
.unwrap();
// Setting up the initial logger format and building it.
let drain = {
let decorator = slog_term::TermDecorator::new().build();
let decorator = logging::AlignedTermDecorator::new(decorator, logging::MAX_MESSAGE_WIDTH);
let drain = slog_term::FullFormat::new(decorator).build().fuse();
slog_async::Async::new(drain)
.chan_size(LOG_CHANNEL_SIZE)
.build()
};
let drain = match debug_level {
log::Level::Info => drain.filter_level(Level::Info),
log::Level::Debug => drain.filter_level(Level::Debug),
log::Level::Trace => drain.filter_level(Level::Trace),
log::Level::Warn => drain.filter_level(Level::Warning),
log::Level::Error => drain.filter_level(Level::Error),
};
let log = Logger::root(drain.fuse(), o!());
tracing_subscriber::fmt()
.with_env_filter(filter_layer)
.init();
// Run the main function emitting any errors
if let Err(e) = match eth_spec_id {
EthSpecId::Minimal => {
main::<types::MinimalEthSpec>(lh_matches, bn_matches, eth2_network_config, log)
main::<types::MinimalEthSpec>(lh_matches, bn_matches, eth2_network_config)
}
EthSpecId::Mainnet => {
main::<types::MainnetEthSpec>(lh_matches, bn_matches, eth2_network_config, log)
main::<types::MainnetEthSpec>(lh_matches, bn_matches, eth2_network_config)
}
EthSpecId::Gnosis => {
main::<types::GnosisEthSpec>(lh_matches, bn_matches, eth2_network_config, log)
main::<types::GnosisEthSpec>(lh_matches, bn_matches, eth2_network_config)
}
} {
slog::crit!(slog_scope::logger(), "{}", e);
logging::crit!(?e);
}
}
@@ -70,7 +46,6 @@ fn main<E: EthSpec>(
lh_matches: &ArgMatches,
bn_matches: &ArgMatches,
eth2_network_config: &Eth2NetworkConfig,
log: slog::Logger,
) -> Result<(), String> {
// Builds a custom executor for the bootnode
let runtime = tokio::runtime::Builder::new_multi_thread()
@@ -83,7 +58,6 @@ fn main<E: EthSpec>(
lh_matches,
bn_matches,
eth2_network_config,
log,
))?;
Ok(())