diff --git a/dropshot/src/dtrace.rs b/dropshot/src/dtrace.rs index a50e8548..819654ce 100644 --- a/dropshot/src/dtrace.rs +++ b/dropshot/src/dtrace.rs @@ -20,6 +20,7 @@ pub(crate) struct ResponseInfo { pub remote_addr: std::net::SocketAddr, pub status_code: u16, pub message: String, + pub latency: std::time::Duration, } #[cfg(feature = "usdt-probes")] diff --git a/dropshot/src/server.rs b/dropshot/src/server.rs index 40f49c77..5d445339 100644 --- a/dropshot/src/server.rs +++ b/dropshot/src/server.rs @@ -796,7 +796,8 @@ async fn http_request_handle_wrap( // In the case the client disconnects early, the scopeguard allows us // to perform extra housekeeping before this task is dropped. let on_disconnect = guard((), |_| { - let latency_us = start_time.elapsed().as_micros(); + let latency = start_time.elapsed(); + let latency_us = latency.as_micros(); warn!(request_log, "request handling cancelled (client disconnected)"; "latency_us" => latency_us, @@ -813,6 +814,7 @@ async fn http_request_handle_wrap( message: String::from( "client disconnected before response returned", ), + latency, } }); }); @@ -830,7 +832,8 @@ async fn http_request_handle_wrap( // cancelled and we can safely "defuse" the scopeguard. let _ = ScopeGuard::into_inner(on_disconnect); - let latency_us = start_time.elapsed().as_micros(); + let latency = start_time.elapsed(); + let latency_us = latency.as_micros(); let response = match maybe_response { Err(error) => { { @@ -848,6 +851,7 @@ async fn http_request_handle_wrap( message: message_external .cloned() .unwrap_or_else(|| message_internal.clone()), + latency, } }); @@ -877,6 +881,7 @@ async fn http_request_handle_wrap( remote_addr, status_code: response.status().as_u16(), message: "".to_string(), + latency, } });