No x-request-id on direct response
Description:
When doing a curl on a directResponse route, I do not see the x-request-id header.
Repro steps:
Envoy config:
# envoy.yaml
admin:
access_log_path: /tmp/admin_access.log
address:
socket_address: { address: 0.0.0.0, port_value: 9901 }
static_resources:
listeners:
- name: listener_0
address:
socket_address: { address: 0.0.0.0, port_value: 80 }
filter_chains:
- filters:
- name: envoy.http_connection_manager
config:
stat_prefix: ingress_http
codec_type: AUTO
route_config:
name: local_route
virtual_hosts:
- name: local_service
domains: ["*"]
routes:
- direct_response:
body:
inline_string: '{"message":"direct response"}'
status: 400
match:
prefix: "/"
response_headers_to_add:
- append: false
header:
key: content-type
value: application/json
http_filters:
- name: envoy.router
Run Envoy:
$ docker run --rm -v $(pwd)/envoy.yaml:/etc/envoy/envoy.yaml -p 80:80 envoyproxy/envoy:latest
See the bug:
$ curl -v http://localhost
* Rebuilt URL to: http://localhost/
* Trying ::1...
* TCP_NODELAY set
* Connection failed
* connect to ::1 port 80 failed: Connection refused
* Trying 127.0.0.1...
* TCP_NODELAY set
* Connected to localhost (127.0.0.1) port 80 (#0)
> GET / HTTP/1.1
> Host: localhost
> User-Agent: curl/7.54.0
> Accept: */*
>
< HTTP/1.1 400 Bad Request
< content-length: 35
< location: http://localhost/
< content-type: application/json
< date: Mon, 04 Feb 2019 16:41:47 GMT
< server: envoy
<
* Connection #0 to host localhost left intact
{"message":"direct response"}%
What I expected to see:
< x-request-id: xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxxI think this is only intended to be inserted for request headers, not response headers. Do you have a use case requiring this on response?
The x-request-id header is spread across all our service logs (even auth & rate-limiting) and sent to the client so we can track a client issue when they contact the support with a request id.
When not using direct response, how does x-request-id get reflected back to the client? AFAICT, Envoy is not inserting this in response headers itself. Does the backend do that?
Right now the only time envoy will response with x-request-id is when the https://www.envoyproxy.io/docs/envoy/latest/configuration/http_conn_man/headers.html#x-envoy-force-trace header is set. This is really old code that allows a similar use case of correlation. With that said, I do agree that Envoy returning x-request-id should be allowed/configurable. We could do this directly with a config option, although I also consider it part of https://github.com/envoyproxy/envoy/issues/4283.
This issue has been automatically marked as stale because it has not had activity in the last 30 days. It will be closed in the next 7 days unless it is tagged "help wanted" or other activity occurs. Thank you for your contributions.
This issue has been automatically closed because it has not had activity in the last 37 days. If this issue is still valid, please ping a maintainer and ask them to label it as "help wanted". Thank you for your contributions.
Right now the only time envoy will response with
x-request-idis when the https://www.envoyproxy.io/docs/envoy/latest/configuration/http_conn_man/headers.html#x-envoy-force-trace header is set. This is really old code that allows a similar use case of correlation. With that said, I do agree that Envoy returningx-request-idshould be allowed/configurable. We could do this directly with a config option, although I also consider it part of #4283.
Can I set the "x-envoy-force-trace" header in lua script (in envoy_on_request) in the envoy edge-proxy and expect the "x-request-id" header in the response handle in the lua script (in envoy_on_response callback) ? I tried but getting nil "x-request-id" in the response handle.
FYI: always_set_request_id_in_response is what I am using to inject x-request-id in the response. Seems to work for direct_response as well.
@surki , Thanks for the information but at that I used streamInfo:DynamicMetadata() to correlate the requestInfo with the corresponding response.
Most helpful comment
FYI:
always_set_request_id_in_responseis what I am using to inject x-request-id in the response. Seems to work for direct_response as well.