Skip to content

Commit

Permalink
Record timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
kushudai committed Nov 22, 2024
1 parent 6754a39 commit 05f08b1
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -807,18 +807,21 @@ impl Consul {
#[cfg(feature = "trace")]
let mut span = crate::hyper_wrapper::span_for_request(&self.tracer, &req);

#[cfg(feature = "metrics")]
let method = req.method().clone();

let future = self.https_client.request(req);

#[cfg(feature = "metrics")]
let mut metrics_info_wrapper =
MetricInfoWrapper::new(method.into(), _function, None, self.metrics_tx.clone());
MetricInfoWrapper::new(req.method().clone().into(), _function, None, self.metrics_tx.clone());
let future = self.https_client.request(req);
let response = if let Some(dur) = duration {
match timeout(dur, future).await {
Ok(resp) => resp.map_err(ConsulError::ResponseError),
Err(_) => Err(ConsulError::TimeoutExceeded(dur)),
Err(_) => {
#[cfg(feature = "metrics")]
{
metrics_info_wrapper.set_status(StatusCode::REQUEST_TIMEOUT);
drop(metrics_info_wrapper.clone());
}
Err(ConsulError::TimeoutExceeded(dur))
},
}
} else {
future.await.map_err(ConsulError::ResponseError)
Expand Down

0 comments on commit 05f08b1

Please sign in to comment.