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

Migrate from log to tracing #58

Closed
wants to merge 6 commits into from
Closed

Migrate from log to tracing #58

wants to merge 6 commits into from

Conversation

starua
Copy link

@starua starua commented Apr 12, 2023

Close #57

I'm not very familiar with this crate, so if i write some message wrong please tell me.

for formatted_exit_state in formatted_exit_states {
log::debug!(" {}", formatted_exit_state);
}

Copy link
Owner

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?

Copy link
Author

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.

Copy link
Owner

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.

Copy link
Owner

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.

@starua
Copy link
Author

starua commented Apr 18, 2023

emm, any other suggestions?

Copy link
Owner

@Finomnis Finomnis left a 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);
}

Copy link
Owner

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);
}

Copy link
Owner

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.

examples/01_normal_shutdown.rs Outdated Show resolved Hide resolved
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)))]
Copy link
Owner

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.

Copy link
Owner

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?

Copy link
Owner

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?

Copy link
Author

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.

Copy link
Owner

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.

Copy link
Author

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.

Copy link
Owner

@Finomnis Finomnis Apr 22, 2023

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.

Copy link
Owner

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 :)

Copy link
Owner

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?

Copy link
Author

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

useless use of format!
}
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

useless use of format!
}
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

useless use of format!
@starua starua closed this Apr 22, 2023
@Finomnis
Copy link
Owner

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

@Finomnis
Copy link
Owner

I have tracing on my radar for a while already now, I just never got around to it

@starua
Copy link
Author

starua commented Apr 22, 2023

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

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 log::debug to tracing::debug. I really do think it my bad that ignore this situation. I'm not closing this pr because think you are unfriendly or something.
If you still think we should do the string replacement thing, then i'm willing to help.

@starua starua reopened this Apr 22, 2023
@Finomnis
Copy link
Owner

As I will take over, let me close this PR and let me open one with a branch I can edit :)

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.

Consider move from log to tracing
2 participants