Skip to content

Commit c60ed24

Browse files
committed
Detect if header injected request_id before creating one
1 parent 4bc943a commit c60ed24

File tree

5 files changed

+11
-4
lines changed

5 files changed

+11
-4
lines changed

docs/examples/customization/configuration-snippets/ingress.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ metadata:
44
name: nginx-configuration-snippet
55
annotations:
66
nginx.ingress.kubernetes.io/configuration-snippet: |
7-
more_set_headers "Request-Id: $request_id";
7+
more_set_headers "Request-Id: $req_id";
88
99
spec:
1010
rules:

docs/user-guide/annotations.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ Using this annotation you can add additional configuration to the NGINX location
207207

208208
```yaml
209209
nginx.ingress.kubernetes.io/configuration-snippet: |
210-
more_set_headers "Request-Id: $request_id";
210+
more_set_headers "Request-Id: $req_id";
211211
```
212212
213213
### Default Backend

docs/user-guide/configmap.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ Example for json output:
332332

333333
```console
334334
log-format-upstream: '{ "time": "$time_iso8601", "remote_addr": "$proxy_protocol_addr",
335-
"x-forward-for": "$proxy_add_x_forwarded_for", "request_id": "$request_id", "remote_user":
335+
"x-forward-for": "$proxy_add_x_forwarded_for", "request_id": "$req_id", "remote_user":
336336
"$remote_user", "bytes_sent": $bytes_sent, "request_time": $request_time, "status":
337337
$status, "vhost": "$host", "request_proto": "$server_protocol", "path": "$uri",
338338
"request_query": "$args", "request_length": $request_length, "duration": $request_time,

internal/file/bindata.go

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rootfs/etc/nginx/template/nginx.tmpl

+7
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,13 @@ http {
273273
'' $this_host;
274274
}
275275

276+
# Reverse proxies can detect if a client provides a X-Request-ID header, and pass it on to the backend server.
277+
# If no such header is provided, it can provide a random value.
278+
map $http_x_request_id $req_id {
279+
default $http_x_request_id;
280+
"" $request_id;
281+
}
282+
276283
{{ if $cfg.ComputeFullForwardedFor }}
277284
# We can't use $proxy_add_x_forwarded_for because the realip module
278285
# replaces the remote_addr too soon

0 commit comments

Comments
 (0)