Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I add X-Request-Start in HAProxy?

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.

like image 952
chendo Avatar asked Jun 24 '15 20:06

chendo


2 Answers

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()]

Note: The newrelic agents can automatically handle timestamps values sent using seconds, milliseconds, or as microseconds.

like image 139
Firefishy Avatar answered Oct 05 '22 23:10

Firefishy


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

like image 23
chendo Avatar answered Oct 05 '22 23:10

chendo