Description
Key information
- RFC PR:
- Related issue(s), if known:
- Area: Metrics
- Meet tenets: Yes
Summary
Add a default dimension named "service" with a value of the provided service name if it exists (via Metrics constructor or env var).
Motivation
This would simplify what I think is the most common use case where users don't need multiple dimensions. It would enable creation of simple custom metrics without needing to think about the underlying CloudWatch dimension construct.
Proposal
With PR #60 the metrics interface was changed to behave more similarly to the other core utils, by accepting a
service
parameter or reading thePOWERTOOLS_SERVICE_NAME
env var. In the metrics util, this service is translated to the namespace used for metrics. We could also use this value to set a dimension by default:{"name": "service", "value": service_name}
. This could be handled in theMetricManager
constructor, by adding to thedimension_set
dict if the service parameter is set.
This would remove the need to make a call toadd_dimension
, so the simplest implementation could look like:
metrics = Metrics(service="ServerlessAirline")
@metrics.log_metrics
def lambda_handler():
# without this change we have to make a call to add dimensions here
metrics.add_metric(name="Something", unit="Count", value=1)
Drawbacks
- We would potentially create additional billable custom metrics for users who want specify their own dimensions.
- The migration path is a bit awkward for anyone who is currently using the
POWERTOOLS_SERVICE_NAME
env var. Right now they are forced to use add_dimension, so they will start to see another dimension for all their metrics when they upgrade.
Rationale and alternatives
- What other designs have been considered? Why not them?
- What is the impact of not doing this?
Users of the library need to understand how CloudWatch metrics dimensions work. In my opinion this is quite hard to grasp from documentation. If we don't abstract this away by implementing this change, users who are not already familiar with CloudWatch can be faced with a time consuming trial/error cycle to discover how to properly use dimensions in their custom metrics. This is compounded by the fact that custom metrics can't be deleted - if mistakes are made here they will pollute the dashboard for 2 weeks until they expire.
Unresolved questions
Optional, stash area for topics that need further development e.g. TBD
Metadata
Metadata
Assignees
Type
Projects
Status