Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wasmtime component bindgen: when tracing is enabled, emit an event for args & results #6209

Merged
merged 3 commits into from
Apr 13, 2023
Merged
Changes from 1 commit
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: 28 additions & 3 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,24 @@ 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>>();
if event_fields.is_empty() {
event_fields.push(format!("\"call\""));
}
uwrite!(
self.src,
"tracing::event!(tracing::Level::TRACE, {});\n",
pchickey marked this conversation as resolved.
Show resolved Hide resolved
event_fields.join(", ")
);
}

self.src.push_str("let host = get(caller.data_mut());\n");
Expand All @@ -1146,6 +1164,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));"
);
}

if self
.special_case_trappable_error(owner, &func.results)
.is_some()
Expand Down