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

@@ -18,7 +18,6 @@ use http_api::TlsConfig;
use lighthouse_network::ListenAddress;
use lighthouse_network::{multiaddr::Protocol, Enr, Multiaddr, NetworkConfig, PeerIdSerialized};
use sensitive_url::SensitiveUrl;
use slog::{info, warn, Logger};
use std::cmp::max;
use std::fmt::Debug;
use std::fs;
@@ -29,6 +28,7 @@ use std::num::NonZeroU16;
use std::path::{Path, PathBuf};
use std::str::FromStr;
use std::time::Duration;
use tracing::{error, info, warn};
use types::graffiti::GraffitiString;
use types::{Checkpoint, Epoch, EthSpec, Hash256, PublicKeyBytes};
@@ -46,7 +46,6 @@ pub fn get_config<E: EthSpec>(
context: &RuntimeContext<E>,
) -> Result<ClientConfig, String> {
let spec = &context.eth2_config.spec;
let log = context.log();
let mut client_config = ClientConfig::default();
@@ -64,12 +63,10 @@ pub fn get_config<E: EthSpec>(
let stdin_inputs = cfg!(windows) || cli_args.get_flag(STDIN_INPUTS_FLAG);
if std::io::stdin().is_terminal() || stdin_inputs {
info!(
log,
"You are about to delete the chain database. This is irreversable \
and you will need to resync the chain."
);
info!(
log,
"Type 'confirm' to delete the database. Any other input will leave \
the database intact and Lighthouse will exit."
);
@@ -80,14 +77,13 @@ pub fn get_config<E: EthSpec>(
let freezer_db = client_config.get_freezer_db_path();
let blobs_db = client_config.get_blobs_db_path();
purge_db(chain_db, freezer_db, blobs_db)?;
info!(log, "Database was deleted.");
info!("Database was deleted.");
} else {
info!(log, "Database was not deleted. Lighthouse will now close.");
info!("Database was not deleted. Lighthouse will now close.");
std::process::exit(1);
}
} else {
warn!(
log,
"The `--purge-db` flag was passed, but Lighthouse is not running \
interactively. The database was not purged. Use `--purge-db-force` \
to purge the database without requiring confirmation."
@@ -104,7 +100,7 @@ pub fn get_config<E: EthSpec>(
let mut log_dir = client_config.data_dir().clone();
// remove /beacon from the end
log_dir.pop();
info!(log, "Data directory initialised"; "datadir" => log_dir.into_os_string().into_string().expect("Datadir should be a valid os string"));
info!(datadir = %log_dir.into_os_string().into_string().expect("Datadir should be a valid os string"), "Data directory initialised");
/*
* Networking
@@ -112,7 +108,7 @@ pub fn get_config<E: EthSpec>(
let data_dir_ref = client_config.data_dir().clone();
set_network_config(&mut client_config.network, cli_args, &data_dir_ref, log)?;
set_network_config(&mut client_config.network, cli_args, &data_dir_ref)?;
/*
* Staking flag
@@ -178,7 +174,6 @@ pub fn get_config<E: EthSpec>(
if cli_args.get_flag("light-client-server") {
warn!(
log,
"The --light-client-server flag is deprecated. The light client server is enabled \
by default"
);
@@ -259,8 +254,8 @@ pub fn get_config<E: EthSpec>(
// (e.g. using the --staking flag).
if cli_args.get_flag("staking") {
warn!(
log,
"Running HTTP server on port {}", client_config.http_api.listen_port
"Running HTTP server on port {}",
client_config.http_api.listen_port
);
}
@@ -274,11 +269,11 @@ pub fn get_config<E: EthSpec>(
*/
if cli_args.get_flag("dummy-eth1") {
warn!(log, "The --dummy-eth1 flag is deprecated");
warn!("The --dummy-eth1 flag is deprecated");
}
if cli_args.get_flag("eth1") {
warn!(log, "The --eth1 flag is deprecated");
warn!("The --eth1 flag is deprecated");
}
if let Some(val) = cli_args.get_one::<String>("eth1-blocks-per-log-query") {
@@ -306,18 +301,14 @@ pub fn get_config<E: EthSpec>(
endpoints.as_str(),
SensitiveUrl::parse,
"--execution-endpoint",
log,
)?;
// JWTs are required if `--execution-endpoint` is supplied. They can be either passed via
// file_path or directly as string.
let secret_file: PathBuf;
// Parse a single JWT secret from a given file_path, logging warnings if multiple are supplied.
if let Some(secret_files) = cli_args.get_one::<String>("execution-jwt") {
secret_file =
parse_only_one_value(secret_files, PathBuf::from_str, "--execution-jwt", log)?;
secret_file = parse_only_one_value(secret_files, PathBuf::from_str, "--execution-jwt")?;
// Check if the JWT secret key is passed directly via cli flag and persist it to the default
// file location.
} else if let Some(jwt_secret_key) = cli_args.get_one::<String>("execution-jwt-secret-key") {
@@ -340,8 +331,7 @@ pub fn get_config<E: EthSpec>(
// Parse and set the payload builder, if any.
if let Some(endpoint) = cli_args.get_one::<String>("builder") {
let payload_builder =
parse_only_one_value(endpoint, SensitiveUrl::parse, "--builder", log)?;
let payload_builder = parse_only_one_value(endpoint, SensitiveUrl::parse, "--builder")?;
el_config.builder_url = Some(payload_builder);
el_config.builder_user_agent = clap_utils::parse_optional(cli_args, "builder-user-agent")?;
@@ -442,7 +432,7 @@ pub fn get_config<E: EthSpec>(
}
if clap_utils::parse_optional::<u64>(cli_args, "slots-per-restore-point")?.is_some() {
warn!(log, "The slots-per-restore-point flag is deprecated");
warn!("The slots-per-restore-point flag is deprecated");
}
if let Some(backend) = clap_utils::parse_optional(cli_args, "beacon-node-backend")? {
@@ -515,10 +505,9 @@ pub fn get_config<E: EthSpec>(
client_config.eth1.set_block_cache_truncation::<E>(spec);
info!(
log,
"Deposit contract";
"deploy_block" => client_config.eth1.deposit_contract_deploy_block,
"address" => &client_config.eth1.deposit_contract_address
deploy_block = client_config.eth1.deposit_contract_deploy_block,
address = &client_config.eth1.deposit_contract_address,
"Deposit contract"
);
// Only append network config bootnodes if discovery is not disabled
@@ -912,10 +901,7 @@ pub fn get_config<E: EthSpec>(
}
/// Gets the listening_addresses for lighthouse based on the cli options.
pub fn parse_listening_addresses(
cli_args: &ArgMatches,
log: &Logger,
) -> Result<ListenAddress, String> {
pub fn parse_listening_addresses(cli_args: &ArgMatches) -> Result<ListenAddress, String> {
let listen_addresses_str = cli_args
.get_many::<String>("listen-address")
.unwrap_or_default();
@@ -1018,7 +1004,7 @@ pub fn parse_listening_addresses(
(None, Some(ipv6)) => {
// A single ipv6 address was provided. Set the ports
if cli_args.value_source("port6") == Some(ValueSource::CommandLine) {
warn!(log, "When listening only over IPv6, use the --port flag. The value of --port6 will be ignored.");
warn!("When listening only over IPv6, use the --port flag. The value of --port6 will be ignored.");
}
// If we are only listening on ipv6 and the user has specified --port6, lets just use
@@ -1032,11 +1018,11 @@ pub fn parse_listening_addresses(
.unwrap_or(port);
if maybe_disc6_port.is_some() {
warn!(log, "When listening only over IPv6, use the --discovery-port flag. The value of --discovery-port6 will be ignored.")
warn!("When listening only over IPv6, use the --discovery-port flag. The value of --discovery-port6 will be ignored.")
}
if maybe_quic6_port.is_some() {
warn!(log, "When listening only over IPv6, use the --quic-port flag. The value of --quic-port6 will be ignored.")
warn!("When listening only over IPv6, use the --quic-port flag. The value of --quic-port6 will be ignored.")
}
// use zero ports if required. If not, use the specific udp port. If none given, use
@@ -1158,7 +1144,6 @@ pub fn set_network_config(
config: &mut NetworkConfig,
cli_args: &ArgMatches,
data_dir: &Path,
log: &Logger,
) -> Result<(), String> {
// If a network dir has been specified, override the `datadir` definition.
if let Some(dir) = cli_args.get_one::<String>("network-dir") {
@@ -1183,7 +1168,7 @@ pub fn set_network_config(
config.shutdown_after_sync = true;
}
config.set_listening_addr(parse_listening_addresses(cli_args, log)?);
config.set_listening_addr(parse_listening_addresses(cli_args)?);
// A custom target-peers command will overwrite the --proposer-only default.
if let Some(target_peers_str) = cli_args.get_one::<String>("target-peers") {
@@ -1211,10 +1196,10 @@ pub fn set_network_config(
.parse()
.map_err(|_| format!("Not valid as ENR nor Multiaddr: {}", addr))?;
if !multi.iter().any(|proto| matches!(proto, Protocol::Udp(_))) {
slog::error!(log, "Missing UDP in Multiaddr {}", multi.to_string());
error!(multiaddr = multi.to_string(), "Missing UDP in Multiaddr");
}
if !multi.iter().any(|proto| matches!(proto, Protocol::P2p(_))) {
slog::error!(log, "Missing P2P in Multiaddr {}", multi.to_string());
error!(multiaddr = multi.to_string(), "Missing P2P in Multiaddr");
}
multiaddrs.push(multi);
}
@@ -1249,7 +1234,7 @@ pub fn set_network_config(
})
.collect::<Result<Vec<PeerIdSerialized>, _>>()?;
if config.trusted_peers.len() >= config.target_peers {
slog::warn!(log, "More trusted peers than the target peer limit. This will prevent efficient peer selection criteria."; "target_peers" => config.target_peers, "trusted_peers" => config.trusted_peers.len());
warn!( target_peers = config.target_peers, trusted_peers = config.trusted_peers.len(),"More trusted peers than the target peer limit. This will prevent efficient peer selection criteria.");
}
}
@@ -1349,14 +1334,14 @@ pub fn set_network_config(
match addr.parse::<IpAddr>() {
Ok(IpAddr::V4(v4_addr)) => {
if let Some(used) = enr_ip4.as_ref() {
warn!(log, "More than one Ipv4 ENR address provided"; "used" => %used, "ignored" => %v4_addr)
warn!(used = %used, ignored = %v4_addr, "More than one Ipv4 ENR address provided")
} else {
enr_ip4 = Some(v4_addr)
}
}
Ok(IpAddr::V6(v6_addr)) => {
if let Some(used) = enr_ip6.as_ref() {
warn!(log, "More than one Ipv6 ENR address provided"; "used" => %used, "ignored" => %v6_addr)
warn!(used = %used, ignored = %v6_addr,"More than one Ipv6 ENR address provided")
} else {
enr_ip6 = Some(v6_addr)
}
@@ -1422,13 +1407,13 @@ pub fn set_network_config(
}
if parse_flag(cli_args, "disable-packet-filter") {
warn!(log, "Discv5 packet filter is disabled");
warn!("Discv5 packet filter is disabled");
config.discv5_config.enable_packet_filter = false;
}
if parse_flag(cli_args, "disable-discovery") {
config.disable_discovery = true;
warn!(log, "Discovery is disabled. New peers will not be found");
warn!("Discovery is disabled. New peers will not be found");
}
if parse_flag(cli_args, "disable-quic") {
@@ -1475,7 +1460,10 @@ pub fn set_network_config(
config.target_peers = 15;
}
config.proposer_only = true;
warn!(log, "Proposer-only mode enabled"; "info"=> "Do not connect a validator client to this node unless via the --proposer-nodes flag");
warn!(
info = "Proposer-only mode enabled",
"Do not connect a validator client to this node unless via the --proposer-nodes flag"
);
}
// The inbound rate limiter is enabled by default unless `disabled` via the
// `disable-inbound-rate-limiter` flag.
@@ -1533,7 +1521,6 @@ pub fn parse_only_one_value<F, T, U>(
cli_value: &str,
parser: F,
flag_name: &str,
log: &Logger,
) -> Result<T, String>
where
F: Fn(&str) -> Result<T, U>,
@@ -1547,11 +1534,10 @@ where
if values.len() > 1 {
warn!(
log,
"Multiple values provided";
"info" => "multiple values are deprecated, only the first value will be used",
"count" => values.len(),
"flag" => flag_name
info = "Multiple values provided",
count = values.len(),
flag = flag_name,
"multiple values are deprecated, only the first value will be used"
);
}