Introduction to Azure Application Insights
What is Azure Application Insights?
Microsoft Azure offers Application Insights as a tool for monitoring application performance and tracking software behaviour. It gives software developers real-time observability into web applications across development, staging, and production environments.
Instead of manually checking logs or waiting for users to report bugs, Application Insights continuously captures background diagnostic signals (telemetry) to help you keep applications fast, reliable, and secure.
What Key Telemetry Does It Collect?
When Application Insights is configured in a .NET or ASP.NET Core project, it can gather useful diagnostic information about application activity, performance, and errors.
- HTTP Requests: Tracks incoming web traffic, endpoint calls, client locations, and HTTP response codes.
- Request Duration: Measures how fast your app processes each request to flag slow- performing routes.
- Exceptions & Failures: Helps identify when an application encounters errors or cannot complete an operation successfully. It provides diagnostic details about the failure, including stack trace information where available, so developers can investigate the underlying cause and determine the appropriate fix.
- Dependencies: Monitors external outgoing calls such as SQL database queries, Redis caches, or REST APIs.
- Application Logs: Captures system logs created using ILogger or custom trace logs.
- Performance Metrics: Tracks server CPU load, memory utilization, and thread counts.
- Usage & Availability: Continuously verifies app uptime through automated health ping tests.
Real-World Example
If a live .NET application suddenly begins throwing 500 Internal Server Errors during checkout, Application Insights allows developers to immediately:
- Identify the POST endpoint associated with the failed transaction and examine its response details.
- View the full stack trace of the unhandled exception.
- See If a slow database query or timed-out payment API dependency caused the failure.
Why do we need Application Insights in a .NET application
Consider a real-world scenario.
You have deployed an ASP.NET Core Web API to Azure.
Your application architecture looks like this:
User → .NET API → SQL Database → External API
After deployment, users start reporting that the application is slow. Without proper monitoring, you may have to manually check different application logs, database performance, and external services. With Application Insights, you can investigate the request and its related telemetry from one monitoring solution.For example:
Application Insights can help you understand how long each part of the request took and whether any part failed.
How Application Insights works with .NET
The basic architecture is:
The Application Insights SDK captures telemetry from your application, such as requests, dependencies, exceptions, and performance data, and securely sends it to the Application Insights resource in Azure for monitoring and analysis.
Step by Step: How we are connecting with Azure Application Insights:
Step 1: Create Application Insights in Azure
Start by setting up an Application Insights resource through the Azure Portal.
Go to:
Azure Portal → Search → Application Insights → Create
Provide the required information such as:
- Subscription:
Cloud-Core-Services-PayAsYouGo - Resource Group: rg-dotnet-engine-eastus
- Application Insights Name: appi-order-processing-service
- Region: Central India
- Log Analytics Workspace: law-platform-diagnostics-workspace
Once the resource is successfully created, Azure generates a Connection String. This connection string acts as the link between your .NET application and Azure Application Insights, allowing your application to send telemetry and monitoring data to Azure.
Step 2: Install Application Insights in the .NET Application
For an ASP.NET Core application, install the Application Insights SDK package:
Microsoft.ApplicationInsights.AspNetCore
You can install it using Visual Studio NuGet Package Manager or the .NET CLI.
Example:
dotnet add package Microsoft.ApplicationInsights.AspNetCore
Microsoft.ApplicationInsights.AspNetCore
You can install it using Visual Studio NuGet Package Manager or the .NET CLI.
Example:
dotnet add package Microsoft.ApplicationInsights.AspNetCore
This package provides the integration required to collect Application Insights telemetry from the ASP.NET Core application.
Step 3: Configure Application Insights
In a modern ASP.NET Core application, Application Insights can be registered in Program.cs.
Example:
Example:
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddApplicationInsightsTelemetry();
builder.Services.AddControllers();
var app = builder.Build();
app.MapControllers();
app.Run();
{
"ApplicationInsights": {
"ConnectionString": "YOUR_CONNECTION_STRING"
}
}You can then provide the Application Insights configuration through application configuration.
For example:
For production applications, avoid storing sensitive configuration directly in source control. Use secure configuration such as environment variables, Azure Key Vault, or your organization's approved secret-management solution.
For example:
For production applications, avoid storing sensitive configuration directly in source control. Use secure configuration such as environment variables, Azure Key Vault, or your organization's approved secret-management solution.
What happens after integration?
Once you integrate Application Insights, it can collect telemetry while your application is running.
To understand this integration, let’s take the following API endpoint as an example:
GET /api/orders/1001
A user sends the request.
The application processes the request and may communicate with a database.
Application Insights can provide telemetry similar to:
If something goes wrong, the telemetry can help you investigate the failure.
If something goes wrong, the telemetry can help you investigate the failure.
Monitoring HTTP Requests
One of the important telemetry types is Requests.
Application Insights can help you analyze requests handled by your application.
For example:
GET /api/products
POST /api/orders
GET /api/customers
PUT /api/profile
DELETE /api/orders/1001
Application Insights can help you analyze requests handled by your application.
For example:
GET /api/products
POST /api/orders
GET /api/customers
PUT /api/profile
DELETE /api/orders/1001
- Total Incoming Calls
- Requests Completed Successfully
- Requests Ending in Errors
- Response Duration
- Result Codes
This helps developers understand how the application's APIs are performing.
You can investigate information such as:
Monitoring Exceptions
Suppose your application encounters an exception:
throw new Exception("Payment service failed");
Application Insights can capture exception telemetry.
You can then investigate information such as:
Exception → Stack Trace → Related Request → Timestamp
This can be extremely useful when troubleshooting production issues.
Instead of asking:
"What went wrong?"
the development team can investigate the actual exception and its associated telemetry.
Monitoring Dependencies
Modern applications rarely work alone.
A .NET application may communicate with:
SQL Server
Azure Storage
Redis
REST APIs
Azure services
Other microservices
For example:
These external calls are known as dependencies.
Application Insights can help monitor dependency calls and identify slow or failed dependencies.
For example:
- API Duration : 5 seconds
- SQL Dependency : 4.5 seconds
- External API : 200 ms
From this information, the team can investigate the SQL operation as a possible
performance bottleneck.
Logging with ILogger
Application Insights can also work with the standard .NET logging framework.
For example:
issue occurred.
For example:
private readonly ILogger<OrderController> _logger;
public OrderController(ILogger<OrderController> logger)
{
_logger = logger;
}
_logger.LogInformation(
"Processing order {OrderId}",
orderId);
You can use different log levels depending on the situation:- Trace
- Debug
- Information
- Warning
- Error
- Critical
issue occurred.
Custom Telemetry
Automatic telemetry is useful, but sometimes an application needs to track specific
business events.
For example:
Order Created
Payment Completed
Supplier Submitted
Profile Approved
Document Uploaded
These are business-specific events.
Application Insights provides
TelemetryClient for sending custom telemetry.Example:
_telemetryClient.TrackEvent(
"OrderCreated",
new Dictionary<string, string>
{
{ "OrderId", orderId.ToString() }
});
The development team can now monitor a critical business event directly within Application Insights.
Application Map
One useful feature of Application Insights is the Application Map.
It helps visualise the relationships between application components and dependencies.
For example:
It helps visualise the relationships between application components and dependencies.
For example:
This becomes especially useful when working with large applications containingmultiple services.If one dependency is experiencing failures or performance issues, the application map can help identify the affected component.
Using KQL to Analyze Application Insights Data
Application Insights data can be queried using Kusto Query Language (KQL).
For example, to find failed requests:
requests
| where success == false
| project timestamp, name, resultCode, duration
| order by timestamp desc
For example, to find failed requests:
requests
| where success == false
| project timestamp, name, resultCode, duration
| order by timestamp desc
exceptions
| project timestamp, type, outerMessage
| order by timestamp desc
requests
| where duration > 1000
| project timestamp, name, duration
| order by duration desc
dependencies
| where duration > 1000
| project timestamp, name, target, duration
| order by duration desc
| project timestamp, type, outerMessage
| order by timestamp desc
requests
| where duration > 1000
| project timestamp, name, duration
| order by duration desc
dependencies
| where duration > 1000
| project timestamp, name, target, duration
| order by duration desc
To find exceptions:
To find slow requests:
To find slow dependencies:
KQL becomes particularly useful when investigating production problems.
To find slow requests:
To find slow dependencies:
KQL becomes particularly useful when investigating production problems.
Real-World Production Scenario
Let's consider a real-world example.
Imagine an e-commerce application built using ASP.NET Core.
Imagine an e-commerce application built using ASP.NET Core.
The architecture is:
Suddenly, customers start reporting:
The API response for this order is currently delayed.
The support team checks Application Insights.
The API response for this order is currently delayed.
The support team checks Application Insights.
Step 1 — Check Requests
They find that:
POST /api/orders
is taking several seconds.
Step 2 — Check Failures
Some requests are returning:
500 Internal Server Error
Step 3 — Check Exceptions
The team finds an exception related to a database operation.
Step 4 — Check Dependencies
Application Insights shows:
The team can now investigate the database query, connection, or related database issue.
This is the practical value of Application Insights.
It helps connect:
Request → Exception → Dependency → Performance
and gives developers useful information for troubleshooting.
It helps connect:
Request → Exception → Dependency → Performance
and gives developers useful information for troubleshooting.
Complete Real-World Flow
The complete monitoring flow can be understood like this:
Application Insights Best Practices
When implementing Application Insights in a real production application, keep these points in mind:
1. Protect your connection string:
Avoid uploading confidential settings or secret values to any version control repository.
2. Use meaningful logging:
Avoid logging everything unnecessarily. Log information that helps
developers troubleshoot and understand application behaviour.
3. Avoid sensitive information:
Do not log passwords, access tokens, secrets, personal information,
or other sensitive data.
4. Use structured logging:
Prefer:
_logger.LogInformation(
"Order {OrderId} created",
orderId);
instead of constructing large strings manually.
5. Use KQL for troubleshooting:
KQL allows developers to investigate large amounts of telemetry efficiently.
6. Monitor dependencies:
An API may be healthy while its database or external service is slow.
Dependency telemetry helps identify these situations.
Why Application Insights is Important for .NET Developers
Application Insights is more than just a logging tool.
It provides visibility into the application's behaviour after deployment.
A typical production troubleshooting process can be:
This makes Application Insights an important part of modern .NET + Azure application
development and production monitoring.
Final Takeaway
When building a .NET application, writing code and deploying it is only one part of the job.
Once the application is running in production, developers need visibility into:
What happened?
Where did it happen?
Why did it happen?
How much time did the request take to complete?
Which dependency caused the problem?
Azure Application Insights helps answer these questions by collecting and analysing application telemetry.
With .NET + Azure Application Insights + Azure Monitor + KQL, developers can build a practical monitoring and troubleshooting solution for production applications.
Once the application is running in production, developers need visibility into:
What happened?
Where did it happen?
Why did it happen?
How much time did the request take to complete?
Which dependency caused the problem?
Azure Application Insights helps answer these questions by collecting and analysing application telemetry.
With .NET + Azure Application Insights + Azure Monitor + KQL, developers can build a practical monitoring and troubleshooting solution for production applications.


.png)

.png)
.png)
.png)
.png)
.png)
.png)
.png)