Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add latency to log messages #737

Merged
merged 2 commits into from
Aug 4, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions dropshot/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -783,6 +783,7 @@ async fn http_request_handle_wrap<C: ServerContext>(
// straightforward, since the request handling code can simply return early
// with an error and we'll treat it like an error from any of the endpoints
// themselves.
let start_time = std::time::Instant::now();
let request_id = generate_request_id();
let request_log = server.log.new(o!(
"remote_addr" => remote_addr,
Expand Down Expand Up @@ -818,6 +819,7 @@ async fn http_request_handle_wrap<C: ServerContext>(
)
.await;

let latency_us = start_time.elapsed().as_micros();
let response = match maybe_response {
Err(error) => {
let message_external = error.external_message.clone();
Expand All @@ -837,7 +839,8 @@ async fn http_request_handle_wrap<C: ServerContext>(

// TODO-debug: add request and response headers here
info!(request_log, "request completed";
"response_code" => r.status().as_str().to_string(),
"response_code" => r.status().as_str(),
"latency_us" => latency_us,
"error_message_internal" => message_internal,
"error_message_external" => message_external,
);
Expand All @@ -848,7 +851,8 @@ async fn http_request_handle_wrap<C: ServerContext>(
Ok(response) => {
// TODO-debug: add request and response headers here
info!(request_log, "request completed";
"response_code" => response.status().as_str().to_string()
"response_code" => response.status().as_str(),
"latency_us" => latency_us,
);

#[cfg(feature = "usdt-probes")]
Expand Down