From 72be786b8613f89311e5fe3562123ca67391e200 Mon Sep 17 00:00:00 2001 From: Tunglies <77394545+Tunglies@users.noreply.github.com> Date: Fri, 6 Feb 2026 11:12:00 +0800 Subject: [PATCH] feat(async_runtime): enable track_caller attribute for async_runtime under tracing feature --- .changes/feat-async_runtime-track.md | 5 +++++ crates/tauri/src/async_runtime.rs | 13 +++++++++++++ 2 files changed, 18 insertions(+) create mode 100644 .changes/feat-async_runtime-track.md diff --git a/.changes/feat-async_runtime-track.md b/.changes/feat-async_runtime-track.md new file mode 100644 index 000000000..2bf5718b6 --- /dev/null +++ b/.changes/feat-async_runtime-track.md @@ -0,0 +1,5 @@ +--- +"tauri": feat +--- + +Enable track_caller attribute for async_runtime under the tracing feature to provide better location information in logs and panics. diff --git a/crates/tauri/src/async_runtime.rs b/crates/tauri/src/async_runtime.rs index 4925878ce..fc367f007 100644 --- a/crates/tauri/src/async_runtime.rs +++ b/crates/tauri/src/async_runtime.rs @@ -42,6 +42,7 @@ impl GlobalRuntime { } } + #[cfg_attr(feature = "tracing", track_caller)] fn spawn(&self, task: F) -> JoinHandle where F: Future + Send + 'static, @@ -54,6 +55,7 @@ impl GlobalRuntime { } } + #[cfg_attr(feature = "tracing", track_caller)] pub fn spawn_blocking(&self, func: F) -> JoinHandle where F: FnOnce() -> R + Send + 'static, @@ -66,6 +68,7 @@ impl GlobalRuntime { } } + #[cfg_attr(feature = "tracing", track_caller)] fn block_on(&self, task: F) -> F::Output { if let Some(r) = &self.runtime { r.block_on(task) @@ -95,6 +98,7 @@ impl Runtime { } } + #[cfg_attr(feature = "tracing", track_caller)] /// Spawns a future onto the runtime. pub fn spawn(&self, task: F) -> JoinHandle where @@ -109,6 +113,7 @@ impl Runtime { } } + #[cfg_attr(feature = "tracing", track_caller)] /// Runs the provided function on an executor dedicated to blocking operations. pub fn spawn_blocking(&self, func: F) -> JoinHandle where @@ -120,6 +125,7 @@ impl Runtime { } } + #[cfg_attr(feature = "tracing", track_caller)] /// Runs a future to completion on runtime. pub fn block_on(&self, task: F) -> F::Output { match self { @@ -177,6 +183,7 @@ impl RuntimeHandle { h } + #[cfg_attr(feature = "tracing", track_caller)] /// Runs the provided function on an executor dedicated to blocking operations. pub fn spawn_blocking(&self, func: F) -> JoinHandle where @@ -188,6 +195,7 @@ impl RuntimeHandle { } } + #[cfg_attr(feature = "tracing", track_caller)] /// Spawns a future onto the runtime. pub fn spawn(&self, task: F) -> JoinHandle where @@ -202,6 +210,7 @@ impl RuntimeHandle { } } + #[cfg_attr(feature = "tracing", track_caller)] /// Runs a future to completion on runtime. pub fn block_on(&self, task: F) -> F::Output { match self { @@ -258,12 +267,14 @@ pub fn handle() -> RuntimeHandle { runtime.handle() } +#[cfg_attr(feature = "tracing", track_caller)] /// Runs a future to completion on runtime. pub fn block_on(task: F) -> F::Output { let runtime = RUNTIME.get_or_init(default_runtime); runtime.block_on(task) } +#[cfg_attr(feature = "tracing", track_caller)] /// Spawns a future onto the runtime. pub fn spawn(task: F) -> JoinHandle where @@ -274,6 +285,7 @@ where runtime.spawn(task) } +#[cfg_attr(feature = "tracing", track_caller)] /// Runs the provided function on an executor dedicated to blocking operations. pub fn spawn_blocking(func: F) -> JoinHandle where @@ -284,6 +296,7 @@ where runtime.spawn_blocking(func) } +#[cfg_attr(feature = "tracing", track_caller)] #[allow(dead_code)] pub(crate) fn safe_block_on(task: F) -> F::Output where