-
Notifications
You must be signed in to change notification settings - Fork 1
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
feat: add function to add Correlation IDs to logger #37
Conversation
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.
Approving to unblock, left an open q
logging/correlation.go
Outdated
|
||
correlationID, ok := ctx.Value(CorrelationIDName).(string) | ||
if ok && len(correlationID) > 0 { | ||
l = l.With(string(CorrelationIDName), correlationID) |
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.
Will this result in a constant GC overhead?
First instance created by With()
is not used and is subject to GC.
The above happening for 1000s of requests.
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.
Are you saying we can combine the two With()s of this function? Probably yes, I can do it.
Also please do note that this is not a middleware so it's not called for each request, atm it will only be called by api-server in case of panics. I hope we won't have 1000s of panics 😂
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.
I avoided the intermediary logger and added unit tests. It should be fine now 😄
3b764dd
to
1158d92
Compare
1158d92
to
f1b20a6
Compare
This function helps in preparing a new logger with correlation ID taken from http request context.