Backport 9217 to release-25.0.0#9259
Merged
alexcrichton merged 2 commits intobytecodealliance:release-25.0.0from Sep 16, 2024
Merged
Backport 9217 to release-25.0.0#9259alexcrichton merged 2 commits intobytecodealliance:release-25.0.0from
alexcrichton merged 2 commits intobytecodealliance:release-25.0.0from
Conversation
…s across await points (bytecodealliance#9217) * Use `tracing::Instrument` in generated bindings to avoid holding spans across await points Previously, if we had a WIT file with a function async-fn: func(); then the generated code in `add_to_linker_get_host` would look like this (if tracing is enabled and the function is async) inst.func_wrap_async( "my-func", move |mut caller: wasmtime::StoreContextMut<'_, T>, (): ()| { wasmtime::component::__internal::Box::new(async move { let span = tracing::span!( tracing::Level::TRACE, "wit-bindgen import", module = "test", function = "my-func", ); let _enter = span.enter(); tracing::event!(tracing::Level::TRACE, "call"); let host = &mut host_getter(caller.data_mut()); let r = Host::my_func(host).await; tracing::event!( tracing::Level::TRACE, result = tracing::field::debug(&r), "return" ); Ok(r) }) }, )?; This keeps the tracing span active, even when the resulting future is suspended. The end result is that other unrelated tokio tasks running on the same thread in the meantime will be shown as executing within the `wit-bindgen import` span. This commit changes the codegen to instead generate inst.func_wrap_async( "async-fn", move |mut caller: wasmtime::StoreContextMut<'_, T>, (): ()| { use tracing::Instrument; let span = tracing::span!( tracing::Level::TRACE, "wit-bindgen import", module = "test", function = "async-fn", ); wasmtime::component::__internal::Box::new( async move { tracing::event!(tracing::Level::TRACE, "call"); let host = &mut host_getter(caller.data_mut()); let r = Host::async_fn(host).await; tracing::event!( tracing::Level::TRACE, result = tracing::field::debug(&r), "return" ); Ok(r) } .instrument(span), ) }, )?; Here, `tracing::Instrument` takes care of entering the span when the future is polled and exiting it when it is suspended. Fixes bytecodealliance#9210 * Bless expanded macro outputs
alexcrichton
approved these changes
Sep 16, 2024
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Backport the fix for #9210 to the release-25.0.0 branch, and update the release notes to describe the fix.