Skip to content

Bug: Duplicate warning being logged when invoking the captureColdStartMetric in the Metrics utility #4227

@sdangol

Description

@sdangol

Expected Behavior

There should be no warnings when I am not trying to set the metric dimensions myself.

Current Behavior

When we instantiate a Metrics class and call the captureColdStartMetric method. There are two messages with the message

Image

Code snippet

import { Metrics } from '@aws-lambda-powertools/metrics';
const metrics = new Metrics();

export const lambdaHandler = () => {
    metrics.captureColdStartMetric();
    return;
};

Steps to Reproduce

  1. Create a lambda function
  2. Instantiate a Metrics class without any options
  3. Invoke the captureColdStartMetric method from the Metrics utility in the Lambda function
  4. Invoke the Lambda function
  5. View the logs from the Lambda function

Possible Solution

The warnings were added as part of #4222. But because thesetDefaultDimensions is being called in multiple places implicitly when instantiating the class and invoking the captureColdStartMetric function, the function tries to warn the user about the dimension being overridden.

The setDefaultDimensions is being called in:

  1. https://github.com/aws-powertools/powertools-lambda-typescript/blob/main/packages/metrics/src/Metrics.ts#L1116
  2. https://github.com/aws-powertools/powertools-lambda-typescript/blob/main/packages/metrics/src/Metrics.ts#L1097
  3. https://github.com/aws-powertools/powertools-lambda-typescript/blob/main/packages/metrics/src/Metrics.ts#L441-L443

Powertools for AWS Lambda (TypeScript) version

latest

AWS Lambda function runtime

22.x

Packaging format used

npm, Lambda Layers

Execution logs

Dimension "service" has already been added. The previous value will be overwritten.

Metadata

Metadata

Labels

bugSomething isn't workingcompletedThis item is complete and has been merged/shipped

Type

No type

Projects

Status

Shipped

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions