summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosh McKinney <joshka@users.noreply.github.com>2023-04-12 18:38:05 -0700
committerD. Scott Boggs <scott@tams.tech>2023-09-01 07:51:59 -0400
commiteb6466490502033231bd7c1796781c5fea769589 (patch)
tree9a20c2c3402fcd5551bddeacec6b0a8f4609f7ba
parentb64a62116ecba3d53ebb81fa5d675cac271185ec (diff)
refactor: use tracing in read_response
-rw-r--r--src/helpers/read_response.rs21
1 files changed, 11 insertions, 10 deletions
diff --git a/src/helpers/read_response.rs b/src/helpers/read_response.rs
index 66ce2b0..ebf87bc 100644
--- a/src/helpers/read_response.rs
+++ b/src/helpers/read_response.rs
@@ -1,12 +1,12 @@
use std::time::Duration;
-use crate::{errors::Result, log_serde, Error};
+use crate::{errors::Result, Error};
use futures::pin_mut;
use futures_util::StreamExt;
-use log::{as_debug, as_serde, debug, trace, warn};
use reqwest::Response;
use serde::{Deserialize, Serialize};
use tokio::time::timeout;
+use tracing::{debug, trace, warn};
/// Adapter for reading JSON data from a response with better logging and a
/// fail-safe timeout.
@@ -21,7 +21,7 @@ where
let mut bytes = vec![];
let url = response.url().clone();
let status = response.status();
- trace!(status = log_serde!(response Status), headers = log_serde!(response Headers); "attempting to stream response");
+ trace!(%status, headers = ?response.headers(), "attempting to stream response");
let stream = response.bytes_stream();
pin_mut!(stream);
loop {
@@ -33,14 +33,15 @@ where
// as of here, we did not hit an error while reading the body
bytes.extend_from_slice(&data);
debug!(
- data = String::from_utf8_lossy(&data), url = url.as_str(),
- bytes_received_so_far = bytes.len();
+ data = ?String::from_utf8_lossy(&data),
+ url = url.as_str(),
+ bytes_received_so_far = bytes.len(),
"data chunk received"
);
} else {
warn!(
url = url.as_str(),
- data_received = bytes.len();
+ data_received = bytes.len(),
"API response timed out"
);
break;
@@ -50,22 +51,22 @@ where
let bytes = bytes.as_slice();
trace!(
url = url.as_str(),
- data = String::from_utf8_lossy(bytes);
+ data = ?String::from_utf8_lossy(bytes),
"parsing response"
);
if status.is_success() {
// the the response should deserialize to T
let result = serde_json::from_slice(bytes)?;
debug!(
- url = url.as_str(),
- result = as_serde!(result);
+ url = url.as_str(),
+ //result = result.serialize(),
"result parsed successfully"
);
Ok(result)
} else {
// we've received an error message, let's deserialize that instead.
let response = serde_json::from_slice(bytes)?;
- debug!(status = as_debug!(status), response = as_serde!(response); "error received from API");
+ debug!(?status, ?response, "error received from API");
Err(Error::Api { status, response })
}
}