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

This commit is contained in:
Amr Bashir
2024-11-21 17:08:34 +02:00
committed by GitHub
parent fecfd5533a
commit a3b553ddb4
13 changed files with 32 additions and 17 deletions
-1
View File
@@ -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"
-3
View File
@@ -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")]
+1 -1
View File
@@ -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 }
+1 -1
View File
@@ -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");
}
}
}
+2
View File
@@ -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"]
+9
View File
@@ -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();
+1 -1
View File
@@ -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
);
+1 -1
View File
@@ -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"] }
+1 -1
View File
@@ -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:?}");
}
}
}