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

Use tracing/tracing_subscriber instead of env_logger #1187

Merged
merged 7 commits into from
Sep 21, 2023

Conversation

ImplOfAnImpl
Copy link
Contributor

@ImplOfAnImpl ImplOfAnImpl commented Sep 14, 2023

This supersedes https://git.mintlayer.org/mintlayer/mintlayer-core/-/merge_requests/1149

The usage of env_logger was replaced with tracing/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 normal tokio::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).

Base automatically changed from p2p_protocol_v2 to master September 15, 2023 08:55
Copy link
Contributor

@iljakuklic iljakuklic left a 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.

subsystem/src/manager.rs Show resolved Hide resolved
p2p/src/sync/tests/network_sync.rs Outdated Show resolved Hide resolved
p2p/src/net/default_backend/transport/impls/channel.rs Outdated Show resolved Hide resolved
p2p/src/net/default_backend/peer.rs Outdated Show resolved Hide resolved
Comment on lines 232 to +236
Action::Ref(call) => {
worker_tasks.spawn(async move {
let subsys = subsys.read().await;
call(&*subsys).await
});
}.in_current_span());
Copy link
Contributor

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?

Copy link
Contributor Author

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?

Copy link
Contributor

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"] }
Copy link
Collaborator

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.

@TheQuantumPhysicist TheQuantumPhysicist merged commit c8626b5 into master Sep 21, 2023
23 checks passed
@TheQuantumPhysicist TheQuantumPhysicist deleted the use_tracing branch September 21, 2023 11:50
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.

None yet

4 participants