In this blog we will learn how to monitor Azure function app using application insights. Below we will dive into these topics
- Overview of Application Insights
- Create Application Insights
- Configure Application Insights into Azure function app
- Viewing Application Insights
Azure Application Insights:
Azure Application Insights is an extensible Application Performance Management (APM) service. Used to monitor live web application. It will automatically detect performance anomalies. It includes powerful analytics tools to help diagnose issues and to understand what users do with the app. It’s designed to help continuously improve performance and usability. It works for apps on a wide variety of platforms including .NET, Node.js and Java EE, hosted on-premises, hybrid, or any public cloud. It integrates with your DevOps process, and has connection points to a variety of development tools.
It provides benefits as:
- Exceptions and performance diagnostics.
- Interactive data analysis.
- Azure diagnostics.
- Proactive detection.
Create Application Insights:
Step 1: To create a new Application insight, sign into the Azure portal. In the upper-left corner of the home page, select Create a resource. In the Search the Marketplace box, enter Application insights and select and press enter.
Step 2: Select Application Insights from the search results, and then select Create.
Step 3: Click on create button and enter required information and also configure log analytics workspace.
Step 4: Once you click on Create button, your application insights is ready to use.
Configure Application Insights into Azure function app:
Step 1: To create a new Function app, sign into the Azure portal. In the upper-left corner of the home page, select Create a resource. In the Search the Marketplace box, enter Function app and select and press enter
Step 2: Select Function app from the search results, and then select Create.
Step 3: Click on create button and enter basic required information as per below screenshot.
Step 4: Click on Monitoring tab and enable Application insights that you have created previously.
Step 5: Click on Create button, your function app is ready to use.
Step 6: Click on left navigation pane, select settings >> Application insights.
Create a Azure Function App via VS 2019:
The Azure Functions project template in Visual Studio creates a project that you can publish to a function app in Azure.
- From the Visual Studio menu, select File > New > Project.
- In Create a new project, enter functions in the search box, choose the Azure Functions template, and then select Next.
- In Configure your new project, enter a Project name for your project, and then select Create. The function app name must be valid as a C# namespace, so don’t use underscores, hyphens, or any other nonalphanumeric characters.
4. Select Create to create the function project and HTTP trigger function.
C# code :
5. Publish this function app on azure portal, as per below screenshot.
Viewing Application Insights:
Step 1: Select function app that you have publish and click on function app test run as per below screenshot and also open app insights on other tab to view the logs.
Step 2: App insights result gave the information that you have logged in your function app.
Hope this will help.