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

@@ -371,7 +371,6 @@ impl<E: EthSpec> Tester<E> {
}
let harness = BeaconChainHarness::<EphemeralHarnessType<E>>::builder(E::default())
.logger(logging::test_logger())
.spec(spec.clone())
.keypairs(vec![])
.chain_config(ChainConfig {

View File

@@ -105,7 +105,6 @@ async fn import_and_unlock(http_url: SensitiveUrl, priv_keys: &[&str], password:
impl<Engine: GenericExecutionEngine> TestRig<Engine> {
pub fn new(generic_engine: Engine) -> Self {
let log = logging::test_logger();
let runtime = Arc::new(
tokio::runtime::Builder::new_multi_thread()
.enable_all()
@@ -114,7 +113,12 @@ impl<Engine: GenericExecutionEngine> TestRig<Engine> {
);
let (runtime_shutdown, exit) = async_channel::bounded(1);
let (shutdown_tx, _) = futures::channel::mpsc::channel(1);
let executor = TaskExecutor::new(Arc::downgrade(&runtime), exit, log.clone(), shutdown_tx);
let executor = TaskExecutor::new(
Arc::downgrade(&runtime),
exit,
shutdown_tx,
"test".to_string(),
);
let mut spec = TEST_FORK.make_genesis_spec(MainnetEthSpec::default_spec());
spec.terminal_total_difficulty = Uint256::ZERO;
@@ -131,8 +135,7 @@ impl<Engine: GenericExecutionEngine> TestRig<Engine> {
default_datadir: execution_engine.datadir(),
..Default::default()
};
let execution_layer =
ExecutionLayer::from_config(config, executor.clone(), log.clone()).unwrap();
let execution_layer = ExecutionLayer::from_config(config, executor.clone()).unwrap();
ExecutionPair {
execution_engine,
execution_layer,
@@ -150,8 +153,7 @@ impl<Engine: GenericExecutionEngine> TestRig<Engine> {
default_datadir: execution_engine.datadir(),
..Default::default()
};
let execution_layer =
ExecutionLayer::from_config(config, executor, log.clone()).unwrap();
let execution_layer = ExecutionLayer::from_config(config, executor).unwrap();
ExecutionPair {
execution_engine,
execution_layer,

View File

@@ -8,14 +8,17 @@ edition = { workspace = true }
[dependencies]
clap = { workspace = true }
env_logger = { workspace = true }
environment = { workspace = true }
eth2_network_config = { workspace = true }
execution_layer = { workspace = true }
futures = { workspace = true }
kzg = { workspace = true }
logging = { workspace = true }
node_test_rig = { path = "../node_test_rig" }
parking_lot = { workspace = true }
rayon = { workspace = true }
sensitive_url = { path = "../../common/sensitive_url" }
serde_json = { workspace = true }
tokio = { workspace = true }
tracing-subscriber = { workspace = true }
types = { workspace = true }

View File

@@ -13,6 +13,12 @@ use rayon::prelude::*;
use std::cmp::max;
use std::sync::Arc;
use std::time::Duration;
use environment::tracing_common;
use logging::MetricsLayer;
use tracing_subscriber::prelude::*;
use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt};
use tokio::time::sleep;
use types::{Epoch, EthSpec, MinimalEthSpec};
@@ -82,23 +88,47 @@ pub fn run_basic_sim(matches: &ArgMatches) -> Result<(), String> {
})
.collect::<Vec<_>>();
let mut env = EnvironmentBuilder::minimal()
.initialize_logger(LoggerConfig {
let (
env_builder,
filter_layer,
_libp2p_discv5_layer,
file_logging_layer,
stdout_logging_layer,
_sse_logging_layer_opt,
logger_config,
_dependency_log_filter,
) = tracing_common::construct_logger(
LoggerConfig {
path: None,
debug_level: log_level.clone(),
logfile_debug_level: log_level.clone(),
debug_level: tracing_common::parse_level(&log_level.clone()),
logfile_debug_level: tracing_common::parse_level(&log_level.clone()),
log_format: None,
logfile_format: None,
log_color: false,
log_color: true,
logfile_color: true,
disable_log_timestamp: false,
max_log_size: 0,
max_log_number: 0,
compression: false,
is_restricted: true,
sse_logging: false,
})?
.multi_threaded_tokio_runtime()?
.build()?;
extra_info: false,
},
matches,
EnvironmentBuilder::minimal(),
);
if let Err(e) = tracing_subscriber::registry()
.with(filter_layer)
.with(file_logging_layer.with_filter(logger_config.logfile_debug_level))
.with(stdout_logging_layer.with_filter(logger_config.debug_level))
.with(MetricsLayer)
.try_init()
{
eprintln!("Failed to initialize dependency logging: {e}");
}
let mut env = env_builder.multi_threaded_tokio_runtime()?.build()?;
let mut spec = (*env.eth2_config.spec).clone();

View File

@@ -3,7 +3,9 @@ use crate::{checks, LocalNetwork};
use clap::ArgMatches;
use crate::retry::with_retry;
use environment::tracing_common;
use futures::prelude::*;
use logging::MetricsLayer;
use node_test_rig::{
environment::{EnvironmentBuilder, LoggerConfig},
testing_validator_config, ValidatorFiles,
@@ -13,8 +15,9 @@ use std::cmp::max;
use std::sync::Arc;
use std::time::Duration;
use tokio::time::sleep;
use tracing_subscriber::prelude::*;
use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt};
use types::{Epoch, EthSpec, MinimalEthSpec};
const END_EPOCH: u64 = 16;
const GENESIS_DELAY: u64 = 32;
const ALTAIR_FORK_EPOCH: u64 = 0;
@@ -89,23 +92,49 @@ pub fn run_fallback_sim(matches: &ArgMatches) -> Result<(), String> {
})
.collect::<Vec<_>>();
let mut env = EnvironmentBuilder::minimal()
.initialize_logger(LoggerConfig {
let (
env_builder,
filter_layer,
libp2p_discv5_layer,
file_logging_layer,
stdout_logging_layer,
_sse_logging_layer_opt,
logger_config,
dependency_log_filter,
) = tracing_common::construct_logger(
LoggerConfig {
path: None,
debug_level: log_level.clone(),
logfile_debug_level: log_level.clone(),
debug_level: tracing_common::parse_level(&log_level.clone()),
logfile_debug_level: tracing_common::parse_level(&log_level.clone()),
log_format: None,
logfile_format: None,
log_color: false,
log_color: true,
logfile_color: false,
disable_log_timestamp: false,
max_log_size: 0,
max_log_number: 0,
compression: false,
is_restricted: true,
sse_logging: false,
})?
.multi_threaded_tokio_runtime()?
.build()?;
extra_info: false,
},
matches,
EnvironmentBuilder::minimal(),
);
if let Err(e) = tracing_subscriber::registry()
.with(dependency_log_filter)
.with(filter_layer)
.with(file_logging_layer.with_filter(logger_config.logfile_debug_level))
.with(stdout_logging_layer.with_filter(logger_config.debug_level))
.with(libp2p_discv5_layer)
.with(MetricsLayer)
.try_init()
{
eprintln!("Failed to initialize dependency logging: {e}");
}
let mut env = env_builder.multi_threaded_tokio_runtime()?.build()?;
let mut spec = (*env.eth2_config.spec).clone();

View File

@@ -1,9 +0,0 @@
[package]
name = "test-test_logger"
version = "0.1.0"
edition = { workspace = true }
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
logging = { workspace = true }
slog = { workspace = true }

View File

@@ -1,22 +0,0 @@
use slog::{info, Logger};
pub struct Config {
log: Logger,
}
pub fn fn_with_logging(config: &Config) {
info!(&config.log, "hi");
}
#[cfg(test)]
mod tests {
use super::*;
use logging::test_logger;
#[test]
fn test_fn_with_logging() {
let config = Config { log: test_logger() };
fn_with_logging(&config);
}
}

View File

@@ -10,5 +10,5 @@ mockito = { workspace = true }
regex = { workspace = true }
sensitive_url = { workspace = true }
serde_json = { workspace = true }
slog = { workspace = true }
tracing = { workspace = true }
types = { workspace = true }

View File

@@ -1,20 +1,18 @@
use eth2::types::{GenericResponse, SyncingData};
use eth2::{BeaconNodeHttpClient, StatusCode, Timeouts};
use logging::test_logger;
use mockito::{Matcher, Mock, Server, ServerGuard};
use regex::Regex;
use sensitive_url::SensitiveUrl;
use slog::{info, Logger};
use std::marker::PhantomData;
use std::str::FromStr;
use std::sync::{Arc, Mutex};
use std::time::Duration;
use tracing::info;
use types::{ChainSpec, ConfigAndPreset, EthSpec, SignedBlindedBeaconBlock};
pub struct MockBeaconNode<E: EthSpec> {
server: ServerGuard,
pub beacon_api_client: BeaconNodeHttpClient,
log: Logger,
_phantom: PhantomData<E>,
pub received_blocks: Arc<Mutex<Vec<SignedBlindedBeaconBlock<E>>>>,
}
@@ -27,11 +25,9 @@ impl<E: EthSpec> MockBeaconNode<E> {
SensitiveUrl::from_str(&server.url()).unwrap(),
Timeouts::set_all(Duration::from_secs(1)),
);
let log = test_logger();
Self {
server,
beacon_api_client,
log,
_phantom: PhantomData,
received_blocks: Arc::new(Mutex::new(Vec::new())),
}
@@ -69,7 +65,6 @@ impl<E: EthSpec> MockBeaconNode<E> {
/// Mocks the `post_beacon_blinded_blocks_v2_ssz` response with an optional `delay`.
pub fn mock_post_beacon_blinded_blocks_v2_ssz(&mut self, delay: Duration) -> Mock {
let path_pattern = Regex::new(r"^/eth/v2/beacon/blinded_blocks$").unwrap();
let log = self.log.clone();
let url = self.server.url();
let received_blocks = Arc::clone(&self.received_blocks);
@@ -80,7 +75,6 @@ impl<E: EthSpec> MockBeaconNode<E> {
.with_status(200)
.with_body_from_request(move |request| {
info!(
log,
"{}",
format!(
"Received published block request on server {} with delay {} s",

View File

@@ -25,7 +25,6 @@ mod tests {
use initialized_validators::{
load_pem_certificate, load_pkcs12_identity, InitializedValidators,
};
use logging::test_logger;
use parking_lot::Mutex;
use reqwest::Client;
use serde::Serialize;
@@ -316,7 +315,6 @@ mod tests {
using_web3signer: bool,
spec: Arc<ChainSpec>,
) -> Self {
let log = test_logger();
let validator_dir = TempDir::new().unwrap();
let config = initialized_validators::Config::default();
@@ -325,7 +323,6 @@ mod tests {
validator_definitions,
validator_dir.path().into(),
config.clone(),
log.clone(),
)
.await
.unwrap();
@@ -340,8 +337,12 @@ mod tests {
);
let (runtime_shutdown, exit) = async_channel::bounded(1);
let (shutdown_tx, _) = futures::channel::mpsc::channel(1);
let executor =
TaskExecutor::new(Arc::downgrade(&runtime), exit, log.clone(), shutdown_tx);
let executor = TaskExecutor::new(
Arc::downgrade(&runtime),
exit,
shutdown_tx,
"test".to_string(),
);
let slashing_db_path = validator_dir.path().join(SLASHING_PROTECTION_FILENAME);
let slashing_protection = SlashingDatabase::open_or_create(&slashing_db_path).unwrap();
@@ -365,7 +366,6 @@ mod tests {
slot_clock,
&config,
executor,
log.clone(),
);
Self {