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 filter to track request ID #553

Merged
merged 1 commit into from
May 5, 2024

Conversation

nscuro
Copy link
Collaborator

@nscuro nscuro commented Apr 20, 2024

This adds a new filter that accepts a X-Request-Id header (or alternatively generates a random UUID) for each request, and adds it to SLF4J's MDC. Being part of the MDC allows it to be included in application and audit logs.

The request ID is also included in every response, in the form of an X-Request-ID header.

This behavior allows for easier correlation of operations in the system. Accepting provided request IDs enables correlation even across system boundaries.

Many API gateways, service meshes, and reverse proxies transparently set the X-Request-Id header. Among them Enovy (https://www.envoyproxy.io/docs/envoy/latest/configuration/http/http_conn_man/headers#x-request-id), Apache APISIX (https://apisix.apache.org/docs/apisix/next/plugins/request-id/), and Heroku (https://devcenter.heroku.com/articles/http-request-id).

This adds a new filter that accepts a `X-Request-Id` header (or alternatively generates a random UUID) for each request, and adds it to SLF4J's `MDC`. Being part of the `MDC` allows it to be included in application and audit logs.

The request ID is also included in every response, in the form of an `X-Request-ID` header.

This behavior allows for easier correlation of operations in the system. Accepting provided request IDs enables correlation even across system boundaries.

Many API gateways, service meshes, and reverse proxies transparently set the `X-Request-Id` header. Among them Enovy (https://www.envoyproxy.io/docs/envoy/latest/configuration/http/http_conn_man/headers#x-request-id), Apache APISIX (https://apisix.apache.org/docs/apisix/next/plugins/request-id/), and Heroku (https://devcenter.heroku.com/articles/http-request-id).

Signed-off-by: nscuro <[email protected]>
@nscuro nscuro force-pushed the request-id-filter branch from b1c24d4 to 0f7c17c Compare April 21, 2024 09:23
@stevespringett stevespringett merged commit 7b725ec into stevespringett:master May 5, 2024
2 checks passed
@nscuro nscuro deleted the request-id-filter branch May 6, 2024 12:08
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.

2 participants