Skip to content

Feature request: support high resolution metrics #1041

Description

@dreamorosi

Is your feature request related to a problem? Please describe.

Amazon CloudWatch announced support for high resolution metric extraction from structured logs (EMF). Customers can now provide an optional StorageResolution parameter within the EMF specification with a value of 1 or 60 (default) to indicate the desired resolution (in seconds) of the metric.

We should consider adding support for this new optional parameter to Metrics.

The EMF log should have this format:

{
  "_aws": {
    "CloudWatchMetrics": [
      {
        "Metrics": [
          {
            "Name": "Time",
            "Unit": "Milliseconds",
            "StorageResolution": 60 // <- new key
          }
        ],
        ...
      }
    ]
  },
  "Time": 1
}

As part of this issue we should also update the API docs, documentation, and unit/integration tests.

Describe the solution you'd like

import software.amazon.lambda.powertools.metrics.Metrics;
import software.amazon.cloudwatchlogs.emf.logger.MetricsLogger;

public class MetricsEnabledHandler implements RequestHandler<Object, Object> {

    MetricsLogger metricsLogger = MetricsUtils.metricsLogger();

    @Override
    @Metrics(namespace = "ExampleApplication", service = "booking")
    public Object handleRequest(Object input, Context context) {
        // Publish a metric with standard resolution i.e. StorageResolution = 60
        metricsLogger.putMetric("SuccessfulBooking", 1, Unit.COUNT, Resolution.STANDARD);
        // Publish a metric with high resolution i.e. StorageResolution = 1
        metricsLogger.putMetric("SuccessfulBooking", 1, Unit.COUNT, Resolution.HIGH);
        // The last parameter (storage resolution) is optional
        metricsLogger.putMetric("SuccessfulBooking", 1, Unit.COUNT);
    }
}

Describe alternatives you've considered

Additional context

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions