-
Notifications
You must be signed in to change notification settings - Fork 742
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
Add sample implementation of FormatEvent
#1189
Conversation
Hi @davidpdrsn, would you mind rebasing this branch onto the latest master? Thanks! |
e3eb675
to
7a16586
Compare
Done 😊 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had a few suggestions, but this looks good to me overall!
/// let ext = span.extensions(); | ||
/// let fields = &ext | ||
/// .get::<FormattedFields<N>>() | ||
/// .expect("will never be `None`"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it would probably be good to have an additional comment explaining this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I stole a line from the docs in 602d7e7
looks like this somehow made rustfmt unhappy? |
Hm strange. Works for me.
|
48837c8
to
a0b7e85
Compare
The docs previously didn't provide much help implementing `FormatEvent`. Especially getting access to fields on spans could be tricky unless the user was aware of `FormattedFields`. This updates the docs with a basic, but working, example.
Co-authored-by: Eliza Weisman <[email protected]>
a9fc915
to
c9f619a
Compare
Omg its green 🤯 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This LGTM!
* Add sample implementation of `FormatEvent` The docs previously didn't provide much help implementing `FormatEvent`. Especially getting access to fields on spans could be tricky unless the user was aware of `FormattedFields`. This updates the docs with a basic, but working, example. * Apply suggestions from code review Co-authored-by: Eliza Weisman <[email protected]> * Add comment explaining what `FormattedFields` is * Expand docs a bit * Fix formatting Co-authored-by: Eliza Weisman <[email protected]>
* Add sample implementation of `FormatEvent` The docs previously didn't provide much help implementing `FormatEvent`. Especially getting access to fields on spans could be tricky unless the user was aware of `FormattedFields`. This updates the docs with a basic, but working, example. * Apply suggestions from code review Co-authored-by: Eliza Weisman <[email protected]> * Add comment explaining what `FormattedFields` is * Expand docs a bit * Fix formatting Co-authored-by: Eliza Weisman <[email protected]>
* Add sample implementation of `FormatEvent` The docs previously didn't provide much help implementing `FormatEvent`. Especially getting access to fields on spans could be tricky unless the user was aware of `FormattedFields`. This updates the docs with a basic, but working, example. * Apply suggestions from code review Co-authored-by: Eliza Weisman <[email protected]> * Add comment explaining what `FormattedFields` is * Expand docs a bit * Fix formatting Co-authored-by: Eliza Weisman <[email protected]>
Fixed - **env-filter**: Fixed directives where the level is in mixed case (such as `Info`) failing to parse ([#1126]) - **fmt**: Fixed `fmt::Subscriber` not providing a max-level hint ([#1251]) - `tracing-subscriber` no longer enables `tracing` and `tracing-core`'s default features ([#1144]) Changed - **chrono**: Updated `chrono` dependency to 0.4.16 ([#1189]) - **log**: Updated `tracing-log` dependency to 0.1.2 Thanks to @salewski, @taiki-e, @davidpdrsn and @markdingram for contributing to this release! [#1126]: #1126 [#1251]: #1251 [#1144]: #1144 [#1189]: #1189 Signed-off-by: Eliza Weisman <[email protected]>
### Fixed - **env-filter**: Fixed directives where the level is in mixed case (such as `Info`) failing to parse ([#1126]) - **fmt**: Fixed `fmt::Subscriber` not providing a max-level hint ([#1251]) - `tracing-subscriber` no longer enables `tracing` and `tracing-core`'s default features ([#1144]) ### Changed - **chrono**: Updated `chrono` dependency to 0.4.16 ([#1189]) - **log**: Updated `tracing-log` dependency to 0.1.2 Thanks to @salewski, @taiki-e, @davidpdrsn and @markdingram for contributing to this release! [#1126]: #1126 [#1251]: #1251 [#1144]: #1144 [#1189]: #1189 Signed-off-by: Eliza Weisman <[email protected]>
### Fixed - **env-filter**: Fixed directives where the level is in mixed case (such as `Info`) failing to parse ([tokio-rs#1126]) - **fmt**: Fixed `fmt::Subscriber` not providing a max-level hint ([tokio-rs#1251]) - `tracing-subscriber` no longer enables `tracing` and `tracing-core`'s default features ([tokio-rs#1144]) ### Changed - **chrono**: Updated `chrono` dependency to 0.4.16 ([tokio-rs#1189]) - **log**: Updated `tracing-log` dependency to 0.1.2 Thanks to @salewski, @taiki-e, @davidpdrsn and @markdingram for contributing to this release! [tokio-rs#1126]: tokio-rs#1126 [tokio-rs#1251]: tokio-rs#1251 [tokio-rs#1144]: tokio-rs#1144 [tokio-rs#1189]: tokio-rs#1189 Signed-off-by: Eliza Weisman <[email protected]>
Motivation
I recently had to write a custom
FormatEvent
implementation. Most things were straight forward but I struggled with how to print the values of fields on the span. Through the context you can getSpanRef
s but those don't include field values, only field names. I had to dig around in the code to discoverFormattedFields
which made things easy. I think an example implementation in the docs would be helpful to others.Solution
A sample implementation of
FormatEvent
in the docs that prints level, span name and fields, and event.