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

Add correlation Ids #25

Merged
merged 6 commits into from
Feb 8, 2022
Merged

Add correlation Ids #25

merged 6 commits into from
Feb 8, 2022

Conversation

0xmuralik
Copy link
Contributor


if correlationID != "" {
ctx = context.WithValue(ctx, CorrelationIDName, correlationID)
c.Writer.Header().Set("X-Correlation-Id", correlationID)
Copy link
Contributor

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.

Copy link
Contributor Author

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.

logging/rest.go Outdated Show resolved Hide resolved
logging/rest.go Show resolved Hide resolved
@@ -16,6 +17,9 @@ func LogRequest(logger *zap.Logger) gin.HandlerFunc {
}

func log(c *gin.Context) {

c.Next()
Copy link
Contributor

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?

Copy link
Contributor Author

@0xmuralik 0xmuralik Feb 2, 2022

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.

Copy link
Contributor

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.

Copy link
Contributor

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

@0xmuralik 0xmuralik requested a review from gsora February 3, 2022 05:01
logging/correlation.go Outdated Show resolved Hide resolved
logging/correlation.go Show resolved Hide resolved
@0xmuralik 0xmuralik requested a review from Pitasi February 3, 2022 10:38
logging/correlation.go Show resolved Hide resolved
logging/rest.go Outdated Show resolved Hide resolved
@0xmuralik 0xmuralik requested a review from gsora February 7, 2022 09:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants