request-id
Adds a unique request ID header to requests and responses.
request-idPriority 12015What it does
request-id gives every request through the route an ID and writes it into the header named under Header name, X-Request-Id unless you change it. The backend receives the header, and with Include in response on, the client finds it on the answer too.
Algorithm picks how the ID is made, uuid unless you change it. Range ID and its two settings are read only when the algorithm is range_id, and the form draws them only then.
When to use it
- A client of the orders API reports a failed call, and support finds the request in the backend's log by the ID on the answer the client got.
- A backend that sorts its records by time and wants IDs that sort the same way, made with
uuidv7. - A short ID that fits a log column or a support ticket, made of hexadecimal characters with a set length.
- A backend that already reads a correlation header under a name of its own, written under Header name.
Not for a header with a fixed value of your own on every request — see proxy-rewrite (Rewrites the request URI, method, host and headers before proxying) or tracing one request across several services with spans — see zipkin (Sends traces to a Zipkin collector).
Set it up
Give every request a short hexadecimal id
Leave Header name at X-Request-Id, set Algorithm to range_id and fill Range ID as in the JSON below.
{
"header_name": "X-Request-Id",
"algorithm": "range_id",
"range_id": {
"char_set": "0123456789abcdef",
"length": 12
}
}
Things to know
- Include in response — Left on, the answer carries the header: with
X-Request-Idas the name, a request to the route is answered200with anX-Request-Idheader. - Header name — A name with a space,
X Request Id, is refused when you save. - Header name — A name made only of the characters this field takes can still be one the response already owns: Content-Length is stored without complaint and then fails every request through this object with 500.
- Char set — A set of fewer than six characters,
abcfor example, is refused when you save. - Char set — Every character ends up in a header: a newline arrives as %0A, and a non-ASCII character is split into bytes, so the id is not what the alphabet spells.
- Length — A length below six,
5for example, is refused when you save. - Length — The id travels in a request header and a response header, so a very long one is refused by the upstream's own header limit rather than by the gateway.
- Length — With
range_id, a character set of hexadecimal digits and a length of 12, every answer carries anX-Request-Idof twelve hex characters. - AdviceKeep one header name across the routes of an environment, so the backends and the support team look for the ID in one place. A global rule carries one copy for every route; Where a plugin runs shows how it meets a route's own.
Settings
The fields as the console shows them, section by section. A field under “When … is …” is there only while that value is set.
header_namestringdefault X-Request-IdThe header the ID is written to.
pattern
^([$]secret://.+|[$][Ee][Nn][Vv]://.+|[A-Za-z0-9!#$%&'*+.^`|~-]+)$include_in_responsebooleandefault trueAdds the header to the response as well as to the request.
algorithmstringdefault uuidHow the ID is made: a UUID, a time-ordered UUID, a KSUID, a NanoID or a range ID drawn from a character set.
When Algorithm is range_id
range_idobjectdefault {"char_set":"abcdefghijklmnopqrstuvwxyzABCDEFGHIGKLMNOPQRSTUVWXYZ0123456789","length":16}range_id.char_setstringdefault abcdefghijklmnopqrstuvwxyzABCDEFGHIGKLMNOPQRSTUVWXYZ0123456789range_id.lengthintegerdefault 16