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

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

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

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

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

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

@ -215,7 +215,7 @@ mod imp {
current.replace(vec![url.clone()]);
let _ = self.app.emit("deep-link://new-url", vec![url]);
} 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 }
url = { workspace = true }
data-url = "0.3"
tracing = { workspace = true, optional = true }
[features]
default = [
@ -71,3 +72,4 @@ http2 = ["reqwest/http2"]
charset = ["reqwest/charset"]
macos-system-configuration = ["reqwest/macos-system-configuration"]
unsafe-headers = []
tracing = ["dep:tracing"]

@ -283,6 +283,9 @@ pub async fn fetch<R: Runtime>(
request = request.headers(headers);
#[cfg(feature = "tracing")]
tracing::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));
@ -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")]
tracing::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));
@ -351,6 +357,9 @@ pub async fn fetch_send<R: Runtime>(
}
};
#[cfg(feature = "tracing")]
tracing::trace!("{:?}", res);
let status = res.status();
let url = res.url().to_string();
let mut headers = Vec::new();

@ -24,7 +24,7 @@ ios = { level = "none", notes = "" }
serde = { workspace = true }
serde_json = { workspace = true }
tauri = { workspace = true }
log = { workspace = true }
tracing = { workspace = true }
thiserror = { workspace = true }
tauri-plugin-deep-link = { path = "../deep-link", version = "2.0.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);
}
_ => {
log::debug!(
tracing::debug!(
"single_instance failed to notify - launching normally: {}",
e
);
@ -108,11 +108,13 @@ fn listen_for_other_instances<A: Runtime>(
s.split('\0').map(String::from).collect();
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) => {
log::debug!("single_instance failed to be notified: {}", err);
tracing::debug!("single_instance failed to be notified: {}", err);
continue;
}
}
@ -120,7 +122,7 @@ fn listen_for_other_instances<A: Runtime>(
});
}
Err(err) => {
log::error!(
tracing::error!(
"single_instance failed to listen to other processes - launching normally: {}",
err
);

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

@ -432,7 +432,7 @@ impl Builder {
for (path, rid) in stores.iter() {
if let Ok(store) = app_handle.resources_table().get::<Store<R>>(*rid) {
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