Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
8 changes: 4 additions & 4 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 0 additions & 1 deletion plugins/autostart/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 changes: 0 additions & 3 deletions plugins/autostart/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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")]
Expand Down
2 changes: 1 addition & 1 deletion plugins/deep-link/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }

Expand Down
2 changes: 1 addition & 1 deletion plugins/deep-link/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}
}
Expand Down
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"
tracing = { 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:tracing"]
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")]
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));
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")]
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));
Expand Down Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion plugins/single-instance/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
10 changes: 6 additions & 4 deletions plugins/single-instance/src/platform_impl/macos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
Expand Down Expand Up @@ -108,19 +108,21 @@ 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;
}
}
}
});
}
Err(err) => {
log::error!(
tracing::error!(
"single_instance failed to listen to other processes - launching normally: {}",
err
);
Expand Down
2 changes: 1 addition & 1 deletion plugins/store/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
Expand Down
2 changes: 1 addition & 1 deletion plugins/store/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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:?}");
}
}
}
Expand Down
Loading