We'd like to track request queue times, and as per https://docs.newrelic.com/docs/apm/other-features/request-queueing/configuring-request-queue-reporting, we need to add X-Request-Start
or X-Queue-Start
with the timestamp in milliseconds.
How do I add X-Request-Start in HAProxy?
2k views Asked by chendo At
2
There are 2 answers
2
On
Using %Ts
is NOT the correct solution as it is the start time of the session (stream) and not the request time. Multiple requests will use the same %Ts
time. See more details here
The correct solution for haproxy version <1.9 is to use the following in the frontend
block. Unfortunately it only has seconds resolution.
http-request set-header X-Request-Start t=%[date()]
If you are using haproxy version >=1.9 there is a new sample fetch method date_us() which can be used to get microseconds resolution.
http-request set-header X-Request-Start t=%[date()]%[date_us()]
The solution is to add this line in your
frontend
block. You'll need one for HTTP and HTTPS.http-request set-header X-Request-Start t=%Ts%ms