Skip to content

Feature request: Option to only publish metrics when there are metrics to publish #2036

Closed
@everett1992

Description

@everett1992

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

Future readers

Please react with 👍 and your use case to help us understand customer demand.

Metadata

Metadata

Assignees

Labels

completedThis item is complete and has been merged/shippedfeature-requestThis item refers to a feature request for an existing or new utilitymetricsThis item relates to the Metrics Utility

Type

No type

Projects

Status

Shipped

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions