Description
Use case
I'd like to use the logMetrics
middleware without seeing a warning that I'm not publishing metrics, or writing an empty metrics object to EMF.
I have a Lambda that may emit 0 metrics. I know this is a possibility and don't consider it an issue.
But I use the logMetrics
middleware which 1. requires me to create any metrics I may emit at the start of my function, and 2. always calls publishStoredMetrics which logs a warning and emits empty metrics.
No application metrics to publish. The cold-start metric may be published if enabled. If application metrics should never be empty, consider using `throwOnEmptyMetrics`
{"_aws":{"Timestamp":1707345436427,"CloudWatchMetrics":[{"Namespace":"ns","Dimensions":[["service"]],"Metrics":[]}]},"service":"service_undefined"}
Solution/User Experience
I see this warning was added in a previous feature #1397 so it's unlikely we would remove it. I'd be happy with a new option doNotWarnOnEmptyMetrics
, or changing throwOnEmptyMetrics
to accept true | false | 'some-option-to-disable-warnings'
.
I'd also be happy if storedMetrics
was public, or there was a public method empty(): boolean
so I could write my own middleware that calls metric.empty() || metric.publishStoredMetrics()
.
Alternative solutions
No response
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