Skip to content
Merged
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
31 changes: 27 additions & 4 deletions crates/wit-bindgen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 = \"{}\",
);
Expand All @@ -1131,7 +1132,22 @@ impl<'a> InterfaceGenerator<'a> {
TypeOwner::None => "<no owner>",
},
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::<Vec<String>>();
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");
Expand All @@ -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()
Expand Down Expand Up @@ -1272,7 +1295,7 @@ impl<'a> InterfaceGenerator<'a> {
"
let span = tracing::span!(
tracing::Level::TRACE,
\"wit-bindgen guest export\",
\"wit-bindgen export\",
module = \"{}\",
function = \"{}\",
);
Expand Down