How do I add X-Request-Start in HAProxy?
Asked Answered
K

2

6

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.

Koziara answered 24/6, 2015 at 20:56 Comment(0)
P
12

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.

Polycotyledon answered 27/4, 2018 at 10:31 Comment(2)
the link for 'See more details here' is not active. Google cache is also not present. Do you have any other link for the explanation?Forceps
From what I recall: %Ts timestamp is when the TCP connection is accepted, but HTTP (+ HTTP/2) requests can be pipelined or use keepalive. eg: Browser with a 10 second keepalive may only send a request after a few seconds, but the %Ts send to the backend will be the initial time of the connection was accepted, which is wrong.Polycotyledon
K
5

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

Koziara answered 24/6, 2015 at 20:56 Comment(1)
This is not the right solution, see https://mcmap.net/q/1607549/-how-do-i-add-x-request-start-in-haproxy for the details.Polycotyledon

© 2022 - 2024 — McMap. All rights reserved.