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
질문됨 3년 전1414회 조회
3개 답변
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
답변함 3년 전
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
답변함 3년 전
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.

답변함 7달 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠