feat(notary): Log notarization elapsed time (#746)

* Log notarisation elapsed time

* Fix formatting

* Include time units in field name
This commit is contained in:
Leonid Logvinov
2025-03-27 16:08:29 +01:00
committed by GitHub
parent 4dc5570a31
commit c8e9cb370e
2 changed files with 24 additions and 4 deletions

View File

@@ -7,6 +7,7 @@ use axum_core::body::Body;
use hyper::upgrade::{OnUpgrade, Upgraded};
use hyper_util::rt::TokioIo;
use std::future::Future;
use tokio::time::Instant;
use tracing::{debug, error, info};
use crate::{domain::notary::NotaryGlobals, service::notary_service, NotaryServerError};
@@ -84,13 +85,22 @@ pub async fn tcp_notarize(
notary_globals: NotaryGlobals,
session_id: String,
) {
let start = Instant::now();
debug!(?session_id, "Upgraded to tcp connection");
match notary_service(stream, notary_globals, &session_id).await {
Ok(_) => {
info!(?session_id, "Successful notarization using tcp!");
info!(
?session_id,
elapsed_time_millis = start.elapsed().as_millis(),
"Successful notarization using tcp!"
);
}
Err(err) => {
error!(?session_id, "Failed notarization using tcp: {err}");
error!(
?session_id,
elapsed_time_millis = start.elapsed().as_millis(),
"Failed notarization using tcp: {err}"
);
}
}
}

View File

@@ -1,3 +1,4 @@
use tokio::time::Instant;
use tracing::{debug, error, info};
use ws_stream_tungstenite::WsStream;
@@ -12,16 +13,25 @@ pub async fn websocket_notarize(
notary_globals: NotaryGlobals,
session_id: String,
) {
let start = Instant::now();
debug!(?session_id, "Upgraded to websocket connection");
// Wrap the websocket in WsStream so that we have AsyncRead and AsyncWrite
// implemented
let stream = WsStream::new(socket.into_inner());
match notary_service(stream, notary_globals, &session_id).await {
Ok(_) => {
info!(?session_id, "Successful notarization using websocket!");
info!(
?session_id,
elapsed_time_millis = start.elapsed().as_millis(),
"Successful notarization using websocket!"
);
}
Err(err) => {
error!(?session_id, "Failed notarization using websocket: {err}");
error!(
?session_id,
elapsed_time_millis = start.elapsed().as_millis(),
"Failed notarization using websocket: {err}"
);
}
}
}