Repository navigation
Closed
Labels
feature-requestfeature request
Description
I'm trying to log multiple values for a single metric using powertool's Metrics class.
However when doing so I only get the last added value flushed.
Here is a minimal example which triggers the problem:
#!/usr/bin/env python3
import json
from aws_lambda_powertools import Metrics
from aws_lambda_powertools.metrics import MetricUnit
metrics = Metrics(namespace="Test", service="Test")
@metrics.log_metrics
def handler(event, context):
metrics.add_metric(name="TestMetric", unit=MetricUnit.Count, value=1)
metrics.add_metric(name="TestMetric", unit=MetricUnit.Count, value=5)
handler(None, None)The code above produces the following output (formatted for better readability):
{
"_aws": {
"Timestamp": 1600250139457,
"CloudWatchMetrics": [
{
"Namespace": "Test",
"Dimensions": [
[
"service"
]
],
"Metrics": [
{
"Name": "TestMetric",
"Unit": "Count"
}
]
}
]
},
"service": "Test",
"TestMetric": 5.0
}What I'd expect instead would be the following:
{
"_aws": {
"Timestamp": 1600250139457,
"CloudWatchMetrics": [
{
"Namespace": "Test",
"Dimensions": [
[
"service"
]
],
"Metrics": [
{
"Name": "TestMetric",
"Unit": "Count"
}
]
}
]
},
"service": "Test",
"TestMetric": [1.0, 5.0]
}I'm not sure if this is a bug or if I'm missing something from the documentation, but to me it currently looks that logging multiple values for a single metric isn't possible without flushing manually between adding them.
Reacted by Tom Mc
Metadata
Metadata
Assignees
Labels
feature-requestfeature request
Type
Projects
- StatusShow more project fieldsTriage
Activity
heitorlessa commentedon Sep 16, 2020
hey @Dunedan - This is not a bug but a known behaviour of Embedded Metric Format (EMF) feature we use for creating metrics async. It only supports one value per unique key name - If you add multiple values it'll override with the last one.
For that and other purposes, we created the
with single_metriccontext manager so it'll create one metric and flush it automatically.I thought of having another API for that would keep multiple values for the same metric, and then flush them at the end as a workaround to EMF specification - But not entirely sure on the value and UX yet. If you think this is a good idea, please feel free to write up a RFC to discuss more about it :)
Dunedan commentedon Sep 16, 2020
Are you sure that this is a limitation of EMF?
The EMF specification suggests otherwise:
Also
aws-embedded-metrics-pythonimplements it as I would expect it and I believe such records are properly handled by CloudWatch Metrics.heitorlessa commentedon Sep 16, 2020
heitorlessa commentedon Sep 16, 2020
@Dunedan just confirmed with the CloudWatch team - This was added recently, it wasn't in the original implementation.
Added the feature request label, and we'll implement this to be available in the next release 1.6.0 this month.
Thanks for flagging it, much much appreciated
heitorlessa commentedon Sep 18, 2020
hey @Dunedan - @cakepietoast just finished implementing it, and as I mentioned before, it'll be available in the next release.
Thanks for flagging this and letting us know about the EMF update, much appreciated!
mwarkentin commentedon Sep 22, 2020
This can be closed now :)
to-mc commentedon Sep 22, 2020
Fixed in 1.6.0