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

Duplicate Request ID if Use middleware several times #825

Open
mason-liu opened this issue Jun 8, 2023 · 3 comments
Open

Duplicate Request ID if Use middleware several times #825

mason-liu opened this issue Jun 8, 2023 · 3 comments

Comments

@mason-liu
Copy link

If the request id middleware is called several times for one request, each time it will generate new request id.
I have this issue because httplog.RequestLogger enables request id middleware by default and no way to remove.
The expected result is, request id should only be generated once for each request even it is called several times, 2 ways I think:

  1. https://github.com/go-chi/chi/blob/master/middleware/request_id.go#L70 request ID should get from context instead of request header
  2. Once generate new request ID, should add it to request header
@pkieltyka
Copy link
Member

so you're using httplog.RequestLogger in addition adding middleware.RequestID separately..?

@dropwhile
Copy link

dropwhile commented Dec 8, 2023

@mason-liu you can use the httplog.Handler as a middleware instead of httplog.RequestLogger, if you are already using the RequestID and Recoverer middlewares:
https://github.com/go-chi/httplog/blob/a414fec0944146d5f63a935c9ad45975f2c09ce7/httplog.go#L57

@VojtechVitek
Copy link
Contributor

Please have a look at https://github.com/go-chi/traceid. It's an alternative to middleware.RequestID, which handles multiple uses well and also adds service-to-service tracing capabilities.

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

No branches or pull requests

4 participants