offer function-level control over tracing (#5194)

* wiggle: fix compilation with async functions when tracing is off

Fixes #5202

* switch tracing config from a boolean to a struct

This will enable more complex tracing rules in the future

* rename AsyncConfField to FunctionField

It is going to be reused for cases other than just async functions

* add support for disabling tracing per-function

This adds a `disable_for` syntax after the `tracing` boolean.  For
example:

```
wiggle::from_witx!(
    tracing: true disable_for {
        module1::foo,
        module2::{bar, baz},
    }
)
```
This commit is contained in:
Joe Shaw
2022-11-05 14:31:09 -04:00
committed by GitHub
parent fba2287c54
commit 1ddf03aaa1
5 changed files with 99 additions and 19 deletions

View File

@@ -84,7 +84,7 @@ fn _define_func(
);
);
if settings.get_async(&module, &func).is_sync() {
let traced_body = if settings.tracing {
let traced_body = if settings.tracing.enabled_for(&mod_name, &func_name) {
quote!(
#mk_span
_span.in_scope(|| {
@@ -109,7 +109,7 @@ fn _define_func(
bounds,
)
} else {
let traced_body = if settings.tracing {
let traced_body = if settings.tracing.enabled_for(&mod_name, &func_name) {
quote!(
use #rt::tracing::Instrument as _;
#mk_span
@@ -261,7 +261,12 @@ impl witx::Bindgen for Rust<'_> {
args.push(quote!(#name));
}
}
if self.settings.tracing && func.params.len() > 0 {
if self
.settings
.tracing
.enabled_for(self.module.name.as_str(), self.funcname)
&& func.params.len() > 0
{
let args = func
.params
.iter()
@@ -290,7 +295,11 @@ impl witx::Bindgen for Rust<'_> {
let ret = #trait_name::#ident(ctx, #(#args),*).await;
})
};
if self.settings.tracing {
if self
.settings
.tracing
.enabled_for(self.module.name.as_str(), self.funcname)
{
self.src.extend(quote! {
#rt::tracing::event!(
#rt::tracing::Level::TRACE,