-
Notifications
You must be signed in to change notification settings - Fork 734
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
attributes: skip async
spans if level disabled
#1607
Merged
Merged
Conversation
This file contains 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
Signed-off-by: Eliza Weisman <[email protected]>
Signed-off-by: Eliza Weisman <[email protected]>
this should hopefully improve the async case a bit as well Signed-off-by: Eliza Weisman <[email protected]>
hawkw
added a commit
that referenced
this pull request
Oct 1, 2021
## Motivation In #1600, the `instrument` code generation was changed to avoid ever constructing a `Span` struct if the level is explicitly disabled. However, for `async` functions, `#[instrument]` will currently still create the span, but simply skips constructing an `Instrument` future if the level is disabled. ## Solution This branch changes the `#[instrument]` code generation for async blocks to totally skip constructing the span if the level is disabled. I also simplfied the code generation a bit by combining the shared code between the `err` and non-`err` cases, reducing code duplication a bit. Signed-off-by: Eliza Weisman <[email protected]>
hawkw
added a commit
that referenced
this pull request
Oct 1, 2021
## Motivation In #1600, the `instrument` code generation was changed to avoid ever constructing a `Span` struct if the level is explicitly disabled. However, for `async` functions, `#[instrument]` will currently still create the span, but simply skips constructing an `Instrument` future if the level is disabled. ## Solution This branch changes the `#[instrument]` code generation for async blocks to totally skip constructing the span if the level is disabled. I also simplfied the code generation a bit by combining the shared code between the `err` and non-`err` cases, reducing code duplication a bit. Signed-off-by: Eliza Weisman <[email protected]>
hawkw
added a commit
that referenced
this pull request
Oct 5, 2021
The changes in #1607 introduced a potential compilation error when using the `#[instrument]` attribute on `async fn`s that return a type that includes a closure or is otherwise unnameable. This is because the future's body code was quoted in two separate places in order to have a separate branch when the span is statically disabled. This means that when a closure is returned, it will technically have two distinct types based on whether or not the span is enabled, since it originates from two separate source code locations (although `quote_spanned!` obscures this, so the compiler diagnostic will appear to have two closures originating from the same location). This branch fixes this issue by changing the code generated for `#[instrument]`ed async functions. Unfortunately, for async functions, we can't have the optimization of not creating the span at all when the level is disabled, because we need to create the span _before_ creating the future, as it may borrow arguments.
hawkw
added a commit
that referenced
this pull request
Oct 5, 2021
## Motivation The changes in #1607 introduced a potential compilation error when using the `#[instrument]` attribute on `async fn`s that return a type that includes a closure or is otherwise unnameable. This is because the future's body code was quoted in two separate places in order to have a separate branch when the span is statically disabled. This means that when a closure is returned, it will technically have two distinct types based on whether or not the span is enabled, since it originates from two separate source code locations (although `quote_spanned!` obscures this, so the compiler diagnostic will appear to have two closures originating from the same location). ## Solution This branch fixes this issue by changing the code generated for `#[instrument]`ed async functions. Unfortunately, for async functions, we can't have the optimization of not creating the span at all when the level is disabled, because we need to create the span _before_ creating the future, as it may borrow arguments. I've also added tests reproducing issue #1615 Fixes #1615
hawkw
added a commit
that referenced
this pull request
Oct 5, 2021
## Motivation The changes in #1607 introduced a potential compilation error when using the `#[instrument]` attribute on `async fn`s that return a type that includes a closure or is otherwise unnameable. This is because the future's body code was quoted in two separate places in order to have a separate branch when the span is statically disabled. This means that when a closure is returned, it will technically have two distinct types based on whether or not the span is enabled, since it originates from two separate source code locations (although `quote_spanned!` obscures this, so the compiler diagnostic will appear to have two closures originating from the same location). ## Solution This branch fixes this issue by changing the code generated for `#[instrument]`ed async functions. Unfortunately, for async functions, we can't have the optimization of not creating the span at all when the level is disabled, because we need to create the span _before_ creating the future, as it may borrow arguments. I've also added tests reproducing issue #1615 Fixes #1615
hawkw
added a commit
that referenced
this pull request
Oct 5, 2021
## Motivation The changes in #1607 introduced a potential compilation error when using the `#[instrument]` attribute on `async fn`s that return a type that includes a closure or is otherwise unnameable. This is because the future's body code was quoted in two separate places in order to have a separate branch when the span is statically disabled. This means that when a closure is returned, it will technically have two distinct types based on whether or not the span is enabled, since it originates from two separate source code locations (although `quote_spanned!` obscures this, so the compiler diagnostic will appear to have two closures originating from the same location). ## Solution This branch fixes this issue by changing the code generated for `#[instrument]`ed async functions. Unfortunately, for async functions, we can't have the optimization of not creating the span at all when the level is disabled, because we need to create the span _before_ creating the future, as it may borrow arguments. I've also added tests reproducing issue #1615 Fixes #1615
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.
Motivation
In #1600, the
instrument
code generation was changed to avoid everconstructing a
Span
struct if the level is explicitly disabled.However, for
async
functions,#[instrument]
will currently stillcreate the span, but simply skips constructing an
Instrument
future ifthe level is disabled.
Solution
This branch changes the
#[instrument]
code generation for async blocksto totally skip constructing the span if the level is disabled. I also
simplfied the code generation a bit by combining the shared code between
the
err
and non-err
cases, reducing code duplication a bit.