27-Apr-2021
06:23
- last edited on
04-Jun-2023
20:56
by
JimmyPackets
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?
27-Apr-2021
10:57
- last edited on
22-Nov-2022
15:35
by
JimmyPackets
Dan44,
I'm not sure about generating the unique ID, I'd look at this article https://devcentral.f5.com/s/articles/random-string-generators or keep it simple and generate an id like Kai Wilke suggested in https://devcentral.f5.com/s/question/0D51T00006i7W29/how-random-is-rand
set uniqueID [TMM::cmp_unit][clock clicks]
Your code also allows a client to supply the header X-Request-ID, is this intended behaviour?
Rob
28-Apr-2021 00:25
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.
29-Apr-2021 12:16
if that is the case you should remove the HTTP_RESPONSE part