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.
I'm trying to log multiple values for a single metric using powertool's
Metricsclass.However when doing so I only get the last added value flushed.
Here is a minimal example which triggers the problem:
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.