From ce119a1c3b3d0d7a3d7519b8e7d8528f2b5b3bcf Mon Sep 17 00:00:00 2001 From: Alex Gartner Date: Fri, 13 Sep 2024 10:18:45 -0700 Subject: [PATCH] chore(zetaclient): improve logging by adding and moving data to attributes --- .../chains/bitcoin/observer/observer.go | 28 ++++++++++++++----- zetaclient/chains/evm/observer/observer.go | 22 ++++++++++----- 2 files changed, 36 insertions(+), 14 deletions(-) diff --git a/zetaclient/chains/bitcoin/observer/observer.go b/zetaclient/chains/bitcoin/observer/observer.go index 4f3ad4ea28..6c6c489f52 100644 --- a/zetaclient/chains/bitcoin/observer/observer.go +++ b/zetaclient/chains/bitcoin/observer/observer.go @@ -240,26 +240,35 @@ func (ob *Observer) WatchRPCStatus(_ context.Context) error { bn, err := ob.btcClient.GetBlockCount() if err != nil { - ob.logger.Chain.Error().Err(err).Msg("RPC status check: RPC down? ") + ob.logger.Chain.Error().Err(err).Msg("RPC status check failed: GetBlockCount") continue } hash, err := ob.btcClient.GetBlockHash(bn) if err != nil { - ob.logger.Chain.Error().Err(err).Msg("RPC status check: RPC down? ") + ob.logger.Chain.Error().Err(err). + Int64("block_number", bn). + Msg("RPC status check failed: GetBlockHash") continue } header, err := ob.btcClient.GetBlockHeader(hash) if err != nil { - ob.logger.Chain.Error().Err(err).Msg("RPC status check: RPC down? ") + ob.logger.Chain.Error(). + Err(err). + Int64("block_number", bn). + Msg("RPC status check failed: GetBlockHeader") continue } blockTime := header.Timestamp - elapsedSeconds := time.Since(blockTime).Seconds() - if elapsedSeconds > 1200 { - ob.logger.Chain.Error().Err(err).Msg("RPC status check: RPC down? ") + blockAgeSeconds := time.Since(blockTime).Seconds() + if blockAgeSeconds > 1200 { + ob.logger.Chain.Error(). + Err(err). + Int64("block_number", bn). + Float64("block_age_seconds", blockAgeSeconds). + Msg("RPC status check failed: block is old") continue } @@ -280,7 +289,12 @@ func (ob *Observer) WatchRPCStatus(_ context.Context) error { } ob.logger.Chain.Info(). - Msgf("[OK] RPC status check: latest block number %d, timestamp %s (%.fs ago), tss addr %s, #utxos: %d", bn, blockTime, elapsedSeconds, tssAddr, len(res)) + Int64("block_number", bn). + Time("block_timestamp", blockTime). + Float64("block_age_seconds", blockAgeSeconds). + Str("tss_address", tssAddr.EncodeAddress()). + Int("utxo_count", len(res)). + Msg("RPC status OK") case <-ob.StopChannel(): return nil diff --git a/zetaclient/chains/evm/observer/observer.go b/zetaclient/chains/evm/observer/observer.go index 32952c28a2..a21b705f61 100644 --- a/zetaclient/chains/evm/observer/observer.go +++ b/zetaclient/chains/evm/observer/observer.go @@ -217,29 +217,37 @@ func (ob *Observer) WatchRPCStatus(ctx context.Context) error { } bn, err := ob.evmClient.BlockNumber(ctx) if err != nil { - ob.Logger().Chain.Error().Err(err).Msg("RPC Status Check error: RPC down?") + ob.Logger().Chain.Error().Err(err).Msg("RPC status check failed: BlockNumber") continue } gasPrice, err := ob.evmClient.SuggestGasPrice(ctx) if err != nil { - ob.Logger().Chain.Error().Err(err).Msg("RPC Status Check error: RPC down?") + ob.Logger().Chain.Error(). + Uint64("block_number", bn). + Err(err).Msg("RPC status check failed: SuggestGasPrice") continue } header, err := ob.evmClient.HeaderByNumber(ctx, new(big.Int).SetUint64(bn)) if err != nil { - ob.Logger().Chain.Error().Err(err).Msg("RPC Status Check error: RPC down?") + ob.Logger().Chain.Error(). + Uint64("block_number", bn). + Err(err).Msg("RPC status check failed: HeaderByNumber") continue } // #nosec G115 always in range blockTime := time.Unix(int64(header.Time), 0).UTC() - elapsedSeconds := time.Since(blockTime).Seconds() - if elapsedSeconds > 100 { + blockAgeSeconds := time.Since(blockTime).Seconds() + if blockAgeSeconds > 100 { ob.Logger().Chain.Warn(). - Msgf("RPC Status Check warning: RPC stale or chain stuck (check explorer)? Latest block %d timestamp is %.0fs ago", bn, elapsedSeconds) + Msgf("RPC status check warning: RPC stale or chain stuck (check explorer)? Latest block %d timestamp is %.0fs ago", bn, blockAgeSeconds) continue } ob.Logger().Chain.Info(). - Msgf("[OK] RPC status: latest block num %d, timestamp %s ( %.0fs ago), suggested gas price %d", header.Number, blockTime.String(), elapsedSeconds, gasPrice.Uint64()) + Uint64("block_number", header.Number.Uint64()). + Time("block_timestamp", blockTime). + Float64("block_age_seconds", blockAgeSeconds). + Uint64("suggested_gas_price", gasPrice.Uint64()). + Msg("RPC status OK") case <-ob.StopChannel(): return nil }