-
Notifications
You must be signed in to change notification settings - Fork 24
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
Use tracing/tracing_subscriber instead of env_logger #1187
Conversation
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.
Looks good. While this adds a fair bit of complexity which makes me a bit uncomfortable, I can see how the span feature and similar can be very useful. On balance, I think this is an improvement.
…and coloring are now specified via an env variable
… parallel; appease clippy; a TODO was added
1d8a081
to
66ddabb
Compare
Action::Ref(call) => { | ||
worker_tasks.spawn(async move { | ||
let subsys = subsys.read().await; | ||
call(&*subsys).await | ||
}); | ||
}.in_current_span()); |
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 can see a future where we gradually move away from task::spawn
in favour of various task pools and scoped tasks and similar. That means either invoking in_current_span
manually like here or coming up with a wrapper to make it convenient (similar to the top-level spawn_in_current_span
).
Does it make sense to address it now or should we leave it and deal with it as the need arises?
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 not sure how to address this now, because it's not clear to me what those spawn
replacements will look like.
Do you have any particular 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'm fine doing it as the need arises and some patterns emerge
log.workspace = true | ||
thiserror.workspace = true | ||
tokio = { workspace = true, default-features = false, features = ["rt", "sync"] } |
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.
Tokio with logging... what could go wrong...
Just for the record, I hate this... but I think I can't provide a case against it to stop it. I hope I'm wrong.
This supersedes https://git.mintlayer.org/mintlayer/mintlayer-core/-/merge_requests/1149
The usage of
env_logger
was replaced withtracing
/tracing_subscriber
.Logging in p2p tests is now initialized globally via the
ctor
crate, instead of doing so explicitly for certain tests only (this selectivity didn't work properly anyway).Calls of the
#[tracing::instrument]
macro were put on every test on p2p, so that the test's name is included in the corresponding log messages.For this to work properly, some futures had to be "instrumented" via the call to the
instrument
method.The type of the log (json/text) and its coloring can now be selected via a separate env var
ML_LOG_STYLE
.The unused "file path" parameter of
init_logging
was removed.Update: I've moved all trivial changes into a separate PR #1191. Also, I've applied Lukas's comment about wrapping the
.instrument
calls in a function. For now this function (spawn_in_current_span
) is called only in selected places, so that the tracing span info is printed in p2p tests. I'm not sure whether I should use it everywhere instead of the normaltokio::spawn
call (for now it won't make any difference, because neither tests of other components nor the production code uses tracing spans, but it still looks a bit inconsistent).