Monitoring Applications using Application Insights (2024)

Home / Monitoring Applications using Application Insights

Last updated : Dec 14, 2023.

Overview

Application Insights comes as part of Visual Studio. You get automatic instrumentation for ASP.NET developers and vital application telemetry data right out of the box; including usage, exceptions, requests, performance, and logs.

Monitor web apps—whether written in Java, Ruby, Python, PHP, Node.JS, or other languages—using open source SDKs. Install the Status Monitor on your existing Azure App Services and virtual machines through the Azure portal to get performance monitoring without needing to update and redeploy your application.

Visual Studio Application Insights is an extensible analytics service that monitors your live web application. With it you can detect and diagnose performance issues, and understand what users actually do with your app. It’s designed for developers, to help you continuously improve performance and usability. It works for apps on a wide variety of platforms including .NET, Node.js and J2EE, hosted on-premises or in the cloud.

It provides benefits as:

  • Exceptions and performance diagnostics.
  • Interactive data analysis.
  • Azure diagnostics.
  • Proactive detection.

Pre-requisites

In order to complete this lab you will need Visual Studio 2017. Click the button below to deploy a VS 2017 Community VM from the Azure marketplace.

Launch the virtual machine

Note: If you don’t have an Azure subscription, you can get one free through Visual Studio Dev Essentials

  • Visual Studio Team Services account. If you don’t have one, you can create from here

  • You can use the VSTS Demo Data generator to provison a project with pre-defined data on to your Visual Studio Team Services account. Please use the My Health Clinic template to follow the hands-on-labs.

  • If you are not using the VSTS Demo Data Generator, you can clone the code from here

Exercise 1: Creating Instrumentation Key

  1. Go to Azure Portal from here

  2. Click on + New icon to create a new Application Insights.

    Monitoring Applications using Application Insights (1)

  3. Search for Application Insights in the search box.

    Monitoring Applications using Application Insights (2)

  4. Click on Create.

    Monitoring Applications using Application Insights (3)

  5. Fill in the following details:-

    • Name: Provide the name as mhcapp
    • Application Type: Select ASP.NET web application as the type
    • Subscription: Select your subscription
    • Resource Group: Create a new resource group with the name mhcapp
    • Location: Select desired location

    Monitoring Applications using Application Insights (4)

  6. Browse to the resource group mhcapp which was created and click on the app insights resource.

    Monitoring Applications using Application Insights (5)

  7. Copy the the Instrumentation Key from the top as shown below.

    Monitoring Applications using Application Insights (6)

Exercise 2: Configure Application Insights

In this lab we have the existing 01_Demos_ASPNET5 .NET Core application, when creating all the infrastructure for the labs, we will need the newly created Instrumentation key to be configured in this project so Application Insights can work.

  1. Open Visual Studio 2017.

    Monitoring Applications using Application Insights (7)

  2. Open 01_Demos_ASPNET5 solution. Under MyHealth.Web project locate the appsettings.json file.

    Monitoring Applications using Application Insights (8)

    Monitoring Applications using Application Insights (9)

  3. Locate this line from that file.

     "InstrumentationKey": "YOUR_INSTRUMENTATION_KEY"
  4. Substitute the text YOUR_INSTRUMENTATION_KEY with the key of your existing Application Insights service.

    Monitoring Applications using Application Insights (10)

  5. Application Insights comes in the form of a Nuget package. Review the project.json file of the web project and look for the Application Insights package added.

    Monitoring Applications using Application Insights (11)

  6. Open the file Startup.cs.

    Monitoring Applications using Application Insights (12)

    Note: In this file we give the startup options for the website, we need to configure Application Insights to read the configuration.
    Unlike the setup for other Application Insights SDKs, adding the SDK doesn’t automatically configure a range of modules to collect different kinds of telemetry. We’re going to add the modules for Telemetry and Exception so we need to do a couple of modifications to the Startup.cs

    Monitoring Applications using Application Insights (13)

  7. Locate the method ConfigureServices and check the line services.AddApplicationInsightsTelemetry(Configuration);.

    This will load the configuration for Application Insights from the configuration file for the site.

    Monitoring Applications using Application Insights (14)

  8. Now locate the method Configure and check these lines:

     * app.UseApplicationInsightsRequestTelemetry(); * app.UseApplicationInsightsExceptionTelemetry();

    With these two lines we are configuring the application to send Telemetry information as well as Exception information to the configured Application Insights.

    Monitoring Applications using Application Insights (15)

  9. Locate the file _Layout.cshtml inside the Views | Shared folder in the web application and open it.

    Note: We need to configure also the client-side reporting of Application Insights telemetry, which will allow us to have telemetry data of what is happening at the client side of our web application.
    This _Layout.cshtml page in ASP.NET is the base page for all the rest of the pages for the application, so adding this code here will add the code in the rest of the pages of the application at runtime.

    Monitoring Applications using Application Insights (16)

    Monitoring Applications using Application Insights (17)

  10. Look at the first line @inject Microsoft.ApplicationInsights.Extensibility.TelemetryConfiguration TelemetryConfiguration. This injects the configuration part of Application Insights to be available for the client-side scripting.

    Monitoring Applications using Application Insights (18)

  11. Now look at the line @Html.ApplicationInsightsJavaScript(TelemetryConfiguration). This will add the needed Javascript code in the page so Application Insights client-side telemetry sends information about client-side execution.

    Monitoring Applications using Application Insights (19)

Exercise 3: Viewing Telemetry

Now that we have configured the application to send telemetry data to Application Insights, let’s review how to send the date and see the telemetry from Visual Studio and the Azure Portal.

  1. Launch the application from Visual Studio and navigate through the application.

    Monitoring Applications using Application Insights (20)

  2. Stop the application from Visual Studio. Even when debugging the application locally it will start sending information to Application Insights. Now we will review the information captured by Application Insights.

  3. Right click on the project MyHealth.Web in the Solution Explorer and select Application Insights | Search Debug Session Telemetry.

    Monitoring Applications using Application Insights (21)

    This view shows telemetry generated in the server side of your app. Experiment with the filters, and click any event to see more detail.

    Monitoring Applications using Application Insights (22)

  4. Right click again on the project MyHealth.Web in the Solution Explorer and select Application Insights | Open Application Insights Portal.

    Monitoring Applications using Application Insights (23)

    The portal opens on a view of the telemetry from your app.

    Monitoring Applications using Application Insights (24)

  5. Click on Server response time.

    Monitoring Applications using Application Insights (25)

    This opens the azure blade with all the information about the server response time of all the calls which have ocurred to the application, and its times. So we can detect for example bottlenecks in our application in particular pages.

    Monitoring Applications using Application Insights (26)

  6. Click on Page View Load Time.

    Monitoring Applications using Application Insights (27)

    We have a lot of other metrics avaliable, like Page view load time which measures times from client side informing how long the pages take to load in the client side.

    Monitoring Applications using Application Insights (28)

    Click again, in this new blade in Page View Load Time in the upper part, you can continue drilling down through all the information in Application Insights.

    Monitoring Applications using Application Insights (29)

Exercise 4: Adding Application Insights to New Web Application

Let’s create a new web application and review how can we add Application Insights from the beginning.

  1. Open Visual Studio. Select File | New Project.

    Monitoring Applications using Application Insights (30)

  2. Select Visual C# | .NET Core | ASP.NET Core Web Application, ensure to mark the checkbox Add Application Insights to Project.

    Monitoring Applications using Application Insights (31)

    In this step we are adding Application Insights to the project, if you want to review default values or make any change on them, click on Configure Settings

    Monitoring Applications using Application Insights (32)

  3. Click Ok on the next screen.

    Monitoring Applications using Application Insights (33)

  4. Open appsetings.json file and check the Instrumentation Key has been added.

    Monitoring Applications using Application Insights (34)

    As we saw in this lab configuring Application Insights, we have now the key already added from the beginning. The Nuget package, Startup.cs file and _layout.cshtml files has been modified to include Application Insights.

  5. Open Startup.cs file, as you also see the lines for Application Insights configuration has already been added automatically.

    Monitoring Applications using Application Insights (35)

  6. Open _Layout.cshtml and check the particular line for client-side Javascript telemetry.

    Monitoring Applications using Application Insights (36)

  7. Open project.json file and check the Application Insights package has also been added.

    Monitoring Applications using Application Insights (37)

From this point we can also run the application, and see telemetry data as we did at the beginning of this same lab.

Monitoring Applications using Application Insights (2024)
Top Articles
How Juice Plus Might Interact Negatively With Medications | Livestrong.com
171 people signed and won this petition
Is Paige Vanzant Related To Ronnie Van Zant
Ghosted Imdb Parents Guide
Aadya Bazaar
All Obituaries | Ashley's J H Williams & Sons, Inc. | Selma AL funeral home and cremation
104 Presidential Ct Lafayette La 70503
Top Hat Trailer Wiring Diagram
Nonuclub
Wordle auf Deutsch - Wordle mit Deutschen Wörtern Spielen
Regal Stone Pokemon Gaia
Accuradio Unblocked
Magic Mike's Last Dance Showtimes Near Marcus Cedar Creek Cinema
Bj Alex Mangabuddy
Craigslist Toy Hauler For Sale By Owner
Jellyfin Ps5
Welcome to GradeBook
Scotchlas Funeral Home Obituaries
Schedule An Oil Change At Walmart
Spn 520211
Terry Bradshaw | Biography, Stats, & Facts
Makemv Splunk
Znamy dalsze plany Magdaleny Fręch. Nie będzie nawet chwili przerwy
Paris Immobilier - craigslist
Table To Formula Calculator
Pronóstico del tiempo de 10 días para San Josecito, Provincia de San José, Costa Rica - The Weather Channel | weather.com
27 Fantastic Things to do in Lynchburg, Virginia - Happy To Be Virginia
Bfsfcu Truecar
Vadoc Gtlvisitme App
Shauna's Art Studio Laurel Mississippi
Abga Gestation Calculator
Ripsi Terzian Instagram
Federal Student Aid
Zero Sievert Coop
Giantess Feet Deviantart
Pokemon Reborn Locations
Section 212 at MetLife Stadium
Doordash Promo Code Generator
Cpmc Mission Bernal Campus & Orthopedic Institute Photos
Bill Manser Net Worth
Trivago Anaheim California
Sarahbustani Boobs
Rush Copley Swim Lessons
Aurora Southeast Recreation Center And Fieldhouse Reviews
Marcel Boom X
4Chan Zelda Totk
Smoke From Street Outlaws Net Worth
Quest Diagnostics Mt Morris Appointment
March 2023 Wincalendar
7 Sites to Identify the Owner of a Phone Number
E. 81 St. Deli Menu
Heisenberg Breaking Bad Wiki
Latest Posts
Article information

Author: Merrill Bechtelar CPA

Last Updated:

Views: 5905

Rating: 5 / 5 (50 voted)

Reviews: 89% of readers found this page helpful

Author information

Name: Merrill Bechtelar CPA

Birthday: 1996-05-19

Address: Apt. 114 873 White Lodge, Libbyfurt, CA 93006

Phone: +5983010455207

Job: Legacy Representative

Hobby: Blacksmithing, Urban exploration, Sudoku, Slacklining, Creative writing, Community, Letterboxing

Introduction: My name is Merrill Bechtelar CPA, I am a clean, agreeable, glorious, magnificent, witty, enchanting, comfortable person who loves writing and wants to share my knowledge and understanding with you.