Skip to content

Powertools-Metrics not working with Lambda Handlder #1128

Closed
@mahedi99

Description

@mahedi99

I have custom dashboard setup with a few widget. Now, I am trying to push CloudWatch metrics with the same namespace name, metrics name and dimension name inside a lambda handler function. However, even though it does not raise any error, it fails to record any value for the putMetric() call. Example code below.

MetricsLogger metricsLogger = MetricsUtils.metricsLogger();

@Metrics(namespace = "mynamespace")
public Void handleRequest(final SQSEvent event, final Context context) {
        metricsLogger.putDimensions(DimensionSet.of("mydimension", "success"));
        metricsLogger.putMetric("testmetric", 1, Unit.COUNT);
}

Expected Behavior

One of the widgets is recording and visualizing all the putMetric() calls. For all the putMetric() calls it should record and reflect on the custom dashboard widget.

Current Behavior

If I call metricsLogger.putMetric(), it executes successfully without raising any error. However, there's no metric value recorded in the dashboard.

Steps to Reproduce (for bugs)

  1. Write a lambda handler function with @Metrics annotation.
  2. Add a custom namespace. eg. @Metrics(namespace = "mynamespace")
  3. Declare metriclogger instance. eg. MetricsLogger metricsLogger = MetricsUtils.metricsLogger();
  4. Execute below api calls:
    metricsLogger.putDimensions(DimensionSet.of("mydimension", "success"));
    metricsLogger.putMetric("testmetric", 1, Unit.COUNT);
  5. In response, it won't record anything on the dashboard.

Environment

  • Powertools version used: 1.15.0
  • Packaging format (Layers, Maven/Gradle): Maven
  • AWS Lambda function runtime: Java11
  • Debugging logs No Logs, since it doesn't raise any error

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingtriage

    Type

    No type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions