I would like to add a unique id to each request done through apache which will be used in the access log and is forwarded to underlying systems in a header to be used in their logs.
What is the best solution to accomplish this?
I would like to add a unique id to each request done through apache which will be used in the access log and is forwarded to underlying systems in a header to be used in their logs.
What is the best solution to accomplish this?
mod_unique_id will provide an environment variable UNIQUE_ID
with a unique identifier for each request.
You can add it to request headers with:
RequestHeader set uniqueid %{UNIQUE_ID}e
If you add that header to apache logs, for example:
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{uniqueid}i\"" combined
you willl get something like:
10.0.2.2 - - [01/Nov/2016:23:12:40 +0000] "GET /index.html HTTP/1.1" 404 208 "WBkhaJRMNmj7U9aiFl2pzQAAAAA"
It seems that the best answer provides a solution in which the related systems pick up the unique identifier from the header of the request. There are some more details about this here: Accessing Apache's unique_id from java code