Skip to content

Commit

Permalink
add request_id to all code paths using lib.UnwrapSDKContext
Browse files Browse the repository at this point in the history
  • Loading branch information
jonfung-dydx committed Feb 8, 2024
1 parent 84d9d00 commit 6d0f776
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
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,
)
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

0 comments on commit 6d0f776

Please sign in to comment.