I'm programming a DataDog monitor, and I want to include the attributes of the event in the notification message. My query looks like this:
logs("service:<SERVICE NAME> @level:ERROR @logger_name:<LOGGER NAME>").index("main").rollup("count").by("@stack_trace,@logger_name,@organization").last("5m") > 0
Here's my problem: some of the errors that I want to monitor don't have the attributes listed in the query.
I'm looking to make all the attributes optional: stack_trace
, logger_name
& organization
. I want my monitor to look for errors, then if they have the attributes, show them in the notification. If not, I want there still to be a notification but a question mark is printed instead of the attribute.
Is that possible?
Here's what I can up with. It's not an ideal solution, but it works...
To be able to use the log attributes in the notification message, you need to include them in the monitor's query. To make the attributes optional, I used a redundant bi-condition, i.e.
@organization:* OR NOT @organization:*
. This query returns logs that have the@organization
attribute, and logs that don't.My full query ended up looking like this:
It's pretty messy, but that's the best solution I could come up with.
If the attributes are not included in the log, they are left as a blank string. Knowing this, you can check for a blank string, and replace it with a ❓ for easier formatting.
So in the notification message text box, I had the following code: