Поиск  
Always will be ready notify the world about expectations as easy as possible: job change page
Feb 22

Setup Azure Logs Alerts & Notifications for application exceptions

Автор:
Anji Keesari
Источник:
Просмотров:
4717

Table of contents

Introduction

Monitoring and detecting application exceptions is crucial for maintaining the reliability and performance of your applications hosted on Azure. Azure Log Analytics and Azure Monitor provide powerful tools to help you achieve this.

In this article, I will provide step by step instructions for setting up Azure Logs Alerts and Notifications specifically for application exceptions.

Prerequisites

Before you begin, ensure you have the following prerequisites:

  • An Azure account with an active subscription.
  • A web application hosted on Azure
  • A Application Insights associated to the web application.
  • A web application configured to send logs data to Azure Application Insights.
  • An Azure Log Analytics workspace set up to collect logs from your application.
  • Diagnostics Settings configured for your application's logs to send exceptions to the Log Analytics workspace.

Step 1: Create Action Groups

Action Group allows you to define a set of notification and automated actions that can be triggered by alerts from various Azure services.

Step 1.1: Action Groups Structure

Before creating action groups, let me provide some valuable tips here.

The number and structure of action groups you need to create can vary based on your application team size and the nature of your project. It's important to modify your approach to meet your specific requirements and needs.

Here are a few suggestions:

  1. Single Action Group for all environments: You can opt for a single action group that covers all your environments. This approach simplifies management and is suitable for smaller teams.
  2. Separate Action Groups for each environment: You can set up separate action groups for individual environments. This provides more granularity and allows you to modify notifications and responses to each environment's unique characteristics.
  3. One for non-production and one for production: For smaller teams, it's often practical to create two action groups—one dedicated to non-production environments and the other focused on the production environment. This way, you can prioritize alerts and responses accordingly.

For larger applications with complex microservices architectures, consider creating separate action groups for each domain or team group. This approach ensures that alerts are directed to the right teams, facilitating efficient issue resolution.

The structure and number of action groups you create should align with your team's size, project complexity, and operational requirements.

Step 1.2: Create Action Groups

Here is the list of steps to create action group:

  1. Sign in to the Azure Portal.
  2. In the left navigation pane, click on "Monitor."
  3. Under "Alerts," click on "Action groups."
  4. Click on the "+ New action group" button.
  5. Under Resource group, select the appropriate resource group.
  6. In the "Basics" tab, provide a unique Name and Short Name for the action group.
  7. In the "Notifications" section, configure the action to notify relevant stakeholders for non-production environments. You can set up email notifications, SMS, or other preferred communication channels.
  8. Click "OK" to create the action group.

Action Group

Action Group

Action Group » Basic

Action Group » Basic

Action Group » Notification

Action Group » Notification

Action Group » Tags

Action Group » Tags

Step 1.3: Test Action Group

Before proceeding to the alert rule setup, test the action group by simulating an alert. This will ensure that notifications are properly configured and reaching the intended recipients.

Action Group » Test

Test Alerts

Test Alerts

Email from mail box

Email from mail box

Email from mail box

Email from mail box

Step 2: Create a new alert rule

  1. In the Azure Portal, under "Monitor," click on "Alert rules."
  2. Click the "+ New alert rule" button.

Step 2.1: Setup Conditions

  1. In the "Basics" tab, choose the appropriate Resource type and Resource for your application.
  2. Under the "Conditions" section, click on "+ Add condition."
  3. In the condition configuration: Choose "Custom log search" as the signal type.
  4. Click "Done" to save the condition.

Monitoring » Alert Rule

Monitoring » Alert Rule

or

Web App or Api App » Alert Rule

Web App or Api App » Alert Rule

Alert Rule » Condition

Alert Rule » Condition

Step 2.2: Write Log Query

The log query written should accurately filter and select the exceptions you want to monitor. Make sure it targets the relevant log data and time frame.

Write a log query that selects application exceptions. For example:

exceptions
| where timestamp > ago(1h)
AppServiceAppLogs
| where TimeGenerated > ago(30m)
| order by TimeGenerated desc
| take 100

Adjust the time range and query as per your requirements.

Alert Rule » Log Query

Alert Rule » Log Query

Step 2.3: Associate Action Group

  1. In the "Actions" section, click on "+ Add action group."
  2. Choose the action group created for the specific environment (non-production or production) where the alert will be triggered.
  3. Configure the alert action settings, including the severity and threshold.
  4. Click "OK" to associate the action group with the alert rule.

Alert Rule » Action Group

Alert Rule » Action Group

Alert Rule » Details

Alert Rule » Details

Alert Rule » Overview

Alert Rule » Overview

Step 2.4: Test Alert Rule

Before finalizing the alert rule, it's essential to test it by creating a simulated exception or by adjusting the log query to match actual exceptions. This ensures that alerts trigger as expected.

Test Alert Rule

Test Alert Rule

Conclusion

Setting up Azure Logs Alerts & Notifications for Application Exceptions is a proactive approach to identifying and addressing issues in your applications. By following the steps outlined in this guide, you can ensure that relevant teams are promptly notified when exceptions occur, allowing for timely troubleshooting and maintenance.

References

Похожее
May 12, 2023
Author: Love Sharma
Developing a robust, scalable, and efficient system can be daunting. However, understanding the key concepts and components can make the process more manageable. In this blog post, we’ll explore essential system design components such as DNS, load balancing, API Gateway,...
Feb 5
Author: Crafting-Code
Lesser-known techniques for optimizing SQL queries in a high-traffic application, especially when dealing with complex joins and indexing challenges The success of high-traffic applications hinges on the efficient performance of their underlying databases. As the complexity of SQL queries grows,...
May 12, 2023
Author: Alex Maher
Language Integrated Query (LINQ) is a powerful feature in C# .NET that allows developers to query various data sources using a consistent syntax. In this article, we’ll explore some advanced LINQ techniques to help you level up your skills and...
Sep 19
Author: Seliesh Jacob
Introduction Application Programming Interfaces (APIs) are the backbone of modern software development. They enable diverse applications to communicate and share data seamlessly, making it possible to integrate different systems and services effectively. Whether you’re building a simple API for a...
Написать сообщение
Тип
Почта
Имя
*Сообщение
RSS
Если вам понравился этот сайт и вы хотите меня поддержать, вы можете
Soft skills: 18 самых важных навыков, которыми должен владеть каждый работник
Стили именования переменных и функций. Используйте их все
10 историй, как «валят» айтишников на технических интервью
Функции и хранимые процедуры в PostgreSQL: зачем нужны и как применять в реальных примерах
Семь итераций наивности или как я полтора года свою дебютную игру писал
Вопросы с собеседований, которые означают не то, что вы думаете
Путеводитель по репликации баз данных
5 приемов увеличения продуктивности разработчика
Топ 8 лучших ресурсов для практики программирования в 2018
Использование SQLite в .NET приложениях
LinkedIn: Sergey Drozdov
Boosty
Donate to support the project
GitHub account
GitHub profile