mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-02 16:21:42 +00:00
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:
@@ -16,9 +16,7 @@ lighthouse_network = { workspace = true }
|
||||
log = { workspace = true }
|
||||
logging = { workspace = true }
|
||||
serde = { workspace = true }
|
||||
slog = { workspace = true }
|
||||
slog-async = { workspace = true }
|
||||
slog-scope = "4.3.0"
|
||||
slog-term = { workspace = true }
|
||||
tokio = { workspace = true }
|
||||
tracing = { workspace = true }
|
||||
tracing-subscriber = { workspace = true }
|
||||
types = { workspace = true }
|
||||
|
||||
@@ -53,9 +53,7 @@ impl<E: EthSpec> BootNodeConfig<E> {
|
||||
|
||||
let mut network_config = NetworkConfig::default();
|
||||
|
||||
let logger = slog_scope::logger();
|
||||
|
||||
set_network_config(&mut network_config, matches, &data_dir, &logger)?;
|
||||
set_network_config(&mut network_config, matches, &data_dir)?;
|
||||
|
||||
// Set the Enr Discovery ports to the listening ports if not present.
|
||||
if let Some(listening_addr_v4) = network_config.listen_addrs().v4() {
|
||||
@@ -85,7 +83,7 @@ impl<E: EthSpec> BootNodeConfig<E> {
|
||||
network_config.discv5_config.enr_update = false;
|
||||
}
|
||||
|
||||
let private_key = load_private_key(&network_config, &logger);
|
||||
let private_key = load_private_key(&network_config);
|
||||
let local_key = CombinedKey::from_libp2p(private_key)?;
|
||||
|
||||
let local_enr = if let Some(dir) = matches.get_one::<String>("network-dir") {
|
||||
@@ -104,7 +102,7 @@ impl<E: EthSpec> BootNodeConfig<E> {
|
||||
|
||||
if eth2_network_config.genesis_state_is_known() {
|
||||
let mut genesis_state = eth2_network_config
|
||||
.genesis_state::<E>(genesis_state_url.as_deref(), genesis_state_url_timeout, &logger).await?
|
||||
.genesis_state::<E>(genesis_state_url.as_deref(), genesis_state_url_timeout).await?
|
||||
.ok_or_else(|| {
|
||||
"The genesis state for this network is not known, this is an unsupported mode"
|
||||
.to_string()
|
||||
@@ -113,7 +111,7 @@ impl<E: EthSpec> BootNodeConfig<E> {
|
||||
let genesis_state_root = genesis_state
|
||||
.canonical_root()
|
||||
.map_err(|e| format!("Error hashing genesis state: {e:?}"))?;
|
||||
slog::info!(logger, "Genesis state found"; "root" => ?genesis_state_root);
|
||||
tracing::info!(root = ?genesis_state_root, "Genesis state found");
|
||||
let enr_fork = spec.enr_fork_id::<E>(
|
||||
types::Slot::from(0u64),
|
||||
genesis_state.genesis_validators_root(),
|
||||
@@ -121,10 +119,7 @@ impl<E: EthSpec> BootNodeConfig<E> {
|
||||
|
||||
Some(enr_fork.as_ssz_bytes())
|
||||
} else {
|
||||
slog::warn!(
|
||||
logger,
|
||||
"No genesis state provided. No Eth2 field added to the ENR"
|
||||
);
|
||||
tracing::warn!("No genesis state provided. No Eth2 field added to the ENR");
|
||||
None
|
||||
}
|
||||
};
|
||||
@@ -160,7 +155,7 @@ impl<E: EthSpec> BootNodeConfig<E> {
|
||||
.map_err(|e| format!("Failed to build ENR: {:?}", e))?
|
||||
};
|
||||
|
||||
use_or_load_enr(&local_key, &mut local_enr, &network_config, &logger)?;
|
||||
use_or_load_enr(&local_key, &mut local_enr, &network_config)?;
|
||||
local_enr
|
||||
};
|
||||
|
||||
|
||||
@@ -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(())
|
||||
|
||||
@@ -8,14 +8,13 @@ use lighthouse_network::{
|
||||
discv5::{self, enr::NodeId, Discv5},
|
||||
EnrExt, Eth2Enr,
|
||||
};
|
||||
use slog::info;
|
||||
use tracing::{info, warn};
|
||||
use types::EthSpec;
|
||||
|
||||
pub async fn run<E: EthSpec>(
|
||||
lh_matches: &ArgMatches,
|
||||
bn_matches: &ArgMatches,
|
||||
eth2_network_config: &Eth2NetworkConfig,
|
||||
log: slog::Logger,
|
||||
) -> Result<(), String> {
|
||||
// parse the CLI args into a useable config
|
||||
let config: BootNodeConfig<E> = BootNodeConfig::new(bn_matches, eth2_network_config).await?;
|
||||
@@ -52,19 +51,19 @@ pub async fn run<E: EthSpec>(
|
||||
let pretty_v4_socket = enr_v4_socket.as_ref().map(|addr| addr.to_string());
|
||||
let pretty_v6_socket = enr_v6_socket.as_ref().map(|addr| addr.to_string());
|
||||
info!(
|
||||
log, "Configuration parameters";
|
||||
"listening_address" => ?discv5_config.listen_config,
|
||||
"advertised_v4_address" => ?pretty_v4_socket,
|
||||
"advertised_v6_address" => ?pretty_v6_socket,
|
||||
"eth2" => eth2_field
|
||||
listening_address = ?discv5_config.listen_config,
|
||||
advertised_v4_address = ?pretty_v4_socket,
|
||||
advertised_v6_address = ?pretty_v6_socket,
|
||||
eth2 = eth2_field,
|
||||
"Configuration parameters"
|
||||
);
|
||||
|
||||
info!(log, "Identity established"; "peer_id" => %local_enr.peer_id(), "node_id" => %local_enr.node_id());
|
||||
info!(peer_id = %local_enr.peer_id(), node_id = %local_enr.node_id(), "Identity established");
|
||||
|
||||
// build the contactable multiaddr list, adding the p2p protocol
|
||||
info!(log, "Contact information"; "enr" => local_enr.to_base64());
|
||||
info!(log, "Enr details"; "enr" => ?local_enr);
|
||||
info!(log, "Contact information"; "multiaddrs" => ?local_enr.multiaddr_p2p());
|
||||
info!(enr = local_enr.to_base64(), "Contact information");
|
||||
info!(enr = ?local_enr, "Enr details");
|
||||
info!(multiaddrs = ?local_enr.multiaddr_p2p(), "Contact information");
|
||||
|
||||
// construct the discv5 server
|
||||
let mut discv5: Discv5 = Discv5::new(local_enr.clone(), local_key, discv5_config).unwrap();
|
||||
@@ -72,16 +71,15 @@ pub async fn run<E: EthSpec>(
|
||||
// If there are any bootnodes add them to the routing table
|
||||
for enr in boot_nodes {
|
||||
info!(
|
||||
log,
|
||||
"Adding bootnode";
|
||||
"ipv4_address" => ?enr.udp4_socket(),
|
||||
"ipv6_address" => ?enr.udp6_socket(),
|
||||
"peer_id" => ?enr.peer_id(),
|
||||
"node_id" => ?enr.node_id()
|
||||
ipv4_address = ?enr.udp4_socket(),
|
||||
ipv6_address = ?enr.udp6_socket(),
|
||||
peer_id = ?enr.peer_id(),
|
||||
node_id = ?enr.node_id(),
|
||||
"Adding bootnode"
|
||||
);
|
||||
if enr != local_enr {
|
||||
if let Err(e) = discv5.add_enr(enr) {
|
||||
slog::warn!(log, "Failed adding ENR"; "error" => ?e);
|
||||
warn!(error = ?e, "Failed adding ENR");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -93,7 +91,7 @@ pub async fn run<E: EthSpec>(
|
||||
|
||||
// if there are peers in the local routing table, establish a session by running a query
|
||||
if !discv5.table_entries_id().is_empty() {
|
||||
info!(log, "Executing bootstrap query...");
|
||||
info!("Executing bootstrap query...");
|
||||
let _ = discv5.find_node(NodeId::random()).await;
|
||||
}
|
||||
|
||||
@@ -131,14 +129,14 @@ pub async fn run<E: EthSpec>(
|
||||
// display server metrics
|
||||
let metrics = discv5.metrics();
|
||||
info!(
|
||||
log, "Server metrics";
|
||||
"connected_peers" => discv5.connected_peers(),
|
||||
"active_sessions" => metrics.active_sessions,
|
||||
"requests/s" => format_args!("{:.2}", metrics.unsolicited_requests_per_second),
|
||||
"ipv4_nodes" => ipv4_only_reachable,
|
||||
"ipv6_only_nodes" => ipv6_only_reachable,
|
||||
"dual_stack_nodes" => ipv4_ipv6_reachable,
|
||||
"unreachable_nodes" => unreachable_nodes,
|
||||
connected_peers = discv5.connected_peers(),
|
||||
active_sessions = metrics.active_sessions,
|
||||
"requests/s" = format_args!("{:.2}", metrics.unsolicited_requests_per_second),
|
||||
ipv4_nodes = ipv4_only_reachable,
|
||||
ipv6_only_nodes = ipv6_only_reachable,
|
||||
dual_stack_nodes = ipv4_ipv6_reachable,
|
||||
unreachable_nodes,
|
||||
"Server metrics",
|
||||
);
|
||||
|
||||
}
|
||||
@@ -149,7 +147,7 @@ pub async fn run<E: EthSpec>(
|
||||
// Ignore these events here
|
||||
}
|
||||
discv5::Event::SocketUpdated(socket_addr) => {
|
||||
info!(log, "Advertised socket address updated"; "socket_addr" => %socket_addr);
|
||||
info!(%socket_addr, "Advertised socket address updated");
|
||||
}
|
||||
_ => {} // Ignore
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user