Skip to content

Use tracing for improved diagnostics #1533

Closed
@thomaseizinger

Description

Tracing: A scoped, structured logging and diagnostics system.

rust-libp2p is designed as an async, event-based system. This makes it fairly hard to add rich logs in user land because peer information is not always available. For example, the InboundUpgrade trait doesn't know, which peer it actually connected to.

It might be worth considering to add a dependency on the tracing crate and create Spans around the calls to these methods that set certain variables in the context.

A downstream crate that also uses tracing would then automatically pick those scopes up and messages printed to the log file would automatically include this context. For example, logging a message like: "Upgrading inbound substream to /foo/bar/1.0.0" would show up as:

Mar 31 15:38:36.158 INFO libp2p{peer_id=QmbhXbFML9JbBHr96eHKXWbc7t2fWCLdnh6aNbzFAoz2rw} app::network: Upgrading inbound substream to /foo/bar/1.0.0

In this example, libp2p is a tracing scope and peer_id is a variable inside that scope.

Scopes also have log levels. A "trace" level scope will not show up as part of an "info" message etc.

Note: tracing is maintained by the folks from tokio but works totally independent of the tokio runtime.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions