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

[feature] Add request_id to all code paths using lib.UnwrapSDKContext #1058

Merged
merged 1 commit into from
Feb 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions protocol/lib/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package lib

import (
"context"
"crypto/rand"
"encoding/hex"
"fmt"

"github.com/cometbft/cometbft/crypto/tmhash"
Expand Down Expand Up @@ -31,5 +33,16 @@ func UnwrapSDKContext(
fmt.Sprintf("x/%s", moduleName),
)
}
// Generate a 20-length random hex string for request id.
bytes := make([]byte, 10)
_, err := rand.Read(bytes)
if err != nil {
return ctx
}
requestId := hex.EncodeToString(bytes)
ctx = log.AddPersistentTagsToLogger(
ctx,
log.RequestId, requestId,
)
Comment on lines +36 to +46
Copy link
Contributor

Choose a reason for hiding this comment

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

The error handling for rand.Read is insufficient. In case of an error, it silently fails and returns the original context without the request ID. Consider logging the error or handling it more gracefully to ensure that failures in generating the request ID do not go unnoticed.

return ctx
}
1 change: 1 addition & 0 deletions protocol/lib/log/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const (
Reason = "reason"
RemovalStatus = "removal_status"
TotalFilled = "total_filled"
RequestId = "request_id"

OrderSizeOptimisticallyFilledFromMatchingQuantums = "order_size_optimistically_filled_from_matching_quantums"
NewLocalValidatorOperationsQueue = "new_local_validator_operations_queue"
Expand Down
Loading