You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
dreamorosi opened this issue
Mar 25, 2025
· 0 comments
Labels
bugSomething isn't workingconfirmedThe scope is clear, ready for implementationmetricsThis item relates to the Metrics Utilityon-holdThis item is on-hold and will be revisited in the future
When calling the metrics.addDimensions() method of the Metrics utility, the dimensions should create a new dimension set rather than concatenating the dimensions into the existing set.
The EMF specification already supports this type of use case, and specifically, it represents a dimension set as an array/list of dimensions within the Dimensions array/list of a metric, for example:
In terms of developer experience, this is how the updated addDimensions() would work alongside existing functions:
Adding a new dimension set:
constmetrics=newMetrics({namespace: 'serverlessAirline',serviceName: 'orders',});exportconsthandler=async()=>{// existing functionality for single dimensionmetrics.addDimension('environment','prod');// fixed featuremetrics.addDimensions({dimension1: "1",dimension2: "2"});// continue emitting & flushing metrics as todaymetrics.addMetric('successfulBooking',MetricUnit.Count,1);metrics.publishStoredMetrics();};
Handling overwritten dimensions
constmetrics=newMetrics({namespace: 'serverlessAirline',serviceName: 'orders',});exportconsthandler=async()=>{metrics.addDimension('dimension1','A');metrics.addDimensions({dimension1: "B",// last value to be set is useddimension2: "2"});};
constmetrics=newMetrics({namespace: 'serverlessAirline',serviceName: 'orders',defaultDimensions: {environment: 'prod'}});exportconsthandler=async()=>{metrics.addDimensions({// this set will include `environment` from default dimensionsdimension1: "1",dimension2: "2"});};
Note: when default dimensions are added at runtime, for example via the metrics.setDefaultDimensions() method, only dimension sets added after the default dimensions were set will include these dimensions. Changes are not retroactive.
constmetrics=newMetrics({namespace: 'serverlessAirline',serviceName: 'orders',defaultDimensions: {environment: 'prod'}});exportconsthandler=async()=>{metrics.addDimensions({"dimension1": "1","dimension2": "2"}) # thisincludesenvironment// for some reason I want to add more default dimensionsmetrics.setDefaultDimensions({tenantId: "1"})// this does not set tenant_id retroactively into the previous setmetrics.addDimensionSet({"foo": "1","bar": "2"}) # thisincludesenvironmentandtenantiId}
In terms of implementation, below is a non-exhaustive list of actions that should be done:
update implementation of addDimensions()here to create a set instead of multiple separate dimensions
update documentation
update unit tests under packages/metrics/tests/unit/dimensions.ts
Powertools for AWS Lambda (TypeScript) version
latest
AWS Lambda function runtime
22.x
Packaging format used
npm
Execution logs
The text was updated successfully, but these errors were encountered:
dreamorosi
added
on-hold
This item is on-hold and will be revisited in the future
confirmed
The scope is clear, ready for implementation
metrics
This item relates to the Metrics Utility
and removed
triage
This item has not been triaged by a maintainer, please wait
labels
Mar 25, 2025
bugSomething isn't workingconfirmedThe scope is clear, ready for implementationmetricsThis item relates to the Metrics Utilityon-holdThis item is on-hold and will be revisited in the future
Expected Behavior
When calling the
metrics.addDimensions()
method of the Metrics utility, the dimensions should create a new dimension set rather than concatenating the dimensions into the existing set.Basically this:
should generate this:
Current Behavior
Currently this:
instead generates this:
Code snippet
See above.
Steps to Reproduce
See above.
Possible Solution
The EMF specification already supports this type of use case, and specifically, it represents a dimension set as an array/list of dimensions within the
Dimensions
array/list of a metric, for example:In terms of developer experience, this is how the updated
addDimensions()
would work alongside existing functions:Adding a new dimension set:
Handling overwritten dimensions
Click to see EMF output
Interaction with default dimensions:
Click to see EMF output
Note: when default dimensions are added at runtime, for example via the
metrics.setDefaultDimensions()
method, only dimension sets added after the default dimensions were set will include these dimensions. Changes are not retroactive.In terms of implementation, below is a non-exhaustive list of actions that should be done:
addDimensions()
here to create a set instead of multiple separate dimensionspackages/metrics/tests/unit/dimensions.ts
Powertools for AWS Lambda (TypeScript) version
latest
AWS Lambda function runtime
22.x
Packaging format used
npm
Execution logs
The text was updated successfully, but these errors were encountered: