diff --git a/crates/wiggle/Cargo.toml b/crates/wiggle/Cargo.toml index d8ede624a7..a176469669 100644 --- a/crates/wiggle/Cargo.toml +++ b/crates/wiggle/Cargo.toml @@ -14,7 +14,7 @@ include = ["src/**/*", "README.md", "LICENSE"] thiserror = "1" witx = { path = "../wasi-common/WASI/tools/witx", version = "0.9.1", optional = true } wiggle-macro = { path = "macro", version = "0.29.0" } -tracing = "0.1.15" +tracing = "0.1.26" bitflags = "1.2" async-trait = "0.1.42" wasmtime = { path = "../wasmtime", version = "0.29.0", optional = true, default-features = false } diff --git a/crates/wiggle/generate/src/funcs.rs b/crates/wiggle/generate/src/funcs.rs index 31e4a7bc26..693f1fe3e9 100644 --- a/crates/wiggle/generate/src/funcs.rs +++ b/crates/wiggle/generate/src/funcs.rs @@ -73,36 +73,54 @@ fn _define_func( }, ); - let asyncness = if settings.get_async(&module, &func).is_sync() { - quote!() - } else { - quote!(async) - }; let mod_name = &module.name.as_str(); let func_name = &func.name.as_str(); - ( - quote! { - #[allow(unreachable_code)] // deals with warnings in noreturn functions - pub #asyncness fn #ident( - ctx: &mut (impl #(#bounds)+*), - memory: &dyn #rt::GuestMemory, - #(#abi_params),* - ) -> Result<#abi_ret, #rt::Trap> { - use std::convert::TryFrom as _; - - let _span = #rt::tracing::span!( - #rt::tracing::Level::TRACE, - "wiggle abi", - module = #mod_name, - function = #func_name - ); - let _enter = _span.enter(); - - #body - } - }, - bounds, - ) + let mk_span = quote!( + let _span = #rt::tracing::span!( + #rt::tracing::Level::TRACE, + "wiggle abi", + module = #mod_name, + function = #func_name + ); + ); + if settings.get_async(&module, &func).is_sync() { + ( + quote!( + #[allow(unreachable_code)] // deals with warnings in noreturn functions + pub fn #ident( + ctx: &mut (impl #(#bounds)+*), + memory: &dyn #rt::GuestMemory, + #(#abi_params),* + ) -> Result<#abi_ret, #rt::Trap> { + use std::convert::TryFrom as _; + #mk_span + _span.in_scope(|| { + #body + }) + } + ), + bounds, + ) + } else { + ( + quote!( + #[allow(unreachable_code)] // deals with warnings in noreturn functions + pub fn #ident<'a>( + ctx: &'a mut (impl #(#bounds)+*), + memory: &'a dyn #rt::GuestMemory, + #(#abi_params),* + ) -> impl std::future::Future> + 'a { + use std::convert::TryFrom as _; + use #rt::tracing::Instrument as _; + #mk_span + async move { + #body + }.instrument(_span) + } + ), + bounds, + ) + } } struct Rust<'a> { diff --git a/crates/wiggle/test-helpers/Cargo.toml b/crates/wiggle/test-helpers/Cargo.toml index 7944bbe24e..b77fb9333e 100644 --- a/crates/wiggle/test-helpers/Cargo.toml +++ b/crates/wiggle/test-helpers/Cargo.toml @@ -17,7 +17,7 @@ wiggle = { path = "..", features = ["tracing_log"] } [dev-dependencies] thiserror = "1.0" -tracing = "0.1.14" +tracing = "0.1.26" tracing-subscriber = "0.2.4" env_logger = "0.8"