Description
Use case
At the root level I define default metric which is environment name in my case.
metrics = Metrics()
metrics.set_default_dimensions(Environment=ENVIRONMENT)
This is all fine and Environment
gets propagated to all metrics. However, when single_metric()
is used this default dimension is ignored. This is what I do to overcome that.
metrics = Metrics()
with single_metric(
name="Metric1", unit=MetricUnit.Milliseconds, value=elapsed_ms
) as this_metric:
this_metric.add_dimension(name="TableName", value=self.table_name)
for name, value in metrics.default_dimensions.items():
this_metric.add_dimension(name=name, value=value)
or it should be possible with this_metric.default_dimensions = metrics.default_dimensions
, I did not tried this.
This way all the default dimensions are propagated with a single metric.
Solution/User Experience
When creating a SingleMetric
with single_metric
context manager default dimensions should be copied to a SingleMetric instance.
I can imagine the situation when you don't want to propagate default dimensions to the SingleMetric.
To keep existing usage untouched I suppose the default behavior should be to not propagate default dimensions. So the solution can be the additional keyword argument inherit_default_dimensions: bool = False
with single_metric("Name", MetricUnit.Count, 1, inherit_default_dimensions=True) as this_metric:
this_metric.add_dimension(name="Dim1", value="Val")
Alternative solutions
No response
Acknowledgment
- This feature request meets Lambda Powertools Tenets
- Should this be considered in other Lambda Powertools languages? i.e. Java, TypeScript