-
Notifications
You must be signed in to change notification settings - Fork 89
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
Conversation
WalkthroughThe recent update enhances the system's logging capabilities by introducing a new feature that generates a 20-length random hexadecimal string to serve as a unique request ID. This cryptographic function-generated ID is then incorporated into the context to facilitate more precise and secure tracking of requests throughout the logging process. Additionally, a new constant Changes
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 1
Configuration used: CodeRabbit UI
Files selected for processing (2)
- protocol/lib/context.go (2 hunks)
- protocol/lib/log/constants.go (1 hunks)
Additional comments: 1
protocol/lib/log/constants.go (1)
- 37-37: The addition of
RequestId
constant is correctly implemented and follows the naming conventions. This change supports the logging of the newly generated request ID as intended.
// 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, | ||
) |
There was a problem hiding this comment.
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.
example logs, now with request logs: