-
Notifications
You must be signed in to change notification settings - Fork 9
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
Migrate from log to tracing #58
Conversation
for formatted_exit_state in formatted_exit_states { | ||
log::debug!(" {}", formatted_exit_state); | ||
} | ||
|
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.
Did you remove this out of personal preference? Or did it break some kind of tracing
guideline? What's the rationale behind 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.
No, actually tracing dose not have an official guideline
.
But in my understanding, tracing logs is made of event
and span
, where every event
should be an independent message, and the context for event should be include in it's span
, not the event happen beside to it.
I think we can keep this by concat all the format messages in one string and output them out in one event
, but i think trigger an event when every subsystem is end will be an better idea.
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.
You don't "trigger when a subsystem ends", though. You do it in perform_shutdown_on_subsystems
, after all the results are collected in a Vec
first. So I don't see the advantage; printing them in toplevel.rs
would at least show toplevel.rs
as the source file in tracing
. With your change, the source is tokio_graceful_shutdown::subsystem::data
, which in its entirety is an internal file not exposed to the user.
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's a debug
message only, anyway. I'd prefer concatenating the number of messages in one big status message instead, as you suggested.
emm, any other suggestions? |
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 don't have much spare time at the moment, please forgive long response periods.
for formatted_exit_state in formatted_exit_states { | ||
log::debug!(" {}", formatted_exit_state); | ||
} | ||
|
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.
You don't "trigger when a subsystem ends", though. You do it in perform_shutdown_on_subsystems
, after all the results are collected in a Vec
first. So I don't see the advantage; printing them in toplevel.rs
would at least show toplevel.rs
as the source file in tracing
. With your change, the source is tokio_graceful_shutdown::subsystem::data
, which in its entirety is an internal file not exposed to the user.
for formatted_exit_state in formatted_exit_states { | ||
log::debug!(" {}", formatted_exit_state); | ||
} | ||
|
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's a debug
message only, anyway. I'd prefer concatenating the number of messages in one big status message instead, as you suggested.
src/toplevel.rs
Outdated
@@ -236,6 +222,7 @@ impl<ErrType: ErrTypeTraits> Toplevel<ErrType> { | |||
/// | |||
/// An error of type [`GracefulShutdownError`] if an error occurred. | |||
/// | |||
#[tracing::instrument(name = "Global System Shutdown", skip_all, level = "debug", fields(timeout = %humantime::format_duration(shutdown_timeout)))] |
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.
Would you mind explaining the rationale for this line? Is this best practice to add a name
whenever possible? I kind of find it distracting. Either way, Global System Shutdown
is kind of incorrect, because people could use nested toplevels and similar. I would prefer to leave the name out, as it will only lead to discussion concerning the correctness of the name. Can't we simply leave out the entire #[tracing::instrument()]
line? Why do we have it? What's wrong with the default? Maybe I simply don't know enough about tracing
.
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.
After reading a little more, I now kind of understand the concept of spans and grasp what #[tracing::instrument]
is for. I don't quite understand what we need the humantime
crate for, as Duration
is already Debug
printable. Further, I don't understand why skip_all
, followed by fields
if we could simply do skip(self)
.
Lastly, I kind of don't quite understand why we need this in general; this will never enter user code, so what's the point in using spans here?
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.
Further, why do we need any of this if there is already tracing-log
? What's the advantage of switching to tracing
in this crate?
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.
tracing-log is just convert every log into event, if we use many layers of subsystems, it's hard to tell which message is from where.
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 understand, but the subsystems themselves should then derive #[tracing::instrument]
, and there is nothing in this crate that prevents this. Setting a span within our code won't do anything for the subsystems themselves, as they are not connected to our code, they get spawned via tokio::spawn
.
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.
You're right, sorry, I didn't think well.
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 did think about moving over to tracing either way at some point. The reason I didn't so far was compatibility - it's a lot easier to use this crate in tracing
if it itself implements log
than the other way round. But of course I could be mistaken; if it is equally simple to use this crate in log
if itself implements tracing
, then I'm actually more inclined to move over to tracing
than not :) After playing around with bevy
I do think that tracing
is the future.
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.
Either way, regardless of whether we move the crate itself over, I definitely would like to move the examples over to tracing
to demonstrate how it should work. But if both can happen simultaneously without breaking too much, I think we should continue with this branch. Don't be intimidated by my feedback, I tend to question things. Not to discredit them, but to understand them :)
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.
If you don't want to continue because it no longer is a valid usecase for you, I might take over your branch if that's fine?
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.
If you don't want to continue because it no longer is a valid usecase for you, I might take over your branch if that's fine?
OK
if let Err(e) = &errors { | ||
match e { | ||
GracefulShutdownError::SubsystemsFailed(_) => { | ||
log::warn!("Subsystems failed.") | ||
sum.push_str(format!("Subsystems failed.\n").as_str()); |
Check warning
Code scanning / clippy
useless use of format! Warning
} | ||
GracefulShutdownError::ShutdownTimeout(_) => { | ||
log::warn!("Shutdown timed out.") | ||
sum.push_str(format!("Shutdown timed out.\n").as_str()); |
Check warning
Code scanning / clippy
useless use of format! Warning
} | ||
MyError::WithoutData => { | ||
log::warn!(" It failed with MyError::WithoutData") | ||
sum.push_str( | ||
format!(" It failed with MyError::WithoutData\n").as_str(), |
Check warning
Code scanning / clippy
useless use of format! Warning
Why did you close it? I'm absolutely open to this change, I just want to get it right, that's why I'm asking questions :) I want to understand what tracing brings to the table |
I have tracing on my radar for a while already now, I just never got around to it |
No, i really think there is no use for do this if we just use span on subsystems, unless we just do an string replace from |
As I will take over, let me close this PR and let me open one with a branch I can edit :) |
Close #57
I'm not very familiar with this crate, so if i write some message wrong please tell me.