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

Add child logger & remove method names from log messages #412

Merged
merged 3 commits into from
Apr 1, 2024

Conversation

ian-shim
Copy link
Contributor

@ian-shim ian-shim commented Mar 29, 2024

Why are these changes needed?

Refactoring loggers across codebase.

  • Adds child loggers with component attribute for better filtering
  • Removes method names from log messages as they're already logged as part of source attribute

Checks

  • I've made sure the lint is passing in this PR.
  • I've made sure the tests are passing. Note that there might be a few flaky tests, in that case, please comment that they are not relevant.
  • Testing Strategy
    • Unit tests
    • Integration tests
    • This PR is not tested :(

Copy link
Contributor

@pschork pschork left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feel free to ignore the nits. When I see tip I think gas tip (ie priority fee), but maybe thats just me ¯_(ツ)_/¯

break
} else {
return receipt, nil
}
} else {
c.Logger.Debug("EnsureTransactionEvaled: failed to get chain tip while waiting for transaction to mine", "err", err)
c.Logger.Debug("failed to get chain tip while waiting for transaction to mine", "err", err)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: failed to query block height

@@ -261,7 +261,7 @@ func (t *txnManager) monitorTransaction(ctx context.Context, req *TxnRequest) (*
}
txID, err := t.wallet.SendTransaction(ctx, newTx)
if err != nil {
t.logger.Error("failed to send txn", "component", "TxnManager", "method", "monitorTransaction", "tag", req.Tag, "txn", req.Tx.Hash().Hex(), "attempt", retryFromFailure, "maxRetry", maxSpeedUpRetry, "err", err)
t.logger.Warn("failed to send txn", "component", "TxnManager", "method", "monitorTransaction", "tag", req.Tag, "txn", req.Tx.Hash().Hex(), "attempt", retryFromFailure, "maxRetry", maxSpeedUpRetry, "err", err)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe log Warn("failed to send txn - retrying" when retrying and Error("failed to send txn - retries exhaused" when we give up.

@@ -265,13 +266,13 @@ func (c *EthClient) waitMined(ctx context.Context, txs []*types.Transaction) (*t
chainTip, err := c.BlockNumber(ctx)
if err == nil {
if receipt.BlockNumber.Uint64()+uint64(c.numConfirmations) > chainTip {
c.Logger.Debug("EnsureTransactionEvaled: transaction has been mined but don't have enough confirmations at current chain tip", "txnBlockNumber", receipt.BlockNumber.Uint64(), "numConfirmations", c.numConfirmations, "chainTip", chainTip)
c.Logger.Debug("transaction has been mined but don't have enough confirmations at current chain tip", "txnBlockNumber", receipt.BlockNumber.Uint64(), "numConfirmations", c.numConfirmations, "chainTip", chainTip)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: don't -> doesn't and tip -> head

@ian-shim ian-shim marked this pull request as ready for review March 29, 2024 20:45
@@ -44,7 +44,7 @@ func NewMetrics(httpPort string, logger logging.Logger) *Metrics {
},
),
httpPort: httpPort,
logger: logger,
logger: logger.With("component", "retriever.Metrics"),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Should we standarize on camel case? So this should be "RetrieverMetrics"?

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 standardized it to the struct name and prefixed by the <package_name>. when the struct name is vague.
I guess it's cleaner to just camel case it

@@ -39,7 +39,7 @@ func NewServer(
churner: churner,
latestExpiry: int64(0),
lastRequestTimeByOperatorID: make(map[core.OperatorID]time.Time),
logger: logger,
logger: logger.With("component", "churner.Server"),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment for everything that has a "." in the name

@@ -41,10 +41,11 @@ var _ common.EthClient = (*EthClient)(nil)
// NewClient creates a new Ethereum client.
// If PrivateKeyString in the config is empty, the client will not be able to send transactions, and it will use the senderAddress to create transactions.
// If PrivateKeyString in the config is not empty, the client will be able to send transactions, and the senderAddress is ignored.
func NewClient(config EthClientConfig, senderAddress gethcommon.Address, rpcIndex int, logger logging.Logger) (*EthClient, error) {
func NewClient(config EthClientConfig, senderAddress gethcommon.Address, rpcIndex int, _logger logging.Logger) (*EthClient, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why adding a new naming convention with underscore prefix? May keep is simple and consistent with others

@ian-shim ian-shim merged commit a64df51 into Layr-Labs:master Apr 1, 2024
5 checks passed
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.

4 participants