Skip to content

Bug: Unexpected behavior of Metrics.addDimensions function #4711

@Akshay314

Description

@Akshay314

Expected Behavior

Hi,

The typescript implementation of addDimensions diverge from python implementation where in former, you are creating a new dimensionSet this.#dimensionsStore.addDimensionSet(newDimensions); while in python, it appends to dimensions to existing set.

Also, the method documentation does not specify this clearly. Ideally as per name suggests, it should append new dimensions to existing dimensionSet.

Current Behavior

AddDimensions function is creating a new dimension set for given set of metrics instead of appending to existing set.

Code snippet

public addDimensions(dimensions: Dimensions): void {
  const newDimensions = this.#sanitizeDimensions(dimensions);
  const currentCount = this.#dimensionsStore.getDimensionCount();
  const newSetCount = Object.keys(newDimensions).length;

  if (currentCount + newSetCount >= MAX_DIMENSION_COUNT) {
    throw new RangeError(
      `The number of metric dimensions must be lower than ${MAX_DIMENSION_COUNT}`
    );
  }

  this.#dimensionsStore.addDimensionSet(newDimensions);
}

Steps to Reproduce

Call addDimensions twice with different set of key value pairs before publishing metrics. It would result in two different dimension sets.

Possible Solution

Loop over given dimensions and add each pair to existing set.
newDimensions.forEach((k,v) -> this.#dimensionsStore.addDimension(name, value);)

Powertools for AWS Lambda (TypeScript) version

latest

AWS Lambda function runtime

22.x

Packaging format used

npm

Execution logs

Metadata

Metadata

Assignees

Labels

not-a-bugNew and existing bug reports incorrectly submitted as bug

Type

No type

Projects

Status

Pending customer

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions