-
Notifications
You must be signed in to change notification settings - Fork 733
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
subscriber: add more ergonomic subscriber configuration APIs #660
Conversation
I think it might be okay to only have |
@@ -50,11 +50,11 @@ fn do_another_thing( | |||
|
|||
#[tracing::instrument] | |||
fn main() { | |||
let subscriber = Registry::default() | |||
.with(FmtLayer::default()) | |||
tracing_subscriber::registry() |
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 wish there was a way to replace this expr with something like tracing_subscriber::fmt()
, aka some sort of conversion fn for a fmt builder to a registry + layer
Signed-off-by: Eliza Weisman <eliza@buoyant.io>
Signed-off-by: Eliza Weisman <eliza@buoyant.io>
Signed-off-by: Eliza Weisman <eliza@buoyant.io>
Signed-off-by: Eliza Weisman <eliza@buoyant.io>
Signed-off-by: Eliza Weisman <eliza@buoyant.io>
Signed-off-by: Eliza Weisman <eliza@buoyant.io>
Signed-off-by: Eliza Weisman <eliza@buoyant.io>
Signed-off-by: Eliza Weisman <eliza@buoyant.io>
Signed-off-by: Eliza Weisman <eliza@buoyant.io>
Signed-off-by: Eliza Weisman <eliza@buoyant.io>
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 think this is a pretty good improvement and I'm not seeing any issues. I'd like to try this out and report back if I run into any issues.
Signed-off-by: Eliza Weisman <eliza@buoyant.io>
Signed-off-by: Eliza Weisman <eliza@buoyant.io>
Signed-off-by: Eliza Weisman <eliza@buoyant.io>
@yaahc are you good with this or do we want to continue bikeshedding naming? I'm open to further discussion if you don't like the current scheme. Re:
Hmm, maybe...I think the main use-case for the non-panicking version of the API, besides cases where people want to return as many errors from #[test]
fn my_great_test() {
// ignore errors if another test has already set the global subscriber
let _ = tracing_subscriber::fmt()
.with_whatever(...)
.try_init();
// ...
} which is also a pretty common pattern in the And, since trying to set a global subscriber in tests is one of the few cases where people will actually initialize a subscriber more than once per program, I think it may actually be one of the cases where providing an ergonomic API has the most impact... What do you all think? |
This makes sense and i agree with it. +1 |
# 0.2.4 (April 6, 2020) This release includes several API ergonomics improvements, including shorthand constructors for many types, and an extension trait for initializing subscribers using method-chaining style. Additionally, several bugs in less commonly used `fmt` APIs were fixed. ### Added - **fmt**: Shorthand free functions for constructing most types in `fmt` (including `tracing_subscriber::fmt()` to return a `SubscriberBuilder`, `tracing_subscriber::fmt::layer()` to return a format `Layer`, etc) (#660) - **registry**: Shorthand free function `tracing_subscriber::registry()` to construct a new registry (#660) - Added `SubscriberInitExt` extension trait for more ergonomic subscriber initialization (#660) ### Changed - **fmt**: Moved `LayerBuilder` methods to `Layer` (#655) ### Deprecated - **fmt**: `LayerBuilder`, as `Layer` now implements all builder methods (#655) ### Fixed - **fmt**: Fixed `Compact` formatter not omitting levels with `with_level(false)` (#657) - **fmt**: Fixed `fmt::Layer` duplicating the fields for a new span if another layer has already formatted its fields (#634) - **fmt**: Added missing space when using `record` to add new fields to a span that already has fields (#659) - Updated outdated documentation (#647) Signed-off-by: Eliza Weisman <eliza@buoyant.io>
Motivation
Users have said fairly frequently that configuring new subscribers in an
application is unnecessarily verbose and confusing. We should try to
make this nicer, especially as it's a common "on ramp" for new
tracing
users.
Solution
This branch adds new APIs, inspired by
tonic
andwarp
, that shouldmake setting up a subscriber a little less verbose. This includes:
tracing-subscriber
now expose free functionsthat construct default instances of various types. This makes
configuring subscribers using these types more concise, a la
warp
..set_default
,.init
, and.try_init
methods to subscribers. This generalizes the similar functions on
fmt
'sSubscriberBuilder
to work with other subscribers.All the old APIs are still left as they were previously. The new APIs
just provide shorthand for them.