-
Notifications
You must be signed in to change notification settings - Fork 790
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
Tracing #4412
Tracing #4412
Conversation
fe73f62
to
d0bdc6b
Compare
ee85b5d
to
b994921
Compare
b994921
to
3805e36
Compare
nano/node/transport/channel.cpp
Outdated
node.logger.trace (nano::log::type::channel_sent, nano::to_log_detail (message_a.type ()), | ||
nano::log::arg{ "message", message_a }, | ||
nano::log::arg{ "channel", *this }, | ||
nano::log::arg{ "dropped", false }); |
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.
To achieve more compression of data, we could remove the dropped field when it is set to false.
So, a missing dropped would mean that the message was not dropped.
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.
Some tools that automatically detect data format (eg. Apache Drill, but likely others too) might have problems with format that is inconsistent. I believe in case of Drill it infers schema from first ~60k entries. Looking at this now, this function flow should be refactored, so that it has a single point at which data is logged.
The goal of this PR is to introduce a framework for tracing events in the node. This is meant to be used for debugging and profiling purposes, eg. by visualizing the flow of votes through the network or analyzing the delay between receiving a block and confirming it.
This is accomplished by introducing a
nano::object_stream
class that can be used to serialize objects. It is meant to be a relatively thin wrapper around the underlying stream, that ensures the output format is structured and consistent. It avoids allocations and unnecessary run-time dispatching by using a compile-time visitor pattern.This interface also allows to switch between different output formats and automatically handles some common functionality, like providing
operator<<
,to_string()
andto_json()
. If in the future a better serialization library is found, it should be possible to easily replace the underlying implementation without changing the interface.Usage
To use tracing, it must be enabled at compile time by passing
-DNANO_TRACING=ON
flag to CMake. By default, it is disabled for release builds and enabled for debug builds.After that, tracing can be enabled by setting the logging verbosity level to
trace
. (NANO_LOG=trace
)Since the amount of logs when setting logging level to
trace
is very large, it is recommended to usetrace
level only for specific components. This can be done by settingNANO_LOG_LEVELS
environment variable to a comma-separated list of components to trace. For example, to trace onlyactive_transactions
andvote_processor
, setNANO_LOG_LEVELS="active_transactions=trace,vote_processor=trace"
. Alternatively this can also be done by modifying theconfig-log.toml
file.Tracing Formats
It is possible to specify format of tracing output at runtime. This is done by setting
NANO_TRACE_FORMAT
environment variable to one of the following:standard
orjson
.Standard
Standard tracing format is enabled by default. It is a simple
key: { value }
format with indentation that should be easy to read.Sample output:
JSON
JSON tracing format is meant to be parsed by external tools. There is no indentation or newlines, so each log output line can be treated as a separate event, which simplifies parsing.
Sample output: