From 4bdd0ee1d75585d77852c6bc3423e218fef1f28d Mon Sep 17 00:00:00 2001 From: Dzejkop Date: Fri, 15 Dec 2023 16:58:09 +0100 Subject: [PATCH] Better logging & instrumentation --- Cargo.lock | 1 + crates/tx-sitter-client/Cargo.toml | 1 + crates/tx-sitter-client/src/lib.rs | 9 ++++++++- 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index 910bd0d4..608fec06 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6323,6 +6323,7 @@ dependencies = [ "serde", "serde_json", "strum", + "tracing", ] [[package]] diff --git a/crates/tx-sitter-client/Cargo.toml b/crates/tx-sitter-client/Cargo.toml index 25fd5bfe..d3e6a026 100644 --- a/crates/tx-sitter-client/Cargo.toml +++ b/crates/tx-sitter-client/Cargo.toml @@ -11,3 +11,4 @@ reqwest = "0.11.14" serde = { version = "1.0.154", features = ["derive"] } serde_json = "1.0.94" strum = { version = "0.25", features = ["derive"] } +tracing = "0.1" diff --git a/crates/tx-sitter-client/src/lib.rs b/crates/tx-sitter-client/src/lib.rs index c33045b1..f9b86aed 100644 --- a/crates/tx-sitter-client/src/lib.rs +++ b/crates/tx-sitter-client/src/lib.rs @@ -1,5 +1,6 @@ use data::{GetTxResponse, SendTxRequest, SendTxResponse, TxStatus}; use reqwest::Response; +use tracing::instrument; pub mod data; @@ -41,22 +42,28 @@ impl TxSitterClient { async fn validate_response(response: Response) -> anyhow::Result { if !response.status().is_success() { + let status = response.status(); let body = response.text().await?; - return Err(anyhow::anyhow!("{body}")); + return Err(anyhow::anyhow!( + "Response failed with status {status} - {body}" + )); } Ok(response) } + #[instrument(skip(self))] pub async fn send_tx(&self, req: &SendTxRequest) -> anyhow::Result { self.json_post(&format!("{}/tx", self.url), req).await } + #[instrument(skip(self))] pub async fn get_tx(&self, tx_id: &str) -> anyhow::Result { self.json_get(&format!("{}/tx/{}", self.url, tx_id)).await } + #[instrument(skip(self))] pub async fn get_txs(&self, tx_status: Option) -> anyhow::Result> { let mut url = format!("{}/txs", self.url);