Skip to content

Bug: Prevent a single metric have more than 100 data points #311

@hjgraca

Description

@hjgraca

Expected Behaviour

Flush metric set when data point is reached to prevent potential data loss, where 100+ data points are added thus being ignored silently by CloudWatch EMF when processed in the background.

docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch_Embedded_Metric_Format_Specification.html#CloudWatch_Embedded_Metric_Format_Specification_structure_target

Current Behaviour

More than 100 metric data points can be added.

Code snippet

using AWS.Lambda.Powertools.Metrics;

public class Function
{
    [Metrics(CaptureColdStart = true)]
    public async Task<APIGatewayProxyResponse> FunctionHandler(APIGatewayProxyRequest apigwProxyEvent,
        ILambdaContext context)
    {

        Metrics.AddMetric("SuccessfulLocations", 1, MetricUnit.Count);
        Metrics.AddMetric("SuccessfulLocations", 1, MetricUnit.Count);
        // add other 100 values to the same metric
    }
}

Possible Solution

Serialize and flush metric data set when a single metric reaches 100 data points.
Throw exception when adding a metric with 100 data points.
Dimensions etc should be kept intact.

Steps to Reproduce

Run the code added in code snippet

Powertools for AWS Lambda (.NET) version

latest

AWS Lambda function runtime

dotnet6

Debugging logs

No response

Metadata

Metadata

Assignees

Labels

area/metricsCore metrics utilitybugUnexpected, reproducible and unintended software behaviourstatus/confirmedThe scope is clear, ready for implementation

Type

No type

Projects

Status

👀 In review

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions