Showing results for 
Search instead for 
Did you mean: 
Login & Join the DevCentral Connects Group to watch the Recorded LiveStream (May 12) on Basic iControl Security - show notes included.

Generate a unique ID with the help of an iRule


Hello everyone


I would like to generate a unique ID with the help of an iRule and place it in a header. The goal is to identify the HTTP request by the ID. Has anyone done something like this before?


What I have tried:

when HTTP_REQUEST priority 3 { ###Generate URL Tracing for { set i 0 } {$i < 8 } { incr i } { append rand_hex [format {%x} [expr {int(rand()*16)}]] } #log local0. "X-Request-ID: $rand_hex" ###Add X-Request-ID Header if {not([HTTP::header exists X-Request-ID ])}{ HTTP::header insert X-Request-ID $rand_hex     } } when HTTP_RESPONSE priority 3 {   HTTP::header insert X-Request-ID $rand_hex }


The problem is that I sometimes see multiple requests with the same ID. Does anyone have a better idea how to solve it?









I'm not sure about generating the unique ID, I'd look at this article or keep it simple and generate an id like Kai Wilke suggested in


set uniqueID [TMM::cmp_unit][clock clicks]

Your code also allows a client to supply the header X-Request-ID, is this intended behaviour?





Hi Rob

Thanks for your reply, the links look interesting. I will have a look at them and test the examples.


Regarding your question. It is actually planned that only F5 LTM does the header insert and not the client.

if that is the case you should remove the HTTP_RESPONSE part