Expected Behavior
addDimension() and addDimensions() should enforce the same maximum dimension limit. When there are 28 dimensions and a user adds 1 more, both methods should either allow or reject it consistently.
Current Behavior
addDimension() uses <= (Metrics.ts:250):
if (MAX_DIMENSION_COUNT <= this.#dimensionsStore.getDimensionCount()) {
addDimensions() uses >= (Metrics.ts:285):
if (currentCount + newSetCount >= MAX_DIMENSION_COUNT) {
At the boundary (28 existing dimensions, adding 1 more to reach the MAX_DIMENSION_COUNT of 29), addDimension() allows it but addDimensions() throws a RangeError.
Code snippet
import { Metrics, MetricUnit } from '@aws-lambda-powertools/metrics';
const metricsA = new Metrics({ namespace: 'test' });
const metricsB = new Metrics({ namespace: 'test' });
// Fill both to 28 dimensions (1 default "service" + 27 regular)
for (let i = 1; i < 28; i++) {
metricsA.addDimension(`dimension-${i}`, 'test');
metricsB.addDimension(`dimension-${i}`, 'test');
}
// ✅ addDimension allows the 29th dimension
metricsA.addDimension('final', 'test');
// ❌ addDimensions rejects the 29th dimension
metricsB.addDimensions({ final: 'test' });
// RangeError: The number of metric dimensions must be lower than 29
Steps to Reproduce
- Create a
Metrics instance (which auto-adds service as a default dimension)
- Add 27 dimensions via
addDimension() to reach 28 total
- Call
addDimensions({ final: 'test' }) to add the 29th
- Observe
RangeError — while addDimension('final', 'test') would have succeeded
Possible Solution
Ensure both addDimension() and addDimensions() allow 29 dimensions.
Powertools for AWS Lambda (TypeScript) version
2.33.0
AWS Lambda function runtime
22.x
Packaging format used
npm
Disclaimer: After creating an issue, please wait until it is triaged and confirmed by a maintainer before implementing it. This will reduce amount of rework and the chance that a pull request gets rejected.
Expected Behavior
addDimension()andaddDimensions()should enforce the same maximum dimension limit. When there are 28 dimensions and a user adds 1 more, both methods should either allow or reject it consistently.Current Behavior
addDimension()uses<=(Metrics.ts:250):addDimensions()uses>=(Metrics.ts:285):At the boundary (28 existing dimensions, adding 1 more to reach the
MAX_DIMENSION_COUNTof 29),addDimension()allows it butaddDimensions()throws aRangeError.Code snippet
Steps to Reproduce
Metricsinstance (which auto-addsserviceas a default dimension)addDimension()to reach 28 totaladdDimensions({ final: 'test' })to add the 29thRangeError— whileaddDimension('final', 'test')would have succeededPossible Solution
Ensure both
addDimension()andaddDimensions()allow 29 dimensions.Powertools for AWS Lambda (TypeScript) version
2.33.0
AWS Lambda function runtime
22.x
Packaging format used
npm
Disclaimer: After creating an issue, please wait until it is triaged and confirmed by a maintainer before implementing it. This will reduce amount of rework and the chance that a pull request gets rejected.