CustomRequestId plugin

Updated at:

Sidecars and gateways use the x-request-id header to uniquely identify requests. For all requests from outside the cluster, sidecars and gateways automatically generate an x-request-id header. If a request already has this header, the sidecar or gateway overwrites its original value by default. For requests within the cluster that do not have this header, gateways and sidecars also automatically generate one.

Prerequisites

Configuration fields

You can configure the following aspects of the CustomRequestId plugin:

  • Whether to automatically generate an x-request-id header.

  • Whether to preserve an existing x-request-id header in external requests.

  • Whether to set the x-request-id in the response header.

Parameter

Type

Required

Default

Description

generate_request_id

string

Valid values: "true" and "false"

Optional

"true"

Specifies whether to automatically generate the x-request-id header.

preserve_external_request_id

string

Valid values: "true" and "false"

Optional

"true"

Specifies whether to preserve an existing x-request-id header from an external request.

always_set_request_id_in_response

string

Valid values: "true" and "false"

Optional

"true"

Specifies whether to set the x-request-id in the response header.

Examples

Return x-request-id in the response header

Go to the plugin configuration tab and enable the CustomRequestId plugin. Set the plugin effective scope to Gateway Scope. Then, click Add ASM Gateway to effective scope and select the target gateway. Use the following configuration:

generate_request_id: 'true'
preserve_external_request_id: 'false'
always_set_request_id_in_response: 'true'

Run the following command to view the response header:

curl <ASM gateway IP>/get -I

Expected output:

HTTP/1.1 200 OK
server: istio-envoy
date: Thu, xx xxx 202x 0x:3x:3x GMT
content-type: application/json
content-length: 524
access-control-allow-origin: *
access-control-allow-credentials: true
x-envoy-upstream-service-time: 1
x-request-id: 9ba63dbf-91eb-458a-adb4-61xxxxxxxx

You can use this ID to troubleshoot abnormal requests.

Disable automatic x-request-id generation

Change the plugin configuration to the following:

generate_request_id: 'false'
preserve_external_request_id: 'false'
always_set_request_id_in_response: 'true'

Run the following command to view the response header:

curl <ASM gateway IP>/get -I

Expected output:

HTTP/1.1 200 OK
server: istio-envoy
date: Thu, xx xxx 202x 0x:3x:3x GMT
content-type: application/json
content-length: 524
access-control-allow-origin: *
access-control-allow-credentials: true
x-envoy-upstream-service-time: 1

The gateway no longer automatically generates an x-request-id header for the request.

Preserve the external x-request-id

Change the plugin configuration to the following:

generate_request_id: 'true'
preserve_external_request_id: 'true'
always_set_request_id_in_response: 'true'

Run the following command to view the response header:

curl <ASM gateway IP>/get -I -H "x-request-id:test"

Expected output:

HTTP/1.1 200 OK
server: istio-envoy
date: Thu, xx xxx 202x 0x:3x:3x GMT
content-type: application/json
content-length: 524
access-control-allow-origin: *
access-control-allow-credentials: true
x-envoy-upstream-service-time: 1
x-request-id: test

The gateway preserves the x-request-id from the external request instead of generating a new one.