Can HAProxy generate a UUID based unique connection id?

I have an HAProxy load balancer that I would like to use to tag requests with a unique id (X-Unique-ID header) so that I can correlate events between logs in multiple systems.

HAProxy has a feature for doing this with the unique-id-format directive. The documentation explains that this uses only the syntax from the logging system and goes on to suggest that you use things like the client and server ip addresses, timestamps, etc to build something that is likely to be unique.

I am wondering if it is possible to generate a random (version 4) UUID (or something similar) for each request rather than generating one with potentially sensitive client information like IP address and request time.


Starting from HAProxy 2.0 uuid() function is available.
So this should do exactly what you need:

unique-id-format %[uuid()]
unique-id-header X-Unique-ID

One advantage to using unique-id-header instead of http-request set-header, is that you can set it in defaults section.