I like X-Request-ID:

The Heroku router generates a unique request ID for every incoming HTTP request that it receives. This unique ID is then passed to your application as an HTTP header called X-Request-ID.

From https://devcenter.heroku.com/articles/http-request-id

How can I configure Apache to provide X-Request-ID which is different, even if a multi-threaded MPM gets used?


You need to do two things:

  1. Load the unique_id_module. This provides the UNIQUE_ID environment variable which serves this purpose.

    LoadModule mod_unique_id.c
  2. Copy the UNIQUE_ID into the X-Request-ID header in the appropriate virtual host using the RequestHeader directive.

    RequestHeader setifempty X-Request-ID %{UNIQUE_ID}e
    ProxyPass ...
    ProxyPassReverse ...

Optionally, you can also put %{UNIQUE_ID}e into a custom log format so that you can log it from Apache (possibly in addition to within your application).

| improve this answer | |
  • Since "X-Request-ID" seems the more common name, I will add this to the log format, and not "UNIQUE_ID". Do you agree? – guettli Aug 18 '16 at 9:21
  • @guettli Do you want the actual unique ID logged, or the literal string "X-Request-ID"? – Michael Hampton Aug 18 '16 at 9:26
  • I want the contents of the variable: the unique id, not the literal string. I would like to have a set up which is like on Heroku: devcenter.heroku.com/articles/http-request-id – guettli Aug 25 '16 at 10:43
  • @guettli Then you should do what I advised. – Michael Hampton Aug 25 '16 at 20:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.