mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-10 04:01:51 +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:
@@ -21,13 +21,13 @@ use lighthouse_network::{
|
||||
service::api_types::{AppRequestId, SyncRequestId},
|
||||
MessageId, NetworkGlobals, PeerId, PeerRequestId, PubsubMessage, Response,
|
||||
};
|
||||
use logging::crit;
|
||||
use logging::TimeLatch;
|
||||
use slog::{crit, debug, o, trace};
|
||||
use slog::{error, warn};
|
||||
use std::sync::Arc;
|
||||
use std::time::{Duration, SystemTime, UNIX_EPOCH};
|
||||
use tokio::sync::mpsc;
|
||||
use tokio_stream::wrappers::UnboundedReceiverStream;
|
||||
use tracing::{debug, error, info_span, trace, warn, Instrument};
|
||||
use types::{BlobSidecar, DataColumnSidecar, EthSpec, ForkContext, SignedBeaconBlock};
|
||||
|
||||
/// Handles messages from the network and routes them to the appropriate service to be handled.
|
||||
@@ -42,8 +42,6 @@ pub struct Router<T: BeaconChainTypes> {
|
||||
network: HandlerNetworkContext<T::EthSpec>,
|
||||
/// A multi-threaded, non-blocking processor for applying messages to the beacon chain.
|
||||
network_beacon_processor: Arc<NetworkBeaconProcessor<T>>,
|
||||
/// The `Router` logger.
|
||||
log: slog::Logger,
|
||||
/// Provides de-bounce functionality for logging.
|
||||
logger_debounce: TimeLatch,
|
||||
}
|
||||
@@ -91,14 +89,11 @@ impl<T: BeaconChainTypes> Router<T> {
|
||||
beacon_processor_send: BeaconProcessorSend<T::EthSpec>,
|
||||
beacon_processor_reprocess_tx: mpsc::Sender<ReprocessQueueMessage>,
|
||||
fork_context: Arc<ForkContext>,
|
||||
log: slog::Logger,
|
||||
) -> Result<mpsc::UnboundedSender<RouterMessage<T::EthSpec>>, String> {
|
||||
let message_handler_log = log.new(o!("service"=> "router"));
|
||||
trace!(message_handler_log, "Service starting");
|
||||
trace!("Service starting");
|
||||
|
||||
let (handler_send, handler_recv) = mpsc::unbounded_channel();
|
||||
|
||||
let sync_logger = log.new(o!("service"=> "sync"));
|
||||
// generate the message channel
|
||||
let (sync_send, sync_recv) = mpsc::unbounded_channel::<SyncMessage<T::EthSpec>>();
|
||||
|
||||
@@ -112,7 +107,6 @@ impl<T: BeaconChainTypes> Router<T> {
|
||||
network_globals: network_globals.clone(),
|
||||
invalid_block_storage,
|
||||
executor: executor.clone(),
|
||||
log: log.clone(),
|
||||
};
|
||||
let network_beacon_processor = Arc::new(network_beacon_processor);
|
||||
|
||||
@@ -124,7 +118,6 @@ impl<T: BeaconChainTypes> Router<T> {
|
||||
network_beacon_processor.clone(),
|
||||
sync_recv,
|
||||
fork_context,
|
||||
sync_logger,
|
||||
);
|
||||
|
||||
// generate the Message handler
|
||||
@@ -132,18 +125,18 @@ impl<T: BeaconChainTypes> Router<T> {
|
||||
network_globals,
|
||||
chain: beacon_chain,
|
||||
sync_send,
|
||||
network: HandlerNetworkContext::new(network_send, log.clone()),
|
||||
network: HandlerNetworkContext::new(network_send),
|
||||
network_beacon_processor,
|
||||
log: message_handler_log,
|
||||
logger_debounce: TimeLatch::default(),
|
||||
};
|
||||
|
||||
// spawn handler task and move the message handler instance into the spawned thread
|
||||
executor.spawn(
|
||||
async move {
|
||||
debug!(log, "Network message router started");
|
||||
debug!("Network message router started");
|
||||
UnboundedReceiverStream::new(handler_recv)
|
||||
.for_each(move |msg| future::ready(handler.handle_message(msg)))
|
||||
.instrument(info_span!("", service = "router"))
|
||||
.await;
|
||||
},
|
||||
"router",
|
||||
@@ -201,7 +194,7 @@ impl<T: BeaconChainTypes> Router<T> {
|
||||
rpc_request: rpc::Request<E>,
|
||||
) {
|
||||
if !self.network_globals.peers.read().is_connected(&peer_id) {
|
||||
debug!(self.log, "Dropping request of disconnected peer"; "peer_id" => %peer_id, "request" => ?rpc_request);
|
||||
debug!( %peer_id, request = ?rpc_request, "Dropping request of disconnected peer");
|
||||
return;
|
||||
}
|
||||
match rpc_request.r#type {
|
||||
@@ -336,7 +329,7 @@ impl<T: BeaconChainTypes> Router<T> {
|
||||
) {
|
||||
match response {
|
||||
Response::Status(status_message) => {
|
||||
debug!(self.log, "Received Status Response"; "peer_id" => %peer_id, &status_message);
|
||||
debug!(%peer_id, ?status_message,"Received Status Response");
|
||||
self.handle_beacon_processor_send_result(
|
||||
self.network_beacon_processor
|
||||
.send_status_message(peer_id, status_message),
|
||||
@@ -448,7 +441,7 @@ impl<T: BeaconChainTypes> Router<T> {
|
||||
)
|
||||
}
|
||||
PubsubMessage::VoluntaryExit(exit) => {
|
||||
debug!(self.log, "Received a voluntary exit"; "peer_id" => %peer_id);
|
||||
debug!(%peer_id, "Received a voluntary exit");
|
||||
self.handle_beacon_processor_send_result(
|
||||
self.network_beacon_processor
|
||||
.send_gossip_voluntary_exit(message_id, peer_id, exit),
|
||||
@@ -456,9 +449,8 @@ impl<T: BeaconChainTypes> Router<T> {
|
||||
}
|
||||
PubsubMessage::ProposerSlashing(proposer_slashing) => {
|
||||
debug!(
|
||||
self.log,
|
||||
"Received a proposer slashing";
|
||||
"peer_id" => %peer_id
|
||||
%peer_id,
|
||||
"Received a proposer slashing"
|
||||
);
|
||||
self.handle_beacon_processor_send_result(
|
||||
self.network_beacon_processor.send_gossip_proposer_slashing(
|
||||
@@ -470,9 +462,8 @@ impl<T: BeaconChainTypes> Router<T> {
|
||||
}
|
||||
PubsubMessage::AttesterSlashing(attester_slashing) => {
|
||||
debug!(
|
||||
self.log,
|
||||
"Received a attester slashing";
|
||||
"peer_id" => %peer_id
|
||||
%peer_id,
|
||||
"Received a attester slashing"
|
||||
);
|
||||
self.handle_beacon_processor_send_result(
|
||||
self.network_beacon_processor.send_gossip_attester_slashing(
|
||||
@@ -484,9 +475,8 @@ impl<T: BeaconChainTypes> Router<T> {
|
||||
}
|
||||
PubsubMessage::SignedContributionAndProof(contribution_and_proof) => {
|
||||
trace!(
|
||||
self.log,
|
||||
"Received sync committee aggregate";
|
||||
"peer_id" => %peer_id
|
||||
%peer_id,
|
||||
"Received sync committee aggregate"
|
||||
);
|
||||
self.handle_beacon_processor_send_result(
|
||||
self.network_beacon_processor.send_gossip_sync_contribution(
|
||||
@@ -499,9 +489,8 @@ impl<T: BeaconChainTypes> Router<T> {
|
||||
}
|
||||
PubsubMessage::SyncCommitteeMessage(sync_committtee_msg) => {
|
||||
trace!(
|
||||
self.log,
|
||||
"Received sync committee signature";
|
||||
"peer_id" => %peer_id
|
||||
%peer_id,
|
||||
"Received sync committee signature"
|
||||
);
|
||||
self.handle_beacon_processor_send_result(
|
||||
self.network_beacon_processor.send_gossip_sync_signature(
|
||||
@@ -515,9 +504,8 @@ impl<T: BeaconChainTypes> Router<T> {
|
||||
}
|
||||
PubsubMessage::LightClientFinalityUpdate(light_client_finality_update) => {
|
||||
trace!(
|
||||
self.log,
|
||||
"Received light client finality update";
|
||||
"peer_id" => %peer_id
|
||||
%peer_id,
|
||||
"Received light client finality update"
|
||||
);
|
||||
self.handle_beacon_processor_send_result(
|
||||
self.network_beacon_processor
|
||||
@@ -531,9 +519,9 @@ impl<T: BeaconChainTypes> Router<T> {
|
||||
}
|
||||
PubsubMessage::LightClientOptimisticUpdate(light_client_optimistic_update) => {
|
||||
trace!(
|
||||
self.log,
|
||||
"Received light client optimistic update";
|
||||
"peer_id" => %peer_id
|
||||
%peer_id,
|
||||
"Received light client optimistic update"
|
||||
|
||||
);
|
||||
self.handle_beacon_processor_send_result(
|
||||
self.network_beacon_processor
|
||||
@@ -559,7 +547,7 @@ impl<T: BeaconChainTypes> Router<T> {
|
||||
|
||||
fn send_status(&mut self, peer_id: PeerId) {
|
||||
let status_message = status_message(&self.chain);
|
||||
debug!(self.log, "Sending Status Request"; "peer" => %peer_id, &status_message);
|
||||
debug!(%peer_id, ?status_message, "Sending Status Request");
|
||||
self.network
|
||||
.send_processor_request(peer_id, RequestType::Status(status_message));
|
||||
}
|
||||
@@ -567,9 +555,8 @@ impl<T: BeaconChainTypes> Router<T> {
|
||||
fn send_to_sync(&mut self, message: SyncMessage<T::EthSpec>) {
|
||||
self.sync_send.send(message).unwrap_or_else(|e| {
|
||||
warn!(
|
||||
self.log,
|
||||
"Could not send message to the sync service";
|
||||
"error" => %e,
|
||||
error = %e,
|
||||
"Could not send message to the sync service"
|
||||
)
|
||||
});
|
||||
}
|
||||
@@ -598,7 +585,7 @@ impl<T: BeaconChainTypes> Router<T> {
|
||||
request_id: RequestId,
|
||||
status: StatusMessage,
|
||||
) {
|
||||
debug!(self.log, "Received Status Request"; "peer_id" => %peer_id, &status);
|
||||
debug!(%peer_id, ?status, "Received Status Request");
|
||||
|
||||
// Say status back.
|
||||
self.network.send_response(
|
||||
@@ -626,20 +613,20 @@ impl<T: BeaconChainTypes> Router<T> {
|
||||
AppRequestId::Sync(sync_id) => match sync_id {
|
||||
id @ SyncRequestId::BlocksByRange { .. } => id,
|
||||
other => {
|
||||
crit!(self.log, "BlocksByRange response on incorrect request"; "request" => ?other);
|
||||
crit!(request = ?other, "BlocksByRange response on incorrect request");
|
||||
return;
|
||||
}
|
||||
},
|
||||
AppRequestId::Router => {
|
||||
crit!(self.log, "All BBRange requests belong to sync"; "peer_id" => %peer_id);
|
||||
crit!(%peer_id, "All BBRange requests belong to sync");
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
trace!(
|
||||
self.log,
|
||||
"Received BlocksByRange Response";
|
||||
"peer" => %peer_id,
|
||||
%peer_id,
|
||||
"Received BlocksByRange Response"
|
||||
|
||||
);
|
||||
|
||||
self.send_to_sync(SyncMessage::RpcBlock {
|
||||
@@ -657,9 +644,8 @@ impl<T: BeaconChainTypes> Router<T> {
|
||||
blob_sidecar: Option<Arc<BlobSidecar<T::EthSpec>>>,
|
||||
) {
|
||||
trace!(
|
||||
self.log,
|
||||
"Received BlobsByRange Response";
|
||||
"peer" => %peer_id,
|
||||
%peer_id,
|
||||
"Received BlobsByRange Response"
|
||||
);
|
||||
|
||||
if let AppRequestId::Sync(id) = request_id {
|
||||
@@ -670,10 +656,7 @@ impl<T: BeaconChainTypes> Router<T> {
|
||||
seen_timestamp: timestamp_now(),
|
||||
});
|
||||
} else {
|
||||
crit!(
|
||||
self.log,
|
||||
"All blobs by range responses should belong to sync"
|
||||
);
|
||||
crit!("All blobs by range responses should belong to sync");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -688,20 +671,19 @@ impl<T: BeaconChainTypes> Router<T> {
|
||||
AppRequestId::Sync(sync_id) => match sync_id {
|
||||
id @ SyncRequestId::SingleBlock { .. } => id,
|
||||
other => {
|
||||
crit!(self.log, "BlocksByRoot response on incorrect request"; "request" => ?other);
|
||||
crit!(request = ?other, "BlocksByRoot response on incorrect request");
|
||||
return;
|
||||
}
|
||||
},
|
||||
AppRequestId::Router => {
|
||||
crit!(self.log, "All BBRoot requests belong to sync"; "peer_id" => %peer_id);
|
||||
crit!(%peer_id, "All BBRoot requests belong to sync");
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
trace!(
|
||||
self.log,
|
||||
"Received BlocksByRoot Response";
|
||||
"peer" => %peer_id,
|
||||
%peer_id,
|
||||
"Received BlocksByRoot Response"
|
||||
);
|
||||
self.send_to_sync(SyncMessage::RpcBlock {
|
||||
peer_id,
|
||||
@@ -722,20 +704,19 @@ impl<T: BeaconChainTypes> Router<T> {
|
||||
AppRequestId::Sync(sync_id) => match sync_id {
|
||||
id @ SyncRequestId::SingleBlob { .. } => id,
|
||||
other => {
|
||||
crit!(self.log, "BlobsByRoot response on incorrect request"; "request" => ?other);
|
||||
crit!(request = ?other, "BlobsByRoot response on incorrect request");
|
||||
return;
|
||||
}
|
||||
},
|
||||
AppRequestId::Router => {
|
||||
crit!(self.log, "All BlobsByRoot requests belong to sync"; "peer_id" => %peer_id);
|
||||
crit!(%peer_id, "All BlobsByRoot requests belong to sync");
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
trace!(
|
||||
self.log,
|
||||
"Received BlobsByRoot Response";
|
||||
"peer" => %peer_id,
|
||||
%peer_id,
|
||||
"Received BlobsByRoot Response"
|
||||
);
|
||||
self.send_to_sync(SyncMessage::RpcBlob {
|
||||
request_id,
|
||||
@@ -756,20 +737,19 @@ impl<T: BeaconChainTypes> Router<T> {
|
||||
AppRequestId::Sync(sync_id) => match sync_id {
|
||||
id @ SyncRequestId::DataColumnsByRoot { .. } => id,
|
||||
other => {
|
||||
crit!(self.log, "DataColumnsByRoot response on incorrect request"; "request" => ?other);
|
||||
crit!(request = ?other, "DataColumnsByRoot response on incorrect request");
|
||||
return;
|
||||
}
|
||||
},
|
||||
AppRequestId::Router => {
|
||||
crit!(self.log, "All DataColumnsByRoot requests belong to sync"; "peer_id" => %peer_id);
|
||||
crit!(%peer_id, "All DataColumnsByRoot requests belong to sync");
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
trace!(
|
||||
self.log,
|
||||
"Received DataColumnsByRoot Response";
|
||||
"peer" => %peer_id,
|
||||
%peer_id,
|
||||
"Received DataColumnsByRoot Response"
|
||||
);
|
||||
self.send_to_sync(SyncMessage::RpcDataColumn {
|
||||
request_id,
|
||||
@@ -786,9 +766,8 @@ impl<T: BeaconChainTypes> Router<T> {
|
||||
data_column: Option<Arc<DataColumnSidecar<T::EthSpec>>>,
|
||||
) {
|
||||
trace!(
|
||||
self.log,
|
||||
"Received DataColumnsByRange Response";
|
||||
"peer" => %peer_id,
|
||||
%peer_id,
|
||||
"Received DataColumnsByRange Response"
|
||||
);
|
||||
|
||||
if let AppRequestId::Sync(id) = request_id {
|
||||
@@ -799,10 +778,7 @@ impl<T: BeaconChainTypes> Router<T> {
|
||||
seen_timestamp: timestamp_now(),
|
||||
});
|
||||
} else {
|
||||
crit!(
|
||||
self.log,
|
||||
"All data columns by range responses should belong to sync"
|
||||
);
|
||||
crit!("All data columns by range responses should belong to sync");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -818,8 +794,7 @@ impl<T: BeaconChainTypes> Router<T> {
|
||||
};
|
||||
|
||||
if self.logger_debounce.elapsed() {
|
||||
error!(&self.log, "Unable to send message to the beacon processor";
|
||||
"error" => %e, "type" => work_type)
|
||||
error!(error = %e, work_type, "Unable to send message to the beacon processor")
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -831,20 +806,18 @@ impl<T: BeaconChainTypes> Router<T> {
|
||||
pub struct HandlerNetworkContext<E: EthSpec> {
|
||||
/// The network channel to relay messages to the Network service.
|
||||
network_send: mpsc::UnboundedSender<NetworkMessage<E>>,
|
||||
/// Logger for the `NetworkContext`.
|
||||
log: slog::Logger,
|
||||
}
|
||||
|
||||
impl<E: EthSpec> HandlerNetworkContext<E> {
|
||||
pub fn new(network_send: mpsc::UnboundedSender<NetworkMessage<E>>, log: slog::Logger) -> Self {
|
||||
Self { network_send, log }
|
||||
pub fn new(network_send: mpsc::UnboundedSender<NetworkMessage<E>>) -> Self {
|
||||
Self { network_send }
|
||||
}
|
||||
|
||||
/// Sends a message to the network task.
|
||||
fn inform_network(&mut self, msg: NetworkMessage<E>) {
|
||||
self.network_send.send(msg).unwrap_or_else(
|
||||
|e| warn!(self.log, "Could not send message to the network service"; "error" => %e),
|
||||
)
|
||||
self.network_send
|
||||
.send(msg)
|
||||
.unwrap_or_else(|e| warn!(error = %e,"Could not send message to the network service"))
|
||||
}
|
||||
|
||||
/// Sends a request to the network task.
|
||||
|
||||
Reference in New Issue
Block a user