Add tracking IDs to your web application

With a complex multi-tier stack with HTTP requests getting proxied it can be difficult to track a request as it goes around the system.

One thing you can do is enable mod_unique_id in apache – this creates a distinct environment variable UNIQUE_ID in the web server context for each incoming request. Simply loading the module enables it.

You can then add this via header to downstream systems (eg application servers such as php-fpm or python flask uwsgi) and return upstream so you can view it with browser DevTools with the following config:

RequestHeader set my_id %{UNIQUE_ID}e
Header set my_id %{UNIQUE_ID}e

Furthermore you can add it to your webserver logs:

LogFormat "%a %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %D %{UNIQUE_ID}e" combinedtime
CustomLog logs/access_log combinedtime

You can do similar in nginx with $request_id.

For a far more in-depth approach to this, look at Open Tracing.

Leave a Reply

Your email address will not be published. Required fields are marked *