How can I add a globally unique http header

Hi,
I am on a campaign to add application tracing to all our complex apps. I want to have a unique id across all incoming requests across all our data centers. All the incoming requests first hit a haproxy, so this is the best place to do this.

Here’s what I am thinking of…

  • Each haproxy has a 16 bit haproxy-id
  • There is a file that has the next block of numbers (48 bits) that this haproxy should use. When haproxy starts up, it reads the file and sets that in a pair of integers (low 32 bits and high 16 bits.)
  • Each request gets a header of X-tracer-tag: with the haproxy-id, high bytes and low bytes in hex, concatenated and the number gets incremented (implementation bumps first).
  • If the value was ffffffff, roll to 0 and increment the high bytes. (I doubt we will handle >48 bits of queries in the life of this software.)
  • When the when the low bytes get closes to the block top, a log entry is generated with the next block to use.
  • A separate process watches the log file and updates the input file

(note: While this is technically not thread safe, it is fine because the worst case is that we would skip a 4G number block when incrementing the high bytes. This is not worth doing any mutex hassle.)

I looked at lua and it could do most of what I want. I have a few questions:
How would I have a global variable that is available to a routine that every connection calls?
How do I set the haproxy id so that lua can access it?
How do I read the file with the current 6 bytes to seed the ID on start?

thanks in advance,
jerry