powertools-lambda-typescript icon indicating copy to clipboard operation
powertools-lambda-typescript copied to clipboard

Feature request: remove `service_undefined` from default dimensions

Open akshuc96 opened this issue 1 year ago • 3 comments

Use case

The customers may not want to publish the service as a dimension, because they are is using other dimensions.

Solution/User Experience

Remove default dimension as service in the powertools

Alternative solutions


Acknowledgment

Future readers

Please react with 👍 and your use case to help us understand customer demand.

akshuc96 avatar Nov 26 '24 20:11 akshuc96

Thanks for opening your first issue here! We'll come back to you as soon as we can. In the meantime, check out the #typescript channel on our Powertools for AWS Lambda Discord: Invite link

boring-cyborg[bot] avatar Nov 26 '24 20:11 boring-cyborg[bot]

Hi @akshuc96,

The default behavior of Metrics is to add a service dimension to all metrics to help customers identify metrics. This value can be set by customers either via the serviceName constructor option or POWERTOOLS_SERVICE_NAME env variable.

This is not something we intend to change, so we will continue with this default as we believe it constitutes a sensible default.

What we can consider changing instead is what happens when customers don't specify a service name using either of the two methods above. Currently, if you don't set a service name, the Metrics utility will set the service dimension with value service_undefined, i.e.:

{"_aws":{"Timestamp":1732794693747,"CloudWatchMetrics":[{"Namespace":"my-app","Dimensions":[["service"]],"Metrics":[{"Name":"CustomMetric","Unit":"Bits"}]}]},"service":"service_undefined","CustomMetric":100}

This is something we implemented this way mainly for consistency, but I can see how it adds little value, so I agree we should consider changing.

Since this is a default, changing it requires a potentially breaking change and thus, we can do this only in our next major version - for which we don't yet have a date.

Besides adding this item to our v3 discussion, as a temporary solution, you can call metrics.clearDefaultDimensions() at some point after having initialized the Metric class, for example:

import { Metrics } from '@aws-lambda-powertools/metrics';

const metrics = new Metrics({ namespace: 'my-app' });
metrics.clearDefaultDimensions();

export const handler = async () => {
  // ...
};

cc @aws-powertools/lambda-python-core & @aws-powertools/lambda-dotnet-core - you might want to consider this same change in case you're doing the same.

dreamorosi avatar Nov 28 '24 11:11 dreamorosi

We are still committed to do this in the next major version - I have added the item to the discussion and the corresponding label.

If you find this item useful please feel free to add a 👍 to the original post above.

dreamorosi avatar Feb 03 '25 17:02 dreamorosi