feat(http): add request and response tracing behind feature flag (#2079)

pull/2090/head
Amr Bashir 7 months ago committed by GitHub
parent fecfd5533a
commit a3b553ddb4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,5 @@
---
"http": "patch"
---
Add tracing logs for requestes and responses behind `tracing` feature flag.

8
Cargo.lock generated

@ -6456,7 +6456,6 @@ name = "tauri-plugin-autostart"
version = "2.0.1" version = "2.0.1"
dependencies = [ dependencies = [
"auto-launch", "auto-launch",
"log",
"serde", "serde",
"serde_json", "serde_json",
"tauri", "tauri",
@ -6520,7 +6519,6 @@ name = "tauri-plugin-deep-link"
version = "2.0.1" version = "2.0.1"
dependencies = [ dependencies = [
"dunce", "dunce",
"log",
"rust-ini", "rust-ini",
"serde", "serde",
"serde_json", "serde_json",
@ -6528,6 +6526,7 @@ dependencies = [
"tauri-plugin", "tauri-plugin",
"tauri-utils", "tauri-utils",
"thiserror 2.0.3", "thiserror 2.0.3",
"tracing",
"url", "url",
"windows-registry 0.3.0", "windows-registry 0.3.0",
"windows-result 0.2.0", "windows-result 0.2.0",
@ -6627,6 +6626,7 @@ dependencies = [
"tauri-plugin-fs", "tauri-plugin-fs",
"thiserror 2.0.3", "thiserror 2.0.3",
"tokio", "tokio",
"tracing",
"url", "url",
"urlpattern", "urlpattern",
] ]
@ -6793,13 +6793,13 @@ dependencies = [
name = "tauri-plugin-single-instance" name = "tauri-plugin-single-instance"
version = "2.0.1" version = "2.0.1"
dependencies = [ dependencies = [
"log",
"semver", "semver",
"serde", "serde",
"serde_json", "serde_json",
"tauri", "tauri",
"tauri-plugin-deep-link", "tauri-plugin-deep-link",
"thiserror 2.0.3", "thiserror 2.0.3",
"tracing",
"windows-sys 0.59.0", "windows-sys 0.59.0",
"zbus 4.4.0", "zbus 4.4.0",
] ]
@ -6826,13 +6826,13 @@ name = "tauri-plugin-store"
version = "2.1.0" version = "2.1.0"
dependencies = [ dependencies = [
"dunce", "dunce",
"log",
"serde", "serde",
"serde_json", "serde_json",
"tauri", "tauri",
"tauri-plugin", "tauri-plugin",
"thiserror 2.0.3", "thiserror 2.0.3",
"tokio", "tokio",
"tracing",
] ]
[[package]] [[package]]

@ -10,6 +10,7 @@ resolver = "2"
[workspace.dependencies] [workspace.dependencies]
serde = { version = "1", features = ["derive"] } serde = { version = "1", features = ["derive"] }
tracing = "0.1"
log = "0.4" log = "0.4"
tauri = { version = "2", default-features = false } tauri = { version = "2", default-features = false }
tauri-build = "2" tauri-build = "2"

@ -27,6 +27,5 @@ tauri-plugin = { workspace = true, features = ["build"] }
serde = { workspace = true } serde = { workspace = true }
serde_json = { workspace = true } serde_json = { workspace = true }
tauri = { workspace = true } tauri = { workspace = true }
log = { workspace = true }
thiserror = { workspace = true } thiserror = { workspace = true }
auto-launch = "0.5" auto-launch = "0.5"

@ -11,8 +11,6 @@
#![cfg(not(any(target_os = "android", target_os = "ios")))] #![cfg(not(any(target_os = "android", target_os = "ios")))]
use auto_launch::{AutoLaunch, AutoLaunchBuilder}; use auto_launch::{AutoLaunch, AutoLaunchBuilder};
#[cfg(target_os = "macos")]
use log::info;
use serde::{ser::Serializer, Serialize}; use serde::{ser::Serializer, Serialize};
use tauri::{ use tauri::{
command, command,
@ -133,7 +131,6 @@ pub fn init<R: Runtime>(
} else { } else {
exe_path exe_path
}; };
info!("auto_start path {}", &app_path);
builder.set_app_path(&app_path); builder.set_app_path(&app_path);
} }
#[cfg(target_os = "linux")] #[cfg(target_os = "linux")]

@ -32,7 +32,7 @@ serde = { workspace = true }
serde_json = { workspace = true } serde_json = { workspace = true }
tauri = { workspace = true } tauri = { workspace = true }
tauri-utils = { workspace = true } tauri-utils = { workspace = true }
log = { workspace = true } tracing = { workspace = true }
thiserror = { workspace = true } thiserror = { workspace = true }
url = { workspace = true } url = { workspace = true }

@ -215,7 +215,7 @@ mod imp {
current.replace(vec![url.clone()]); current.replace(vec![url.clone()]);
let _ = self.app.emit("deep-link://new-url", vec![url]); let _ = self.app.emit("deep-link://new-url", vec![url]);
} else if cfg!(debug_assertions) { } else if cfg!(debug_assertions) {
log::warn!("argument {url} does not match any configured deep link scheme; skipping it"); tracing::warn!("argument {url} does not match any configured deep link scheme; skipping it");
} }
} }
} }

@ -41,6 +41,7 @@ http = "1"
reqwest = { version = "0.12", default-features = false } reqwest = { version = "0.12", default-features = false }
url = { workspace = true } url = { workspace = true }
data-url = "0.3" data-url = "0.3"
tracing = { workspace = true, optional = true }
[features] [features]
default = [ default = [
@ -71,3 +72,4 @@ http2 = ["reqwest/http2"]
charset = ["reqwest/charset"] charset = ["reqwest/charset"]
macos-system-configuration = ["reqwest/macos-system-configuration"] macos-system-configuration = ["reqwest/macos-system-configuration"]
unsafe-headers = [] unsafe-headers = []
tracing = ["dep:tracing"]

@ -283,6 +283,9 @@ pub async fn fetch<R: Runtime>(
request = request.headers(headers); request = request.headers(headers);
#[cfg(feature = "tracing")]
tracing::trace!("{:?}", request);
let fut = async move { request.send().await.map_err(Into::into) }; let fut = async move { request.send().await.map_err(Into::into) };
let mut resources_table = webview.resources_table(); let mut resources_table = webview.resources_table();
let rid = resources_table.add_request(Box::pin(fut)); let rid = resources_table.add_request(Box::pin(fut));
@ -304,6 +307,9 @@ pub async fn fetch<R: Runtime>(
.header(header::CONTENT_TYPE, data_url.mime_type().to_string()) .header(header::CONTENT_TYPE, data_url.mime_type().to_string())
.body(reqwest::Body::from(body))?; .body(reqwest::Body::from(body))?;
#[cfg(feature = "tracing")]
tracing::trace!("{:?}", response);
let fut = async move { Ok(reqwest::Response::from(response)) }; let fut = async move { Ok(reqwest::Response::from(response)) };
let mut resources_table = webview.resources_table(); let mut resources_table = webview.resources_table();
let rid = resources_table.add_request(Box::pin(fut)); let rid = resources_table.add_request(Box::pin(fut));
@ -351,6 +357,9 @@ pub async fn fetch_send<R: Runtime>(
} }
}; };
#[cfg(feature = "tracing")]
tracing::trace!("{:?}", res);
let status = res.status(); let status = res.status();
let url = res.url().to_string(); let url = res.url().to_string();
let mut headers = Vec::new(); let mut headers = Vec::new();

@ -24,7 +24,7 @@ ios = { level = "none", notes = "" }
serde = { workspace = true } serde = { workspace = true }
serde_json = { workspace = true } serde_json = { workspace = true }
tauri = { workspace = true } tauri = { workspace = true }
log = { workspace = true } tracing = { workspace = true }
thiserror = { workspace = true } thiserror = { workspace = true }
tauri-plugin-deep-link = { path = "../deep-link", version = "2.0.1", optional = true } tauri-plugin-deep-link = { path = "../deep-link", version = "2.0.1", optional = true }
semver = { version = "1", optional = true } semver = { version = "1", optional = true }

@ -34,7 +34,7 @@ pub fn init<R: Runtime>(cb: Box<SingleInstanceCallback<R>>) -> TauriPlugin<R> {
listen_for_other_instances(&socket, app.clone(), cb); listen_for_other_instances(&socket, app.clone(), cb);
} }
_ => { _ => {
log::debug!( tracing::debug!(
"single_instance failed to notify - launching normally: {}", "single_instance failed to notify - launching normally: {}",
e e
); );
@ -108,11 +108,13 @@ fn listen_for_other_instances<A: Runtime>(
s.split('\0').map(String::from).collect(); s.split('\0').map(String::from).collect();
cb(app.app_handle(), args, cwd.clone()); cb(app.app_handle(), args, cwd.clone());
} }
Err(e) => log::debug!("single_instance failed to be notified: {e}"), Err(e) => {
tracing::debug!("single_instance failed to be notified: {e}")
}
} }
} }
Err(err) => { Err(err) => {
log::debug!("single_instance failed to be notified: {}", err); tracing::debug!("single_instance failed to be notified: {}", err);
continue; continue;
} }
} }
@ -120,7 +122,7 @@ fn listen_for_other_instances<A: Runtime>(
}); });
} }
Err(err) => { Err(err) => {
log::error!( tracing::error!(
"single_instance failed to listen to other processes - launching normally: {}", "single_instance failed to listen to other processes - launching normally: {}",
err err
); );

@ -27,7 +27,7 @@ tauri-plugin = { workspace = true, features = ["build"] }
serde = { workspace = true } serde = { workspace = true }
serde_json = { workspace = true } serde_json = { workspace = true }
tauri = { workspace = true } tauri = { workspace = true }
log = { workspace = true } tracing = { workspace = true }
thiserror = { workspace = true } thiserror = { workspace = true }
dunce = { workspace = true } dunce = { workspace = true }
tokio = { version = "1", features = ["sync", "time", "macros"] } tokio = { version = "1", features = ["sync", "time", "macros"] }

@ -432,7 +432,7 @@ impl Builder {
for (path, rid) in stores.iter() { for (path, rid) in stores.iter() {
if let Ok(store) = app_handle.resources_table().get::<Store<R>>(*rid) { if let Ok(store) = app_handle.resources_table().get::<Store<R>>(*rid) {
if let Err(err) = store.save() { if let Err(err) = store.save() {
log::error!("failed to save store {path:?} with error {err:?}"); tracing::error!("failed to save store {path:?} with error {err:?}");
} }
} }
} }

Loading…
Cancel
Save