AZ-400: Designing and Implementing Microsoft DevOps Solutions

Analyze Metrics

Inspect distributed tracing by using Application Insights

Application Insights is part of Azure Monitor and Microsoft’s application performance management (APM) service. It provides real-time telemetry, automatic anomaly detection, powerful analytics, and seamless integration with Azure services and DevOps toolchains. In this guide, you’ll learn how to enable, configure, and explore distributed tracing for your .NET web app using Application Insights.

Table of Contents

  1. Key Features
  2. Enable Application Insights in Azure Portal
  3. Add the Application Insights SDK
  4. Configure the Instrumentation Key
  5. Explore Telemetry in Application Insights
  6. Configure Alerts
  7. Diagnostic Settings & Log Analytics
  8. References

Key Features

FeatureDescription
Real-time TelemetryMonitor requests, dependencies, and exceptions as they occur.
Anomaly DetectionAutomatic alerts on performance deviations and failures.
Powerful AnalyticsAd-hoc queries and customizable charting with Log Analytics.
DevOps & Toolchain IntegrationPlug-ins for Visual Studio, Azure Pipelines, GitHub Actions, etc.

Enable Application Insights in Azure Portal

  1. In the Azure Portal, create or select your Web App (e.g., KodeKloud Support).
  2. Under Deployment > Networking, configure required networking options.
  3. Navigate to Monitor and Secure, toggle Application Insights to Yes.
  4. Choose an existing resource or create a new one for KodeKloud Support.
  5. (Optional) Enable Defender for additional security monitoring.
  6. Click Review + create to finalize.

Note

Ensure your Azure role has Monitoring Contributor permissions before enabling Application Insights on the resource.


Add the Application Insights SDK

Open your project in Visual Studio and update your front‐end page if needed. For example, your Index.cshtml might look like this:

@page
@model IndexModel
@{
    ViewData["Title"] = "Home page";
}
<div class="hero-image" style="background-image: url('/img/frontpage.jpg'); background-size: cover; background-position: center;">
    <h1 class="display-4 text-white">Welcome to Kode Kloud</h1>
</div>
<div class="container mt-4">
    <div class="row">
        <div class="col-md-8 offset-md-2 text-center">
            <h2>Expert Tech Support at Your Service</h2>
            <p class="lead">
                At Kode Kloud, our dedicated tech support team is committed to providing you with exceptional service. With our extensive knowledge and passion for problem-solving, we're here to ensure your team runs smoothly, allowing you to focus on what matters most – your success.
            </p>
        </div>
    </div>
</div>

Then install the Application Insights SDK package:

PM> Install-Package Microsoft.ApplicationInsights.AspNetCore

Configure the Instrumentation Key

  1. In the Azure Portal, go to Monitor > Application Insights > KodeKloud Support.
  2. Under Instrument your application, select .NET and the Recommended Basic level.
  3. Enable the Profiler and click Apply.

The image shows a Microsoft Azure portal page for "KodeKloudSupport" with a focus on Application Insights settings. It includes options for instrumenting applications with various programming languages and settings for collection level, profiler, and snapshot debugger.

  1. Copy the Instrumentation Key, then add it to appsettings.json:
{
  "ApplicationInsights": {
    "InstrumentationKey": "YOUR_INSTRUMENTATION_KEY"
  }
}
  1. Update your application startup (Program.cs or Startup.cs):
using Microsoft.ApplicationInsights.Extensibility;

var builder = WebApplication.CreateBuilder(args);

// Add Application Insights telemetry
builder.Services.AddApplicationInsightsTelemetry();

var app = builder.Build();
app.Run();

Warning

Do not commit your Instrumentation Key to public repositories. Store secrets securely using Azure Key Vault or environment variables.

Build and run locally to verify telemetry, then deploy through your CI/CD pipeline.


Explore Telemetry in Application Insights

After deployment, navigate to Monitor > Application Insights > KodeKloud Support.

Overview Dashboard

The Overview dashboard presents high-level metrics:

  • Failed requests
  • Server response time
  • Server requests
  • Availability

The image shows a Microsoft Azure dashboard for "KodeKloudSupport," displaying metrics such as usage, reliability, responsiveness, and browser performance with various graphs and statistics.

Live Metrics Stream

  1. Go to Live Metrics and reset the view.
  2. Generate traffic to monitor request rate, duration, CPU usage, and memory in real time.

The image shows a Microsoft Azure dashboard displaying live metrics for "KodeKloudSupport," including graphs for incoming and outgoing requests, overall health, and server performance.

Live metrics are ideal for high-load scenarios and can be displayed on a team dashboard.

Application Map

The Application Map visualizes components, dependencies, instance counts, and response times. It also highlights top failures and slowest requests.

The image shows a Microsoft Azure Application Insights dashboard for "KodeKloudSupport," displaying an application map with metrics such as 1 instance, 301.7 microseconds response time, and 39,000 calls. It also highlights top failing requests and slowest requests on the right panel.

Performance

Review operations by response time to identify slow dependencies or endpoints.

The image shows a Microsoft Azure dashboard displaying performance metrics for "KodeKloudSupport," including graphs of request counts and operation durations. It features various tabs and options for analyzing server performance data.

Failures

Inspect error types and counts. In this demo, we intentionally generated 4,800 HTTP 404 errors.

The image shows a Microsoft Azure Application Insights dashboard displaying failure analytics for "KodeKloudSupport," highlighting a high number of 404 response codes.

Availability

Track uptime and response trends over time to assess reliability.

The image shows a Microsoft Azure dashboard for "KodeKloudSupport" with metrics on failed requests, server response time, server requests, and availability over the past hour. It includes graphs and various monitoring options on the left sidebar.


Configure Alerts

Define alert rules to get notified when metrics cross thresholds.

MetricConditionThreshold
Failed requestsGreater than3 per minute
Response timeAbove average500 ms
CPU usageExceeds80%
  1. In the portal, choose Alerts > New alert rule.
  2. Select the target resource and signal type (e.g., Failed requests).
  3. Set the condition logic and threshold.

The image shows a Microsoft Azure interface for creating an alert rule, specifically for monitoring failed requests. It includes options for setting alert conditions, logic, and a preview graph of failed request counts over time.

  1. On Actions, choose or create an action group to send email, SMS, or webhook notifications.

The image shows a Microsoft Azure portal interface for creating an alert rule, specifically on the "Actions" tab, where users can configure quick actions and select notification methods like email.

Tip: Pin custom metric charts to your dashboard for quick visibility.

The image shows a Microsoft Azure dashboard for KodeKloudSupport, displaying metrics selection options and chart settings for monitoring application insights.


Diagnostic Settings & Log Analytics

  1. Under Diagnostic settings, configure streaming export of logs and metrics to storage, Event Hubs, or Log Analytics.

The image shows the "Diagnostic settings" page in Microsoft Azure for "KodeKloudSupport," where users can configure the export of platform logs and metrics. It includes options to add diagnostic settings and lists various data types that can be collected.

  1. Use Log Analytics to run Kusto queries on your telemetry and logs for advanced diagnostics.

Note

Leverage Log Analytics workspaces to correlate Application Insights data with other Azure monitor logs.


References

Watch Video

Watch video content

Previous
Analyze metrics by using collected telemetry including usage and application performance