Add Custom Attributes to Gateway Request Logs¶
The underlying gateway used in the microservice engine is contour, which is responsible for delivering configuration to envoy for the control plane. The logging fields for request logs are also configured by contour and sent to envoy. Therefore, all that is needed is to add the desired fields to the contour configuration file.
The specific steps are as follows:
-
Go to the Microservice Engine - Cloud Native Gateway List and locate the cluster and namespace where the gateway with the configuration to be modified is located.
-
In the cluster and namespace where the gateway is located, search for the custom CR (ContourConfiguration).
-
Edit the CR resource obtained in the previous step and add the desired log fields in
.spec.envoy.logging.accessLogJSONFields
. For example, to add a log field for the response header X-Envoy-Upstream-Service-Time, add the following line:X-Envoy-Upstream-Service-Time=%RESP(X-ENVOY-UPSTREAM-SERVICE-TIME)%
.Before editing:
After editing:
-
Restart the contour component (this will not cause any interruption to the traffic).
-
After the pods have started successfully, access the interface through the gateway API and observe the log fields in the gateway logs.
Select a log entry and view the original text:
The custom response header can be seen in the log entry.
Note
This feature is applicable to Microservice Engine version 0.29.0 and higher.