Omitted dimensions in CloudWatch Metrics
Dunedan opened this issue · 2 comments
When adding a dimension with an integer value, the dimension appears as expected in the output generated by aws-embedded-metrics
, however it causes CloudWatch Metrics to omit all dimensions for this log record when ingesting it. That's probably because CloudWatch Metrics requires all dimension values to be strings, but it's still quite surprising behavior. To avoid this problem, I suggest that aws-embedded-metrics
should convert all non-string dimension values to strings when serializing them.
The same problem probably appears if dimension names or values contain characters not permitted by CloudWatch Metrics. To avoid problems there, stripping space and non-ASCII characters from dimension names and values would be great as well.
Here is a sample serialized record, which does end up without any dimension in CloudWatch Metrics. The value of the status_code
dimension is an integer there, causing the problem.
{
"LogGroup": "sample-lambda",
"ServiceName": "sample-lambda",
"ServiceType": "AWS::Lambda::Function",
"status_code": 404,
"executionEnvironment": "AWS_Lambda_python3.8",
"memorySize": "1024",
"functionVersion": "$LATEST",
"logStreamId": "2020/09/01/[$LATEST]bacf5b45a2af1917a4a736b4427dc0bc",
"_aws": {
"Timestamp": 1598940148182,
"CloudWatchMetrics": [
{
"Dimensions": [
[
"LogGroup",
"ServiceName",
"ServiceType",
"status_code"
]
],
"Metrics": [
{
"Name": "http_calls",
"Unit": "Count"
}
],
"Namespace": "foo"
}
]
},
"http_calls": 1
}
I need to do some more research on this one. I expected numeric dimensions should be supported. Agree on stripping non-ASCII characters.