Skip to content

Commit a3b553d

Browse files
authored
feat(http): add request and response tracing behind feature flag (tauri-apps#2079)
1 parent fecfd55 commit a3b553d

File tree

13 files changed

+32
-17
lines changed

13 files changed

+32
-17
lines changed

.changes/http-tracing.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"http": "patch"
3+
---
4+
5+
Add tracing logs for requestes and responses behind `tracing` feature flag.

Cargo.lock

+4-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ resolver = "2"
1010

1111
[workspace.dependencies]
1212
serde = { version = "1", features = ["derive"] }
13+
tracing = "0.1"
1314
log = "0.4"
1415
tauri = { version = "2", default-features = false }
1516
tauri-build = "2"

plugins/autostart/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,5 @@ tauri-plugin = { workspace = true, features = ["build"] }
2727
serde = { workspace = true }
2828
serde_json = { workspace = true }
2929
tauri = { workspace = true }
30-
log = { workspace = true }
3130
thiserror = { workspace = true }
3231
auto-launch = "0.5"

plugins/autostart/src/lib.rs

-3
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111
#![cfg(not(any(target_os = "android", target_os = "ios")))]
1212

1313
use auto_launch::{AutoLaunch, AutoLaunchBuilder};
14-
#[cfg(target_os = "macos")]
15-
use log::info;
1614
use serde::{ser::Serializer, Serialize};
1715
use tauri::{
1816
command,
@@ -133,7 +131,6 @@ pub fn init<R: Runtime>(
133131
} else {
134132
exe_path
135133
};
136-
info!("auto_start path {}", &app_path);
137134
builder.set_app_path(&app_path);
138135
}
139136
#[cfg(target_os = "linux")]

plugins/deep-link/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ serde = { workspace = true }
3232
serde_json = { workspace = true }
3333
tauri = { workspace = true }
3434
tauri-utils = { workspace = true }
35-
log = { workspace = true }
35+
tracing = { workspace = true }
3636
thiserror = { workspace = true }
3737
url = { workspace = true }
3838

plugins/deep-link/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ mod imp {
215215
current.replace(vec![url.clone()]);
216216
let _ = self.app.emit("deep-link://new-url", vec![url]);
217217
} else if cfg!(debug_assertions) {
218-
log::warn!("argument {url} does not match any configured deep link scheme; skipping it");
218+
tracing::warn!("argument {url} does not match any configured deep link scheme; skipping it");
219219
}
220220
}
221221
}

plugins/http/Cargo.toml

+2
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ http = "1"
4141
reqwest = { version = "0.12", default-features = false }
4242
url = { workspace = true }
4343
data-url = "0.3"
44+
tracing = { workspace = true, optional = true }
4445

4546
[features]
4647
default = [
@@ -71,3 +72,4 @@ http2 = ["reqwest/http2"]
7172
charset = ["reqwest/charset"]
7273
macos-system-configuration = ["reqwest/macos-system-configuration"]
7374
unsafe-headers = []
75+
tracing = ["dep:tracing"]

plugins/http/src/commands.rs

+9
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,9 @@ pub async fn fetch<R: Runtime>(
283283

284284
request = request.headers(headers);
285285

286+
#[cfg(feature = "tracing")]
287+
tracing::trace!("{:?}", request);
288+
286289
let fut = async move { request.send().await.map_err(Into::into) };
287290
let mut resources_table = webview.resources_table();
288291
let rid = resources_table.add_request(Box::pin(fut));
@@ -304,6 +307,9 @@ pub async fn fetch<R: Runtime>(
304307
.header(header::CONTENT_TYPE, data_url.mime_type().to_string())
305308
.body(reqwest::Body::from(body))?;
306309

310+
#[cfg(feature = "tracing")]
311+
tracing::trace!("{:?}", response);
312+
307313
let fut = async move { Ok(reqwest::Response::from(response)) };
308314
let mut resources_table = webview.resources_table();
309315
let rid = resources_table.add_request(Box::pin(fut));
@@ -351,6 +357,9 @@ pub async fn fetch_send<R: Runtime>(
351357
}
352358
};
353359

360+
#[cfg(feature = "tracing")]
361+
tracing::trace!("{:?}", res);
362+
354363
let status = res.status();
355364
let url = res.url().to_string();
356365
let mut headers = Vec::new();

plugins/single-instance/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ ios = { level = "none", notes = "" }
2424
serde = { workspace = true }
2525
serde_json = { workspace = true }
2626
tauri = { workspace = true }
27-
log = { workspace = true }
27+
tracing = { workspace = true }
2828
thiserror = { workspace = true }
2929
tauri-plugin-deep-link = { path = "../deep-link", version = "2.0.1", optional = true }
3030
semver = { version = "1", optional = true }

plugins/single-instance/src/platform_impl/macos.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ pub fn init<R: Runtime>(cb: Box<SingleInstanceCallback<R>>) -> TauriPlugin<R> {
3434
listen_for_other_instances(&socket, app.clone(), cb);
3535
}
3636
_ => {
37-
log::debug!(
37+
tracing::debug!(
3838
"single_instance failed to notify - launching normally: {}",
3939
e
4040
);
@@ -108,19 +108,21 @@ fn listen_for_other_instances<A: Runtime>(
108108
s.split('\0').map(String::from).collect();
109109
cb(app.app_handle(), args, cwd.clone());
110110
}
111-
Err(e) => log::debug!("single_instance failed to be notified: {e}"),
111+
Err(e) => {
112+
tracing::debug!("single_instance failed to be notified: {e}")
113+
}
112114
}
113115
}
114116
Err(err) => {
115-
log::debug!("single_instance failed to be notified: {}", err);
117+
tracing::debug!("single_instance failed to be notified: {}", err);
116118
continue;
117119
}
118120
}
119121
}
120122
});
121123
}
122124
Err(err) => {
123-
log::error!(
125+
tracing::error!(
124126
"single_instance failed to listen to other processes - launching normally: {}",
125127
err
126128
);

plugins/store/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ tauri-plugin = { workspace = true, features = ["build"] }
2727
serde = { workspace = true }
2828
serde_json = { workspace = true }
2929
tauri = { workspace = true }
30-
log = { workspace = true }
30+
tracing = { workspace = true }
3131
thiserror = { workspace = true }
3232
dunce = { workspace = true }
3333
tokio = { version = "1", features = ["sync", "time", "macros"] }

plugins/store/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ impl Builder {
432432
for (path, rid) in stores.iter() {
433433
if let Ok(store) = app_handle.resources_table().get::<Store<R>>(*rid) {
434434
if let Err(err) = store.save() {
435-
log::error!("failed to save store {path:?} with error {err:?}");
435+
tracing::error!("failed to save store {path:?} with error {err:?}");
436436
}
437437
}
438438
}

0 commit comments

Comments
 (0)