Dan44
Apr 27, 2021Altostratus
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?