forest icon indicating copy to clipboard operation
forest copied to clipboard

use `tracing`'s structured logging

Open aatifsyed opened this issue 1 year ago • 0 comments

Before: https://github.com/ChainSafe/forest/blob/9e3ed095a32d14a293ce7ed7b52b48d74d3b67b3/src/chain/store/chain_store.rs#L221 After:

info!(epoch = %ts.epoch(), key = %ts.key(), "new heaviest tipset");

Before: https://github.com/ChainSafe/forest/blob/9e3ed095a32d14a293ce7ed7b52b48d74d3b67b3/src/rpc/channel.rs#L360 After:

tracing::error!(?e, "Failed to serialize channel message");

Plan

  • refactor all tracing callsites
    • Could this be automated with synsert?
  • educate team on
    • std::error::Error and anyhow::Error's design
    • (structured) logging principles
      • Each info string or above should be unique and descriptive
      • Fields should be structured so that we can run metrics on them
      • Logging vs end-user messages
  • [hard] write CI

Motivation

Either... or all error messages should use the ?e or a variant of that. If we do the latter, it should be enforced in CI.

Originally posted by @LesnyRumcajs in https://github.com/ChainSafe/forest/issues/4128#issuecomment-2036753097

aatifsyed avatar Apr 04 '24 12:04 aatifsyed