diff --git a/crates/wit-bindgen/src/lib.rs b/crates/wit-bindgen/src/lib.rs index f564a5a9561c..5af48778c158 100644 --- a/crates/wit-bindgen/src/lib.rs +++ b/crates/wit-bindgen/src/lib.rs @@ -1112,11 +1112,12 @@ impl<'a> InterfaceGenerator<'a> { } if self.gen.opts.tracing { - self.src.push_str(&format!( + uwrite!( + self.src, " let span = tracing::span!( tracing::Level::TRACE, - \"wit-bindgen guest import\", + \"wit-bindgen import\", module = \"{}\", function = \"{}\", ); @@ -1131,7 +1132,22 @@ impl<'a> InterfaceGenerator<'a> { TypeOwner::None => "", }, func.name, - )); + ); + let mut event_fields = func + .params + .iter() + .enumerate() + .map(|(i, (name, _ty))| { + let name = to_rust_ident(&name); + format!("{name} = tracing::field::debug(&arg{i})") + }) + .collect::>(); + event_fields.push(format!("\"call\"")); + uwrite!( + self.src, + "tracing::event!(tracing::Level::TRACE, {});\n", + event_fields.join(", ") + ); } self.src.push_str("let host = get(caller.data_mut());\n"); @@ -1146,6 +1162,13 @@ impl<'a> InterfaceGenerator<'a> { uwrite!(self.src, ");\n"); } + if self.gen.opts.tracing { + uwrite!( + self.src, + "tracing::event!(tracing::Level::TRACE, result = tracing::field::debug(&r), \"return\");" + ); + } + if self .special_case_trappable_error(owner, &func.results) .is_some() @@ -1272,7 +1295,7 @@ impl<'a> InterfaceGenerator<'a> { " let span = tracing::span!( tracing::Level::TRACE, - \"wit-bindgen guest export\", + \"wit-bindgen export\", module = \"{}\", function = \"{}\", );