Description
Describe the feature
Access (and in the case of web socket apis, data trace) logs are critical for debugging problems with api gateways. There are no options on the HttpStage and WebSocketStage classes to enable access and data logs. They should be added.
Use Case
When debugging problems with contacting/using Http and WebSocket apis.
Proposed Solution
For both Http and WebSocket stages (which both have access logs), the idea would be to add an accessLogEnabled flag and a accessLogFormat field (which has a default, unlike the raw setting in CfnStage). An Http api instantiation might look like this:
const httpApi = new apigw.HttpApi(this, 'HttpApi', { createDefaultStage: false });
new apigw.HttpStage(this, 'HttpDev', {
httpApi,
stageName: 'dev',
autoDeploy: true,
accessLogEnabled: true,
});
using the default value for the access log format. Alternatively, it would be possible to supply a format like this:
const accessLogFormat = JSON.stringify({
apigw: {
api_id: '$context.apiId',
stage: '$context.stage',
},
request: {
request_id: '$context.requestId',
extended_request_id: '$context.extendedRequestId',
},
errors: {
message: '$context.error.message',
}
http: {
method: '$context.httpMethod'
}
});
new apigw.HttpStage(this, 'HttpDevStageWithExternalLogGroup', {
httpApi: httpApiWithExternalLogGroup,
stageName: 'dev',
autoDeploy: true,
accessLogEnabled: true,
accessLogFormat: accessLogFormat,
});
Web sockets would also support the accessLogEnabled and accessLogFormat properties in exactly the same way.
Web socket apis (but not http apis) support data logging, which would be controlled by a new property dataTraceLoggingLevel, with supported levels of INFO, ERROR and OFF, like this:
const websocketApi = new apigw.WebSocketApi(this, 'WebSocketApi');
new apigw.WebSocketStage(this, 'WebSocketDev', {
webSocketApi,
stageName: 'dev',
autoDeploy: true,
dataTraceLoggingLevel: 'INFO',
});
The CfnStage has a property to enable data trace logging and a separate log level property, but that seems redundant. If the log level is OFF, then the data trace enabled flag is false.
Finally, while metrics aren't logging, to flesh out the possibilities surfaced by the defaultRouteSettings support for turning on detailed metrics should be surfaced in HttpStage (this is something that's not supported by web socket apis), like this:
new HttpStage(stack, 'DefaultStage', {
httpApi: api,
stageName: 'dev',
detailedMetricsEnabled: true,
});
Other Information
No response
Acknowledgements
- I may be able to implement this feature request
- This feature might incur a breaking change
CDK version used
2.40.0
Environment details (OS name and version, etc.)
Windows, Linux and Mac OS