-
Notifications
You must be signed in to change notification settings - Fork 0
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 #20
Conversation
If you have not seen it, @gsora has left a relevant comment in the issue. Please replace the existing generated error id to be the |
Yup! Added that in the |
1b451c7
to
3197f33
Compare
…-api-server into prathyusha/correlation
@SpideyPool192 I do not think that this merge automatically created a release This needs to be reviewed and merged today if possible |
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.
Hi, can you write in short why you're panicking in the router instead of writing the error to log (even to the response maybe).
Also please shortly explain the logic behind the panic in deps.go
api/router/router.go
Outdated
if err != nil && r.l == nil { | ||
panic("cant get logger from context") | ||
} | ||
r.l = l |
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.
is this safe to do? When multiple API calls arrive aren't them executed concurrently and sharing the same router object?
even it this was safe looks like an anti-pattern to me: request-related stuff should stay inside request's context. What's this r.l used for anyway?
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.
We set a modified logger to the context in the CorrelationIDMiddleware
function. Intention is to use this logger everywhere. As the api server uses the logger from router, I'm changing the router logger (r.l) to use the logger from context.
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.
We set a modified logger to the context in the CorrelationIDMiddleware function. Intention is to use this logger everywhere.
that's ok
As the api server uses the logger from router, I'm changing the router logger (r.l) to use the logger from context.
I don't get why we need a router logger (+ I'm still concerned about concurrency safety)
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.
…rathyusha/correlation
The issue suggests that we use a logger from the context if it doesn't exist check if there is another logger (to the router) provided. If there is no logger found we panic. In deps.go we are trying to replace the error id with the internal correlation id which we created earlier. Hence, we try to find it in the context and panic if not found. |
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.
LGTM!
Fixes EmerisHQ/demeris-backend#346