-
-
Notifications
You must be signed in to change notification settings - Fork 142
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 an environment-configured console_subscriber::init #53
Conversation
103021e
to
f8edc47
Compare
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.
overall, this looks like the right general direction; i had some minor style and documentation suggestions.
console-subscriber/src/builder.rs
Outdated
/** | ||
Configures this builder from a standard set of environment variables: | ||
|
||
* `TOKIO_CONSOLE_RETENTION`: The number of seconds to accumulate | ||
completed tracing data. Default: 60s. | ||
* `TOKIO_CONSOLE_BIND`: a HOST:PORT description, such as | ||
localhost:1234 or similar. Default: 127.0.0.1:6669 | ||
* `TOKIO_CONSOLE_PUBLISH_INTERVAL`: The number of milliseconds to wait | ||
between sending updates to the console. Default: 1000ms (1s) | ||
*/ |
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.
style nit: elsewhere we use ///
-style doc comments exclusively...i could be convinced to switch to using block comments for doc comments, but i'd prefer to be consistent about it.
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'm a big fan of /**
/ /*!
for doc comments because it's less visually distracting, but in this case it was just habit and I should have checked for project convention
console-subscriber/src/lib.rs
Outdated
Starts the console subscriber server on its own thread | ||
|
||
This function represents the easiest way to get started using | ||
tokio-console. | ||
|
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.
these docs should probably state explicitly that this function also sets the default tracing
subscriber (and maybe include a link to the tracing
docs?). otherwise, i can see people being surprised if they try to set their own subscriber and it fails because the default subscriber is already set.
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.
addressed in f2b6de5
console-subscriber/src/builder.rs
Outdated
/// localhost:1234 or similar. Default: 127.0.0.1:6669 | ||
/// * `TOKIO_CONSOLE_PUBLISH_INTERVAL`: The number of milliseconds to wait | ||
/// between sending updates to the console. Default: 1000ms (1s) | ||
|
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.
take it or leave it: it would be nice if the docs for this also included an example of using the builder to configure a console layer from the default environment variables , and then using it to build a subscriber, spawn the background task, etc? but, we can come back and add that later.
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.
Before I saw your review on this PR, I attempted to address this use case by adding a single in-code extension point: init_with_layer
, with the hope that we can accommodate all common initialization patterns and discourage anyone who would need docs on how to eject from doing so. With the addition of init_with_layer, have we covered all of those use cases? An advantage of this approach is that if the majority of users are going through init
or init_with_layer
, future changes to those functions wouldn't require app code change, whereas if we encourage a copy-paste initializer through documentation, we have no way of pushing out changes to that "ejected" code.
console-subscriber/src/lib.rs
Outdated
* `TOKIO_CONSOLE_RETENTION`: The number of seconds to accumulate | ||
completed tracing data. Default: 60s. | ||
* `TOKIO_CONSOLE_BIND`: a HOST:PORT description, such as | ||
localhost:1234 or similar. Default: 127.0.0.1:6669 | ||
* `TOKIO_CONSOLE_PUBLISH_INTERVAL`: The number of milliseconds to wait | ||
between sending updates to the console. Default: 1000ms (1s) | ||
* `RUST_LOG`: configure the tracing filter. Default: `tokio=trace`, | ||
and any additional filtering directives will be appended to this | ||
default. See [`EnvFilter`] for further information on the format | ||
for this variable. |
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.
take it or leave it: similarly, this might want to be a table?
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.
addressed in f2b6de5
Co-authored-by: Eliza Weisman <eliza@buoyant.io>
Co-authored-by: Eliza Weisman <eliza@buoyant.io>
Co-authored-by: Eliza Weisman <eliza@buoyant.io>
console-subscriber/src/init.rs
Outdated
|
||
/// Starts the console subscriber server with an additional subscriber | ||
/// layer, for example a log layer. This interface can be combined | ||
/// with any of the environment configuration documented at [`init`]. |
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 be nice to show an example here, but it's okay to add that in a follow-up branch if you prefer?
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.
What's a good example layer that people might want to add on here? My inexperience with tracing means I don't have a good intuition for what people might want
console-subscriber/src/init.rs
Outdated
EnvFilter::from_default_env().add_directive("tokio=trace".parse().unwrap()); | ||
|
||
let console_subscriber = tracing_subscriber::registry() | ||
.with(fmt::layer()) |
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.
do we always want to include a fmt
layer? this means that users can't customize how events are logged, even if they call init_with_layer
. i might just only add the fmt
layer in init
.
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'm new to tracing, but layers seem to be order-dependent, and there's no way to prepend because everything is composed through wrapping, so I'm not sure how to extract the fmt layer. Any suggestions?
Do you imagine replacing the fmt layer to be a commonly-needed extension point? I'm trying to figure out how to balance keeping the usage simple with providing the right sort of escape hatches for common customization
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'm new to tracing, but layers seem to be order-dependent, and there's no way to prepend because everything is composed through wrapping, so I'm not sure how to extract the fmt layer. Any suggestions?
layers are not order dependent :)
Do you imagine replacing the fmt layer to be a commonly-needed extension point? I'm trying to figure out how to balance keeping the usage simple with providing the right sort of escape hatches for common customization
the fmt
layer is very configurable. i think wanting to change how events are formatted by providing your own fmt
layer is probably going to be one of the most common use-cases for overriding the default configuration. for example, if you want to change the log format from textual to JSON, the current API means that you would have to use the builder and do everything manually.
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.
addressed in bb2c2db — there's now init
and build
and build
doesn't add the fmt layer. this does involve a bit of heavy-handed documentation because that might be surprising
console-subscriber/src/init.rs
Outdated
pub fn init_with_layer<AdditionalLayer>(additional_layer: AdditionalLayer) | ||
where | ||
AdditionalLayer: Layer<ConsoleSubscriberLayer> + Send + Sync + 'static, |
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.
an alternative API design is to have a function that spawns the background thread, and just returns a Registry
with the EnvFilter
and TasksLayer
layers already added. that way, the user can call any methods on that Registry
to add additional layers, and set it as the default subscriber themselves. the init
function could just call that and then immediately call init()
on the returned registry.
i feel like this design could be more intuitive than taking a layer as an argument, but it might be slightly wordier to use...i could be convinced either way.
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.
That does feel more flexible. What if instead of init_with_layer it was build() -> impl Layer + Into<Dispatch>
, with #[must_use]
.
console_subscriber::build().with(…).init()
console_subscriber::init(); // shorthand for console_subscriber::build().init();
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.
addressed in bb2c2db — build and init
Co-authored-by: Eliza Weisman <eliza@buoyant.io>
because clippy was right
use tokio::runtime; | ||
use tracing_subscriber::{fmt, layer::Layered, prelude::*, EnvFilter, Registry}; | ||
|
||
type ConsoleSubscriberLayer = Layered<TasksLayer, Layered<EnvFilter, 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.
nit (and this isn't that important, since this isn't part of the public API), i would just call this
type ConsoleSubscriberLayer = Layered<TasksLayer, Layered<EnvFilter, Registry>>; | |
type ConsoleSubscriber = Layered<TasksLayer, Layered<EnvFilter, Registry>>; |
this type isn't actually a Layer
, since it includes a subscriber --- it doesn't implement the Layer
trait, it implements the Subscriber
trait.
/// ``` | ||
|
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.
nit: extra whitespace here
/// ``` | |
/// ``` |
/// ``` | ||
|
||
#[must_use = "build() without init() will not attach a tracing subscriber"] | ||
pub fn build() -> ConsoleSubscriberLayer { |
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.
take it or leave it: i'm not totally sold on the name build()
for this --- it doesn't feel super clear to me how this differs from init()
.. i might have called this subscriber()
or something, because it returns a Subscriber
. but, i'm not attached to that, this is fine.
closes #49