Description
What were you trying to accomplish?
I want to use MetricsUtils.withSingleMetric
to publish a single metric with additional dimensions without affecting dimensions of other metrics. The single metric should also have the same default powertools dimension as other metrics when I don't overriding the default dimensions.
Expected Behavior
The single metric should have the default "Service" dimension as other normal metrics
Current Behavior
The single metric doesn't have the default "Service" dimension as other normal metrics
Possible Solution
I think the problem is in MetricsUtils#logger
. I suspect two issues here:
-
If there is no overriding default dimensions, we skip setting default dimensions. But in
LambdaMetricsAspect#refreshMetricsContext
(normal cases) we are appending the default powertoolsService
dimension instead. Possible solution: appending default PowertoolsService
dimension here as well. -
By using
setDimensions
if there are default overriding dimensions, this will likely cause another issue when customers usemetric.setDimensions(dimensions);
in theirConsumer<MetricsLogger>
, the overriding default dimensions will be gone. Possible solution: usesetDefaultDimensions
and update documentation to advice customers usingputDimensions
instead ofsetDimensions
(because usingsetDimensions
will hide all the default dimensions)
Steps to Reproduce (for bugs)
- Don't overwrite
defaultDimensions
. - Put some metrics using
MetricsUtils.metricsLogger()
so my metrics will have the default "Service" dimension created by Lambda Powertools - Publish a single metric with an additional dimension as following, the metric will only have
AdditionalDimension
MetricsUtils.withSingleMetric("MyCoolMetric", 1, Unit.COUNT, metric -> {
final DimensionSet dimensions = DimensionSet.of("AdditionalDimension", "AdditionalDimensionValue");
metric.setDimensions(dimensions);
});
- If Using
metric.putDimension(dimensions)
instead ofsetDimensions
, you will get all default EMF dimensions such asLogGroup
,ServiceName
,ServiceType
which is also not desirable, I think.
Environment
- Powertools version used: v1.5.0
- Packaging format (Layers, Maven/Gradle): Maven
- AWS Lambda function runtime: Java8
- Debugging logs: N/A