Trial integrating spantrace extraction with tracing-subscriber via generic member access #1861
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
I'd like to be able to log errors that have captured a
SpanTrace
to gather context on the state of the world when the error was constructed. Right now this is possible but the only way to get this spantrace info back into tracing logs is to either include the info in your error message's display output or separately extract and log the spantrace in the tracing event alongside the error. I feel that the first option ends up looking bad, and the second option is error prone / easy to forget. I'd like to make this automatic in a way that formats well.Solution
This PR uses generic member access to request an arbitrary type through a
&dyn Error
trait object. For now I'm only printing aSpan
becauseSpanTrace
is defined in a downstream crate and would have to be moved intotracing-subscriber
to name it directly sincetracing-error
depends ontracing-subscriber
.This PR only compiles when using a custom rustc toolchain based on rust-lang/rust#90328