Description
Use case
In my environment, I have two serverless applications: one built using Python and the other using TypeScript/Node.js. Both utilize AWS Powertools. However, I have noticed a discrepancy between the two in how they handle CloudWatch cold start metrics by default.
In the Node.js Powertools, the middleware automatically includes default dimensions such as service name, function name, and additional custom dimensions.
.use(logMetrics(metrics, {
throwOnEmptyMetrics: false,
captureColdStartMetric: true,
defaultDimensions: {'Environment': process.env.ENV!}
}))
On the other hand, in the Python Powertools, the cold start metric only includes the function and service name by default, with no apparent way to extend or override this behavior using custom dimensions without completely managing the cold start metric manually.
@metrics.log_metrics(capture_cold_start_metric=True, default_dimensions={"Environment": ENVIRONMENT})
def lambda_handler(event: dict, context: LambdaContext):
...
This creates an inconsistency between the two libraries and forces us to write additional boilerplate code in Python if we want additional dimensions to be recorded along with the ColdStart metric, while the Node.js implementation provides a more seamless experience.
FWIW:
The docs are accurate in both cases:
Python's page says:
If it's a cold start invocation, this feature will:
Create a separate EMF blob solely containing a metric named ColdStart
Add function_name and service dimensions
and TypeScript's page says:
If it's a cold start invocation, this feature will:
Create a separate EMF blob solely containing a metric named ColdStart
Add the function_name, service and default dimensions
Solution/User Experience
Ideally, the default_dimensions
provided to the log_metrics decorator would be used when recording the cold start metric in Python.
Alternative solutions
As mentioned, an alternative is to continue to have users manually handle the cold start metrics themselves to support adding custom dimensions to the ColdStart metric in Python.
Acknowledgment
- This feature request meets Powertools for AWS Lambda (Python) Tenets
- Should this be considered in other Powertools for AWS Lambda languages? i.e. Java, TypeScript, and .NET
Metadata
Metadata
Assignees
Labels
Type
Projects
Status