All Products
Search
Document Center

API Gateway:Use Simple Log Service to manage logs of API calls

Last Updated:Jun 04, 2024

API Gateway seamlessly integrates with Simple Log Service for 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.

image

  • Simple 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 Pricing.

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 lists fields in logs. You can query logs by these fields. The requestQueryString, requestHeaders, requestBody, responseHeaders, and responseBody fields are supported only by virtual private cloud (VPC)-connected dedicated instances and must be configured on the group details page.

Field

Description

apiGroupUid

The ID of the group to which the API belongs.

apiGroupName

The name of the group to which the API belongs.

apiUid

The API ID.

apiName

The API name.

apiStageUid

The ID of the environment in which the API was called.

apiStageName

The environment name.

httpMethod

The HTTP method that was used by the API request.

path

The request path of the API.

domain

The domain name that was used for the API call.

statusCode

HttpStatusCode

errorMessage

The returned error message.

appId

The ID of the application that was used to call the API.

appName

The name of the application that was used to call the API.

clientIp

The IP address of the client that initiated the API call.

exception

The specific error message that was returned by the backend service of the API.

exchangeTimestamp

The I/O points in time in the request link.

  • FrontRequestStart: the point in time when API Gateway started to receive the request from the client.

  • FrontRequestEnd: the point in time when API Gateway completed receiving the request from the client.

  • BackendRequestStart: the point in time when API Gateway started to forward the request to the backend service.

  • BackendRequestEnd: the point in time when API Gateway completed forwarding the request to the backend service.

  • BackendResponseStart: the point in time when API Gateway started to receive the response from the backend service.

  • BackendResponseEnd: the point in time when API Gateway completed receiving the response from the backend service.

  • FrontResponseStart: the point in time when API Gateway started to send the response to the client.

  • FrontResponseEnd: the point in time when API Gateway completed sending the response to the client.

providerAliUid

The ID of the account that provides the API.

region

The region where the API 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 request ID. The ID is globally unique.

requestSize

The request size. Unit: bytes.

responseSize

The response size. Unit: bytes.

serviceLatency

The total time consumed to access the backend resources. The total time includes the time consumed to request a connection to the resources, the time consumed to establish the connection, and the time consumed to call the backend service. Unit: milliseconds.

errorCode

The error code, such as X500ER.

requestProtocol

The protocol used by the client to send the request. Valid values: HTTP, HTTPS, and WS.

instanceId

The ID of the API Gateway instance to which the API belongs.

initialRequestId

If an API calls another API, for example, API-1 calls API-2, initialRequestId is used to record the request ID of API-1 in the logs of API-2.

clientNonce

The X-Ca-Nonce header in the request initiated from the client.

requestQueryString

The queryString in the request initiated from the client. This field is for dedicated instances only.

requestHeaders

The header content in the request initiated from the client. This field is for dedicated instances only.

requestBody

The body of the request sent by the client. The body can contain up to 1,024 bytes in length. This field is for dedicated instances only.

responseHeaders

The header content of the API response. This field is for dedicated instances only.

responseBody

The response content. The response can contain up to 1,024 bytes in length. This field is for dedicated instances only.

consumerAppKey

The AppKey that was used in the request.

totalLatency

The total latency of the API request. Unit: milliseconds.

customTraceId

The traceId of the end-to-end log.

jwtClaims

The JSON web token (JWT) claims. The claims can be configured at the group level.

plugin

The plug-in hit by the request and the relevant context.

2. Configure the log service for API Gateway

2.1 Configure the log service

You can configure the log service for API Gateway in two methods. In the first method, you synchronize logs by using the log audit service in the Simple Log Service console. Then, logs from all regions are aggregated in the configured project and no additional configurations are required in API Gateway. In the second method, you connect API Gateway data to Simple Log Service by synchronizing configurations for each region. This section describes the two methods.

Only the first method is supported for synchronizing logs on Alibaba Gov Cloud and on Alibaba Finance Cloud.

2.1.1 Configure log audit

1. Go to the Log Audit Service page in the Simple Log Service console and select the region of central project. Then, all API Gateway logs will be delivered to this region.

Perform authorization in any of the two methods by following instructions. In this example, manual authorization is used.

After the authorization is complete, view the call logs of API Gateway in apigateway_log in the central project.

2.1.1 Configure the log service in the API Gateway console

1. Make sure that you have activated Simple Log Service. Then, select the corresponding region in the Simple Log Service console and create a project and a Logstore. In this example, the China (Hangzhou) region is used.

2. Select API Gateway as the data source.

Click Next until the configuration is complete.

2.2 View logs of API calls

You can log on to the Simple Log Service console to view logs and retrieve call logs online based on the query syntax.

2.3 Configure a custom query report

You can configure a custom query report based on your business requirements. For more information, see Create a dashboard.