Saturday 23 September 2023

How to implement Azure Application Insight in Web app?

Azure Application Insights is a powerful service for monitoring and gaining insights into the performance and usage of your web applications. To implement Application Insights in a web app, follow these steps:

Step 1: Create an Application Insights resource

Log in to the Azure portal (https://portal.azure.com).

Click on "+ Create a resource" on the left-hand menu.

Search for "Application Insights" in the Azure Marketplace.

Select "Application Insights" from the search results.

Click the "Create" button to create a new Application Insights resource.

Fill in the required details like Subscription, Resource Group, Region, and give it a name. You can also configure the pricing tier based on your needs. Click "Review + create" and then "Create" to provision the resource.

Step 2: Instrument your Web App

Now that you have an Application Insights resource, you need to instrument your web app to send telemetry data to it. This involves adding the Application Insights SDK to your application code. The exact steps may vary depending on the technology stack of your web app.

Below are some common scenarios:

ASP.NET Core Application (C#):

Open your ASP.NET Core project in Visual Studio.

Install the Microsoft.ApplicationInsights.AspNetCore NuGet package if not already installed:


Install-Package Microsoft.ApplicationInsights.AspNetCore

In the Startup.cs file, add the following code in the ConfigureServices method to configure Application Insights:


services.AddApplicationInsightsTelemetry(Configuration["ApplicationInsights:InstrumentationKey"]);
In the appsettings.json file, add your Application Insights Instrumentation Key:


"ApplicationInsights": {
  "InstrumentationKey": "YOUR_INSTRUMENTATION_KEY"
}

Node.js Application:

Install the applicationinsights npm package:


npm install applicationinsights --save

In your Node.js code, require and configure Application Insights using your Instrumentation Key:


const appInsights = require("applicationinsights");
appInsights.setup("YOUR_INSTRUMENTATION_KEY").start();

Other Platforms: Application Insights has SDKs and integrations for various platforms. You can find specific instructions for your technology stack in the official documentation.

Step 3: Verify Integration

After instrumenting your web app, you can verify if telemetry data is being sent to Application Insights:

Run your web app.

In the Azure portal, navigate to your Application Insights resource.

Go to the "Overview" or "Logs" section to see telemetry data, including requests, exceptions, and performance metrics.

Step 4: Analyze and Monitor

With Application Insights set up, you can use it to:

  • Monitor application performance and detect issues.
  • Create custom dashboards and alerts.
  • Analyze user behavior and track conversions.
  • Debug and diagnose problems using distributed tracing.
Application Insights is a powerful tool for gaining insights into your web app's behaviour and performance, helping you improve its reliability and user experience.

No comments:

Post a Comment

Note: only a member of this blog may post a comment.