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

Trial integrating spantrace extraction with tracing-subscriber via generic member access #1861

Closed
wants to merge 1 commit into from

Conversation

yaahc
Copy link
Collaborator

@yaahc yaahc commented Jan 26, 2022

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 a Span because SpanTrace is defined in a downstream crate and would have to be moved into tracing-subscriber to name it directly since tracing-error depends on tracing-subscriber.

This PR only compiles when using a custom rustc toolchain based on rust-lang/rust#90328

@@ -58,16 +58,6 @@ where
span.extensions_mut().insert(fields);
}
}

unsafe fn downcast_raw(&self, id: TypeId) -> Option<NonNull<()>> {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this appears to be dead code but doesn't produce a lint????!?

} else {
self.record_debug(field, &format_args!("{}", value))
let source = value.source();
let spantrace = value.chain().find_map(|value| value.request_ref::<tracing::Span>());
Copy link
Collaborator Author

@yaahc yaahc Jan 26, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this would be tracing_error::SpanTrace if it weren't for the circular dependency issue that I will need to navigate later if I ever want this to actually be a thing.

@yaahc yaahc closed this Jan 31, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant