Correlate requests and responses using a unique ID transmitted over an HTTP header.
Configuration Reference
This plugin is not compatible with DB-less mode.
Enable the plugin on a service
Admin API
Kubernetes
Declarative (YAML)
Konnect Cloud
Kong Manager
For example, configure this plugin on a service by
making the following request:
curl -X POST http://{HOST}:8001/services/{SERVICE}/plugins \
--data "name=correlation-id" \
--data "config.header_name=Kong-Request-ID" \
--data "config.generator=uuid#counter" \
--data "config.echo_downstream=false"
SERVICE
is the id
or name
of the service that this plugin
configuration will target.
First, create a KongPlugin
resource:
apiVersion: configuration.konghq.com/v1
kind: KongPlugin
metadata:
name: <correlation-id-example>
config:
header_name: Kong-Request-ID
generator: uuid#counter
echo_downstream: false
plugin: correlation-id
Next, apply the KongPlugin resource to a
Service by annotating the
Service as follows:
apiVersion: v1
kind: Service
metadata:
name: {SERVICE}
labels:
app: {SERVICE}
annotations:
konghq.com/plugins: <correlation-id-example>
spec:
ports:
- port: 80
targetPort: 80
protocol: TCP
name: {SERVICE}
selector:
app: {SERVICE}
{SERVICE}
is the id
or name
of the service that this plugin
configuration will target.
Note: The KongPlugin resource only needs to be defined once
and can be applied to any service, consumer, or route in the namespace. If you
want the plugin to be available cluster-wide, create the resource as a
KongClusterPlugin
instead of KongPlugin
.
For example, configure this plugin on a service by
adding this section to your declarative configuration file:
plugins:
- name: correlation-id
service: {SERVICE}
config:
header_name: Kong-Request-ID
generator: uuid#counter
echo_downstream: false
SERVICE
is the id
or name
of the service that this plugin
configuration will target.
Configure this plugin on a service:
- In Konnect Cloud, select the service on the ServiceHub page.
- Scroll down to Versions and select the version.
- Scroll down to Plugins and click New Plugin.
- Find and select the Correlation ID plugin.
- Click Create.
Configure this plugin on a service:
- In Kong Manager, select the workspace.
- From the Dashboard, scroll down to Services and click View for the
service row.
- Scroll down to plugins and click Add Plugin.
-
Find and select the Correlation ID plugin.
Note: If the plugin is greyed out, then it is not available
for your product tier. See
Kong Gateway tiers.
- If the option is available, select Scoped.
- Add the service name and ID to the Service field if it
is not already prefilled.
- Click Create.
Enable the plugin on a route
Admin API
Kubernetes
Declarative (YAML)
Konnect Cloud
Kong Manager
For example, configure this plugin on a route with:
$ curl -X POST http://{HOST}:8001/routes/{ROUTE}/plugins \
--data "name=correlation-id" \
--data "config.header_name=Kong-Request-ID" \
--data "config.generator=uuid#counter" \
--data "config.echo_downstream=false"
ROUTE
is the id
or name
of the route that this plugin configuration
will target.
First, create a KongPlugin
resource:
apiVersion: configuration.konghq.com/v1
kind: KongPlugin
metadata:
name: <correlation-id-example>
config:
header_name: Kong-Request-ID
generator: uuid#counter
echo_downstream: false
plugin: correlation-id
Then, apply it to an ingress (Route or Routes)
by annotating the ingress as follows:
apiVersion: networking/v1beta1
kind: Ingress
metadata:
name: {ROUTE}
annotations:
kubernetes.io/ingress.class: kong
konghq.com/plugins: <correlation-id-example>
spec:
rules:
- host: examplehostname.com
http:
paths:
- path: /bar
backend:
serviceName: echo
servicePort: 80
ROUTE
is the id
or name
of the route that this plugin configuration
will target.
Note: The KongPlugin resource only needs to be defined once
and can be applied to any service, consumer, or route in the namespace. If you
want the plugin to be available cluster-wide, create the resource as a
KongClusterPlugin
instead of KongPlugin
.
For example, configure this plugin on a route by
adding this section to your declarative configuration file:
plugins:
- name: correlation-id
route: <route>
config:
header_name: Kong-Request-ID
generator: uuid#counter
echo_downstream: false
ROUTE
is the id
or name
of the route that this plugin configuration
will target.
Configure this plugin on a route:
- In Konnect Cloud, select the service from the ServiceHub page.
- Scroll down to Versions and select the version.
- Select the route.
- Scroll down to Plugins and click Add Plugin.
- Find and select the Correlation ID plugin.
- Click Create.
Configure this plugin on a route:
- In Kong Manager, select the workspace.
- From the Dashboard, select Routes in the left navigation.
- Click View for the route row.
- Scroll down to plugins and click Add Plugin.
-
Find and select the Correlation ID plugin.
Note: If the plugin is greyed out, then it is not available
for your product tier. See
Kong Gateway tiers.
- If the option is available, select Scoped.
- Add the Route ID if it is not already prefilled.
- Click Create.
Enabling the plugin on a consumer
Admin API
Kubernetes
Declarative (YAML)
Kong Manager
For example, configure this plugin on a consumer with:
$ curl -X POST http://{HOST}:8001/consumers/{CONSUMER}/plugins \
--data "name=correlation-id" \
--data "config.header_name=Kong-Request-ID" \
--data "config.generator=uuid#counter" \
--data "config.echo_downstream=false"
CONSUMER
is the id
or username
of the consumer that this plugin
configuration will target.
You can combine consumer.id
, service.id
, or route.id
in the same request, to further narrow the scope of the plugin.
First, create a KongPlugin
resource:
apiVersion: configuration.konghq.com/v1
kind: KongPlugin
metadata:
name: <correlation-id-example>
config:
header_name: Kong-Request-ID
generator: uuid#counter
echo_downstream: false
plugin: correlation-id
Then, apply it to a consumer by
annotating the KongConsumer resource as follows:
apiVersion: configuration.konghq.com/v1
kind: KongConsumer
metadata:
name: {CONSUMER}
annotations:
konghq.com/plugins: <correlation-id-example>
kubernetes.io/ingress.class: kong
CONSUMER
is the id
or username
of the consumer that this plugin
configuration will target.
Note: The KongPlugin resource only needs to be defined once
and can be applied to any Service, Consumer, or Route in the namespace. If you
want the plugin to be available cluster-wide, create the resource as a
KongClusterPlugin
instead of KongPlugin
.
For example, configure this plugin on a consumer by
adding this section to your declarative configuration file:
plugins:
- name: correlation-id
consumer: {CONSUMER}
config:
header_name: Kong-Request-ID
generator: uuid#counter
echo_downstream: false
CONSUMER
is the id
or username
of the consumer that this plugin
configuration will target.
Configure this plugin on a consumer:
- In Kong Manager, select the workspace.
- From the Dashboard, scroll down to Consumers and click View for the consumer row.
- Select the Plugins tab.
- Click Add Plugin.
-
Find and select the Correlation ID plugin.
Note: If the plugin is greyed out, then it is not available
for your product tier. See
Kong Gateway tiers.
- If the option is available, select Global.
- Click Create.
Enable the plugin globally
A plugin which is not associated to any service, route, or consumer is
considered global, and will be run on every request. Read the
Plugin Reference and the Plugin Precedence
sections for more information.
Admin API
Kubernetes
Declarative (YAML)
Kong Manager
For example, configure this plugin globally with:
$ curl -X POST http://{HOST}:8001/plugins/ \
--data "name=correlation-id" \
--data "config.header_name=Kong-Request-ID" \
--data "config.generator=uuid#counter" \
--data "config.echo_downstream=false"
Create a KongClusterPlugin
resource and label it as global:
apiVersion: configuration.konghq.com/v1
kind: KongClusterPlugin
metadata:
name: <global-correlation-id>
annotations:
kubernetes.io/ingress.class: kong
labels:
global: \"true\"
config:
header_name: Kong-Request-ID
generator: uuid#counter
echo_downstream: false
plugin: correlation-id
For example, configure this plugin using the plugins:
entry in the declarative
configuration file:
plugins:
- name: correlation-id
config:
header_name: Kong-Request-ID
generator: uuid#counter
echo_downstream: false
Configure this plugin globally:
- In Kong Manager, select the workspace.
- From the Dashboard, select Plugins in the left navigation.
- Click New Plugin.
-
Find and select the Correlation ID plugin.
Note: If the plugin is greyed out, then it is not available
for your product tier. See
Kong Gateway tiers.
- If the option is available, set the plugin scope to Global.
- Click Create.
Parameters
Here's a list of all the parameters which can be used in this plugin's configuration:
Form Parameter |
Description |
name
required
Type: string |
The name of the plugin, in this case correlation-id . |
service.id
Type: string |
The ID of the Service the plugin targets. |
route.id
Type: string |
The ID of the Route the plugin targets. |
consumer.id
Type: string |
The ID of the Consumer the plugin targets. |
enabled
required
Type: boolean
Default value: true |
Whether this plugin will be applied. |
config.header_name
optional
Default value: Kong-Request-ID
|
The HTTP header name to use for the correlation ID.
|
config.generator
optional
Default value: uuid#counter
|
The generator to use for the correlation ID. Accepted values are uuid , uuid#counter and tracker See Generators.
|
config.echo_downstream
optional
Default value: false
|
Whether to echo the header back to downstream (the client).
|
How it works
When enabled, this plugin will add a new header to all of the requests processed by Kong. This header bears the name configured in config.header_name
, and a unique value generated according to config.generator
.
This header is always added to calls to your upstream services, and optionally echoed back to your clients according to the config.echo_downstream
setting.
If a header bearing the same name is already present in the client request, it is honored and this plugin will not tamper with it.
Generators
uuid
Format:
xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
Using this format, a UUID is generated in its hexadecimal form for each request.
uuid#counter
Format:
xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx#counter
In this format, a single UUID is generated on a per-worker basis, and further requests simply append a counter to the UUID after a #
character. The counter
value starts at 0
for each worker, and gets incremented independently of the others.
This format provides a better performance, but might be harder to store or process for analyzing (due to its format and low cardinality).
tracker
Format:
ip-port-pid-connection-connection_requests-timestamp
In this format, the correlation id contains more practical implications for each request.
The following is a detailed description of the field
form parameter |
description |
ip |
an address of the server which accepted a request |
port |
port of the server which accepted a request |
pid |
pid of the nginx worker process |
connection |
connection serial number |
connection_requests |
current number of requests made through a connection |
timestamp |
a floating-point number for the elapsed time in seconds (including milliseconds as the decimal part) from the epoch for the current time stamp from the nginx cached time |
FAQ
Can I see my correlation ids in my Kong logs?
The correlation id will not show up in the Nginx access or error logs. As such, we suggest you use this plugin alongside one of the Logging plugins, or store this id on your backend-side.