Metric filter for logs JSON data with @ property names

1

For Logs Insights, it seems rather straightforward to query/filter against JSON data with property names prefixed with '@'

| filter @@level like /Error/ and @@msgtxt in ["event 1", "event 2"]

However when it comes to defining filter patterns for custom metrics, the JSON property matching selector does not appear to like '@'

https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/FilterAndPatternSyntax.html

{ $.@msgtxt = "event 1" || $.@msgtxt = "event 2" }

will throw

An error occurred while testing the subscription filter.
Invalid character(s) in term '$.@'

How should the proper metric filter pattern be like?

Edited by: icelava on Oct 5, 2021 11:33 PM Typo

icelava
asked 3 years ago1387 views
3 Answers
0

The documentation does not explicitly state so, but OR filters can also apply to whole phrases instead of just standalone words.

?"Event 1" ?"Event 2"

So have to fall back to plain text-phrase matching instead of JSON selector matching.

Edited by: icelava on Oct 6, 2021 4:28 AM

icelava
answered 3 years ago
0

I need to filter on JSON properties with @ as a prefix as well. Can Amazon come out and explicitly say whether they don't support fields which start with special characters and that it was a significant oversight or give us a way around this? It's already painful to use this tool after coming from other log providers which support this or show logs from recent to oldest instead.

SD123
answered 3 years ago
0

Considering the fact that many frameworks, such as "Serilog", use the character @ as the prefix for the log properties, it is very unconvenient that AWS CloudWatch filters don't support this format.

answered 6 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions