-
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
Add correlation Ids #25
Conversation
…romContext from api-server
logging/correlation.go
Outdated
|
||
if correlationID != "" { | ||
ctx = context.WithValue(ctx, CorrelationIDName, correlationID) | ||
c.Writer.Header().Set("X-Correlation-Id", 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.
Why are we re-writing X-Correlation-Id
, if to enter this code branch we depend on that very value?
Also, please extract X-Correlation-Id
as a constant.
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 issue suggests to take an optional external correlation id and add it to the context. Here we check for the external id from request and adding it to context if its not nil.
@@ -16,6 +17,9 @@ func LogRequest(logger *zap.Logger) gin.HandlerFunc { | |||
} | |||
|
|||
func log(c *gin.Context) { | |||
|
|||
c.Next() |
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.
Why did you move c.Next()
at the beginning of the function?
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.
Even incase of an error, the "status" field in log info says 200. This is because we are setting this before we execute the endpoint logic function. So moved c.Next() to the first line so that the we get the correct status after the endpoint logic function is executed.
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.
@gsora
You can view in the image attached here
If the logging middleware is not executed last, it cannot pick any errors that have happened in the meantime.
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.
maybe start := time.Now()
should be above c.Next()
though
Fixes part of EmerisHQ/demeris-backend#346