1

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?

guettli
  • 3,113
  • 14
  • 59
  • 110

2 Answers2

2

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).

Michael Hampton
  • 237,123
  • 42
  • 477
  • 940
-1

You might want to escape the value of %{UNIQUE_ID}e for the header. This article describes it as the first example: https://httpd.apache.org/docs/trunk/env.html#examples

#
# The following works around a client sending a broken Accept_Encoding
# header.
#
SetEnvIfNoCase ^Accept.Encoding$ ^(.*)$ fix_accept_encoding=$1
RequestHeader set Accept-Encoding %{fix_accept_encoding}e env=fix_accept_encoding
AlexN
  • 1