Description
Use case
We would like our Metrics to be logged in pure JSON to match the EMF document structure for addMetric()
and the logMetrics()
middleware. This will allow the logs to be machine readable and ingested by aggregators. Instead we are seeing the EMF JSON prefixed with the timestamp, request Id, and log level, because the code uses console.log()
We use the Powertools for AWS Lambda (TypeScript) Metrics and Powertools for AWS Lambda (TypeScript) Logger. The Logger works fine because it uses its own console instance.
This is an example of one of the log events from CloudWatch:
2023-10-25T17:38:05.273Z 274cced9-0439-4a76-befe-eeef0ec34460 INFO
{
"_aws": {
"Timestamp": 1698255485273,
"CloudWatchMetrics": [
{
"Namespace": "xxxxxx",
"Dimensions": [
[
"service",
"environment",
"function_name"
]
],
"Metrics": [
{
"Name": "ColdStart",
"Unit": "Count"
}
]
}
]
},
"service": "xxxxxx",
"environment": "test",
"function_name": "xxxxxx",
"ColdStart": 1
}
Solution/User Experience
I would like to see the metrics logged with just JSON similar to how the logs are output from the Powertools Logger package.
- Option 1: Stop using standard
console.log()
and do something similar to the Powertools Logger, or even re-use it.- Con: This would not technically be backwards compatible and could in theory break folks if they are parsing their logs in a specific way
- Pro: Everyone now gets easily machine readable metrics logs
- Option 2: Update addMetric() and logMetrics() to accept an option indicating the desire for pure JSON output.
- Pro: Can be done in a backwards compatible manner
- Con: requires code changes for folks that want JSON logging
Alternative solutions
An alternative would be for us to stop using PowerTools metrics and EMF and use our aggregator's metrics, or convert to OpenTelemetry to be vendor agnostic.
Acknowledgment
- This feature request meets Powertools for AWS Lambda (TypeScript) Tenets
- Should this be considered in other Powertools for AWS Lambda languages? i.e. Python, Java, and .NET
Future readers
Please react with 👍 and your use case to help us understand customer demand.
Metadata
Metadata
Assignees
Labels
Type
Projects
Status