cmeeren
cmeeren

Reputation: 4210

How to get alerted for new (unique) errors

A useful feature of application monitoring services is sending alerts (e.g. emails) each time a new, unique error/problem/exception occurs (i.e., not for each occurrence). Either only the very first time, or at most once per X time (a day or week or such). This is, for example, possible with Visual Studio App Center. Unfortunately I haven't been able to find any such feature in Application Insights.

For clarification, a "new, unique error/problem/exception" can be thought of as a specific log statement in the code. I'm using Serilog, so all logged traces/exceptions have a MessageTemplate property which may help. But ideally the "problem ID" would be based on the code location, too (since multiple log statements may use the same message template).

The best lead I have found is the ability to send alerts based on a custom analytics query, but I'm not sure if it's possible to write a query that can give a behaviour similar to (if not exactly like) to what I describe above.

Is something similar to the behaviour I describe above possible to achieve with Application Insights? If it's possible through a custom query, how might such a query look?

Upvotes: 3

Views: 1534

Answers (1)

Ivan Glasenberg
Ivan Glasenberg

Reputation: 29950

Just through UI of azure portal, it's hard or impossible to achieve your first requirement: alert only the very first time. But you can try to use app insights rest api to fetch the data, then use code to implement your logic.

There is a similar solution(not exactly like you describe) for alert once per X time. The steps are as below:

1.Nav to azure portal -> you application insights -> Alerts -> new alert rule -> in the Condition, click Add button -> then select "Custom Log Search"

2.In the "search query" textbox, write your query like below:

exceptions
| where xxxx

Note that in the where clause, use some properties to identify the unique error.

3.Then in the "Alert logic", use the following settings: Based on: Number of results, Operator: Greater than, Threshold value: 0

4.In the "Evaluated based on", set proper value for Period(max value is 2880 minutes) / Frequency(max value is 1440 minutes).

So if you want to trigger alert 1 time per day, you can set Period to 1440 minutes, set Frequency to 1440 minutes. But you also need to note that, if in the next day, there is no such specified error, it will not trigger in the next day.

Upvotes: 1

Related Questions