API Gateway seamlessly integrates with Log Service. Log Service provides various features. For example, you can query logs, download logs, and perform multi-dimensional statistical analysis of logs in real time. You can also ship logs to Object Storage Service(OSS) or MaxCompute.
For more information about Log Service, see What is Simple Log Service?.
Log Service allows you to generate 500 MB of log data for free each month. If you generate more log data than this limit, the excess will be charged. For more information, see Billable items of pay-by-feature.
1. Overview
1.1 Online log query
You can use keywords to query logs. Both exact match and fuzzy match are supported. Log query can be used for troubleshooting or statistical query.
1.2 Detailed logs of API calls
The following table describes information about each API call in detailed logs.
Field | Description |
apiGroupUid | The ID of the API group to which the API operation belongs. |
apiGroupName | The name of the API group to which the API operation belongs. |
apiUid | The ID of the API operation. |
apiName | The name of the API operation. |
apiStageUid | The ID of the environment where the API operation resides. |
apiStageName | The name of the environment where the API operation resides. |
httpMethod | The HTTP method that was used by the API request. |
path | The request path in the API request. |
Domain | The domain name of the requested resources. |
statusCode | The HTTP status code of the API response. |
errorMessage | The error message. |
appId | The ID of the application from which the API request was sent. |
appName | The name of the application from which the API request was sent. |
clientIp | The IP address of the client from which the API request was sent. |
exception | The specific error message that was returned by the backend service of the API operation. |
providerAliUid | The ID of the account that owns the API operation. |
region | The region where the API operation resides, for example, cn-hangzhou, which indicates the China (Hangzhou) region. |
requestHandleTime | The time point in UTC at which the API request was received by API Gateway. |
requestId | The ID of the API request. The ID of each API request is unique within API Gateway. |
requestSize | The size of the API request. Unit: bytes. |
responseSize | The size of the API response. Unit: bytes. |
serviceLatency | The latency of the backend service of the API operation. Unit: milliseconds. |
1.3 Custom analysis chart
You can use log fields in section 1.2 to customize analysis charts based on your statistical and business requirements.
1.4 Predefined analysis report
API Gateway provides a predefined analysis report, which contains predefined global statistical charts that are easy to use. You can use these charts to obtain information such as the number of API requests, success rate, failure rate, latency, number of applications that called API operations, failure statistics, most-called API groups, most-called API operations, and highest latency.
2. Configure the log service for API Gateway
2.1 Configure the log service
Before you begin, make sure that you have activated Log Service and created a project and a Logstore in the Log Service console. For more information, see What is Simple Log Service?.
You can configure the log service for API Gateway in the API Gateway console or the Log Service console.
2.1.1 Configure the log service in the API Gateway console
(1) Log on to the API Gateway console. In the left-side navigation pane, choose Publish APIs > Log Manage. Select a region in the top navigation bar, for example, the China (Hangzhou) region.
(2) On the Log Manage page, click Create Log Config. The Create Log Config dialog box appears.
(3) Select a project and a Logstore. If no options are available after you click the drop-down arrow, click create new project to create a project and a LogStore in the Log Service Console.
(4) Go back to the API Gateway console and complete the configurations.
(5) You are navigated to the Log Service console. Enable the indexing feature for the Logstore.
2.1.2 Configure the log service in the Log Service console
For information about how to configure the log service for API Gateway in the Log Service console, see API Gateway access logs.
After configurations are completed, API calls will be recorded in the Logstore that you created in the Log Service console and configured for the log service of API Gateway.
2.2 View logs of API calls
Log on to the API Gateway console. In the left-side navigation pane, choose Publish APIs > Log Manage. On the Log Manage page, click Access Log in the Operation column. You are navigated to the Log Service console, as shown in the following figure. On this page, you can query logs.
You can also log on to the Log Service console to view logs.
2.3 Customize query reports
You can customize query reports based on your business requirements. For more information, see Overview of visualization.