Improve logging around handling RPC requests on client

This commit is contained in:
Max Brunsfeld 2022-02-23 15:37:51 -08:00
parent 170487a528
commit e714b00c26
2 changed files with 18 additions and 4 deletions

View file

@ -530,10 +530,13 @@ impl Client {
let cx = cx.clone(); let cx = cx.clone();
let this = self.clone(); let this = self.clone();
async move { async move {
let mut message_id = 0_usize;
while let Some(message) = incoming.next().await { while let Some(message) = incoming.next().await {
let mut state = this.state.write(); let mut state = this.state.write();
let payload_type_id = message.payload_type_id(); message_id += 1;
let type_name = message.payload_type_name(); let type_name = message.payload_type_name();
let payload_type_id = message.payload_type_id();
let sender_id = message.original_sender_id().map(|id| id.0);
let model = state let model = state
.models_by_message_type .models_by_message_type
@ -575,8 +578,10 @@ impl Client {
let client_id = this.id; let client_id = this.id;
log::debug!( log::debug!(
"rpc message received. client_id:{}, name:{}", "rpc message received. client_id:{}, message_id:{}, sender_id:{:?}, type:{}",
client_id, client_id,
message_id,
sender_id,
type_name type_name
); );
cx.foreground() cx.foreground()
@ -584,15 +589,19 @@ impl Client {
match future.await { match future.await {
Ok(()) => { Ok(()) => {
log::debug!( log::debug!(
"rpc message handled. client_id:{}, name:{}", "rpc message handled. client_id:{}, message_id:{}, sender_id:{:?}, type:{}",
client_id, client_id,
message_id,
sender_id,
type_name type_name
); );
} }
Err(error) => { Err(error) => {
log::error!( log::error!(
"error handling message. client_id:{}, name:{}, {}", "error handling message. client_id:{}, message_id:{}, sender_id:{:?}, type:{}, error:{:?}",
client_id, client_id,
message_id,
sender_id,
type_name, type_name,
error error
); );

View file

@ -37,6 +37,7 @@ pub trait AnyTypedEnvelope: 'static + Send + Sync {
fn as_any(&self) -> &dyn Any; fn as_any(&self) -> &dyn Any;
fn into_any(self: Box<Self>) -> Box<dyn Any + Send + Sync>; fn into_any(self: Box<Self>) -> Box<dyn Any + Send + Sync>;
fn is_background(&self) -> bool; fn is_background(&self) -> bool;
fn original_sender_id(&self) -> Option<PeerId>;
} }
pub enum MessagePriority { pub enum MessagePriority {
@ -64,6 +65,10 @@ impl<T: EnvelopedMessage> AnyTypedEnvelope for TypedEnvelope<T> {
fn is_background(&self) -> bool { fn is_background(&self) -> bool {
matches!(T::PRIORITY, MessagePriority::Background) matches!(T::PRIORITY, MessagePriority::Background)
} }
fn original_sender_id(&self) -> Option<PeerId> {
self.original_sender_id
}
} }
macro_rules! messages { macro_rules! messages {