Skip to content

Commit

Permalink
feat(http): add request and response tracing behind feature flag
Browse files Browse the repository at this point in the history
closes #2055
  • Loading branch information
amrbashir committed Nov 20, 2024
1 parent 59dd5f1 commit 5adcc3c
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changes/http-tracing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"http": "patch"
---

Add tracing logs for requestes and responses behind `tracing` feature flag.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions plugins/http/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ http = "1"
reqwest = { version = "0.12", default-features = false }
url = { workspace = true }
data-url = "0.3"
log = { workspace = true, optional = true }

[features]
default = [
Expand Down Expand Up @@ -71,3 +72,4 @@ http2 = ["reqwest/http2"]
charset = ["reqwest/charset"]
macos-system-configuration = ["reqwest/macos-system-configuration"]
unsafe-headers = []
tracing = ["dep:log"]
9 changes: 9 additions & 0 deletions plugins/http/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,9 @@ pub async fn fetch<R: Runtime>(

request = request.headers(headers);

#[cfg(feature = "tracing")]
log::trace!("{:?}", request);

let fut = async move { request.send().await.map_err(Into::into) };
let mut resources_table = webview.resources_table();
let rid = resources_table.add_request(Box::pin(fut));
Expand All @@ -304,6 +307,9 @@ pub async fn fetch<R: Runtime>(
.header(header::CONTENT_TYPE, data_url.mime_type().to_string())
.body(reqwest::Body::from(body))?;

#[cfg(feature = "tracing")]
log::trace!("{:?}", response);

let fut = async move { Ok(reqwest::Response::from(response)) };
let mut resources_table = webview.resources_table();
let rid = resources_table.add_request(Box::pin(fut));
Expand Down Expand Up @@ -351,6 +357,9 @@ pub async fn fetch_send<R: Runtime>(
}
};

#[cfg(feature = "tracing")]
log::trace!("{:?}", res);

let status = res.status();
let url = res.url().to_string();
let mut headers = Vec::new();
Expand Down

0 comments on commit 5adcc3c

Please sign in to comment.