Request/response capture
Request/response capture is a log enhancement capability of the gateway. It records the content of requests and responses that pass through the gateway in access logs and delivers the content to Simple Log Service (SLS) along with the access logs. This facilitates troubleshooting, API auditing, and traffic analysis.
The captured content consists of four items: request headers, request bodies, response headers, and response bodies. Each item can be enabled or disabled independently. The feature takes effect at the gateway level and applies to all traffic on the gateway.
Enabling this feature significantly increases log volume and log costs. We recommend that you enable the feature only for debugging purposes and disable it promptly after troubleshooting is complete.
Gateway version requirements
This feature requires a recent gateway engine version. The Serverless edition does not support this feature.
When you enable the feature, the system automatically checks the engine version. If the engine version does not meet the requirements, the operation is rejected and you are prompted to upgrade. Disabling the feature is not version-restricted. You can disable the feature at any time, regardless of the version.
Gateway type | Minimum engine version |
Cloud Native API Gateway | 2.1.18 or later |
AI Gateway | 2.1.20 or later |
If your engine version is earlier than required, upgrade the gateway engine before you enable the feature.
Configuration description
The feature provides the following configuration items:
Configuration item | Description | Default value |
Record request headers | Specifies whether to capture request headers | Disabled |
Record request body | Specifies whether to capture request bodies | Disabled |
Maximum request body capture size (bytes) | The maximum number of bytes that can be captured from a request body | 5120 (5 KB) |
Record response headers | Specifies whether to capture response headers | Disabled |
Record response body | Specifies whether to capture response bodies | Disabled |
Maximum response body capture size (bytes) | The maximum number of bytes that can be captured from a response body | 5120 (5 KB) |
Body capture size rules
The unit is bytes. The setting takes effect only when the corresponding body capture is enabled.
If this parameter is left empty or set to 0 or a smaller value, the default size of 5 KB applies.
The maximum capture size limit for a single body depends on the deployment form of the gateway instance. Use the limit displayed on the configuration page in the console. The current limits are 5 KB (5,120 bytes) for fully managed instances and 200 KB (204,800 bytes) for non-fully managed instances.
Body content that exceeds the size is truncated, and only the beginning portion is retained.
Enable and disable
Enable
The captured content is delivered to Simple Log Service (SLS) along with access logs. Before you enable the feature, make sure that access log delivery is configured.
Go to the gateway details page, open Parameters, and find the Access Log Delivery Configuration section.
Find Request/Response Capture and click the status link on the right to open the configuration dialog box.
Enable Record request headers, Record request body, Record response headers, and Record response body as needed, and set the maximum body capture size.
Click Save. After the settings are saved, the status link changes to Enabled.
Disable
Open the configuration dialog box, turn off the corresponding switches, and click Save. Turning off all four items is equivalent to disabling the entire feature. After the settings are saved, the status link changes to Disabled, and the relevant content is no longer written to access logs.
View captured logs
The captured content is written to gateway access logs as additional fields and delivered to Simple Log Service (SLS) along with the access logs. The captured content corresponds to the following log fields:
Captured content | Access log field | Control switch |
Request headers |
| Record request headers |
Request body | Top-level field | Record request body |
Response headers |
| Record response headers |
Response body | Top-level field | Record response body |
Field description
Request body/response body: written directly to the top-level fields
request_bodyandresponse_body.Request headers/response headers: written to the
envoy.all_request_headersandenvoy.all_response_headerssubfields in therequest_headersandresponse_headersobjects. These two objects also carry the custom header capture capability of access logs. Therefore, the captured header information coexists with the custom header fields in the form of subfields, and they do not overwrite each other.
Field occurrence rules
Fields appear on demand: a field is written to access logs only when the corresponding capture item is enabled. Fields for disabled capture items do not appear.
You can query, filter, and analyze data by these fields in Simple Log Service (SLS).
If a request body or response body exceeds the configured maximum capture size, only the truncated beginning portion of the content is retained in the corresponding field.
Data security and capture limits
Sensitive data: request and response headers and bodies may contain sensitive data, such as tokens, passwords, and personal information. Before you enable the feature, evaluate compliance and data masking requirements. Enable only the necessary capture items and set an appropriate body size.
Body capture scope: not all types of bodies are recorded (limited by content type), and portions that exceed the configured size are truncated.