Application Insights Introduction

Application Insights is Azure Monitor's application performance management (APM) service. It monitors your live web applications, detects performance anomalies, and helps you diagnose issues. While Azure Monitor watches infrastructure, Application Insights watches your code — the requests it handles, the dependencies it calls, the exceptions it throws.

What Application Insights Tracks

Telemetry TypeWhat It CapturesExample
RequestsIncoming HTTP requests to your appGET /api/users → 200, 45ms
DependenciesOutbound calls your app makesSQL query to orders DB → 120ms
ExceptionsUnhandled errors and caught exceptionsNullReferenceException in UserService
TracesCustom log messages (ILogger, console.log)"Processing order #12345"
Custom EventsBusiness events you define"UserSignedUp", "OrderPlaced"
Page ViewsBrowser-side page loads (JS SDK)/checkout loaded in 2.3s
AvailabilitySynthetic ping tests from Azure regionsHomepage responding from 5 locations

Connection Strings vs Instrumentation Keys

AspectInstrumentation Key (legacy)Connection String (current)
FormatSingle GUIDFull URI with endpoint + key
Endpoint controlNo (hardcoded to global endpoint)Yes (supports regional, private link)
StatusDeprecated (still works)Recommended for all new apps
Example00000000-0000-0000-0000-000000000000InstrumentationKey=...;IngestionEndpoint=https://eastus-0.in.applicationinsights.azure.com/

Always use connection strings for new applications. Instrumentation keys still work but lack endpoint flexibility and will eventually be retired.

Creating an App Insights Resource

# Create an Application Insights resource (workspace-based)
az monitor app-insights component create \
  --app myAppInsights \
  --location eastus \
  --resource-group myRG \
  --kind web \
  --application-type web \
  --workspace "/subscriptions/<sub-id>/resourceGroups/myRG/providers/Microsoft.OperationalInsights/workspaces/myWorkspace"

# Get the connection string (use this in your app configuration)
az monitor app-insights component show \
  --app myAppInsights \
  --resource-group myRG \
  --query connectionString --output tsv

# Get the instrumentation key (legacy, but sometimes needed)
az monitor app-insights component show \
  --app myAppInsights \
  --resource-group myRG \
  --query instrumentationKey --output tsv

# List all App Insights resources in a resource group
az monitor app-insights component show \
  --resource-group myRG \
  --output table

Enabling Auto-Instrumentation on App Service (Zero-Code)

Auto-instrumentation means Application Insights monitors your app without any code changes. Azure injects the monitoring agent at runtime.

Portal

  1. Open your App Service → Settings → Application Insights
  2. Click Turn on Application Insights
  3. Select an existing App Insights resource or create new
  4. Choose collection level (Recommended = full telemetry)
  5. Click Apply — your app restarts with monitoring enabled

CLI

# Enable auto-instrumentation on a .NET App Service
az monitor app-insights component connect-webapp \
  --app myAppInsights \
  --resource-group myRG \
  --web-app myWebApp

# Alternative: Set the connection string as an app setting
az webapp config appsettings set \
  --resource-group myRG \
  --name myWebApp \
  --settings APPLICATIONINSIGHTS_CONNECTION_STRING="InstrumentationKey=xxx;IngestionEndpoint=https://eastus-0.in.applicationinsights.azure.com/"

# Enable for a Node.js app (requires app setting)
az webapp config appsettings set \
  --resource-group myRG \
  --name myNodeApp \
  --settings APPLICATIONINSIGHTS_CONNECTION_STRING="<your-connection-string>" \
             ApplicationInsightsAgent_EXTENSION_VERSION="~3"

# Verify the settings
az webapp config appsettings list \
  --resource-group myRG \
  --name myWebApp \
  --query "[?contains(name, 'APPLICATIONINSIGHTS')]" \
  --output table

Supported Languages and Frameworks

LanguageAuto-InstrumentationSDK AvailableNotes
.NET / ASP.NET Core✅ Yes (App Service, VM)✅ YesBest support, richest telemetry
Java✅ Yes (App Service, VM)✅ YesJava agent auto-collects dependencies
Node.js✅ Yes (App Service)✅ YesSet extension version app setting
Python❌ No auto-instrumentation✅ Yes (OpenCensus/OpenTelemetry)Requires SDK integration
JavaScript (browser)N/A✅ Yes (JS SDK)Tracks page views, client errors
Go❌ No✅ Community SDKOpenTelemetry recommended
PHP❌ No❌ LimitedUse OpenTelemetry exporter

Live Metrics Stream

Live Metrics shows real-time telemetry with ~1 second latency. It's your "is it working right now?" tool.

What you see:

  • Incoming request rate and response times
  • Dependency call rate and failures
  • Exception rate
  • CPU and memory usage
  • Custom metrics (if configured)

Use it for:

  • Monitoring a deployment as it rolls out
  • Watching traffic during a load test
  • Verifying a fix is working immediately after deploy

Live Metrics has zero cost — it doesn't count toward ingestion billing.

Application Map

Application Map is a visual topology of your distributed application. It automatically discovers:

  • Your application components (web app, API, worker)
  • External dependencies (SQL, Redis, HTTP services, queues)
  • The health and performance of each connection

Each node shows:

  • Average response time
  • Failure rate
  • Request volume

Click any node or edge to drill into specific failures or slow calls. This is invaluable for microservices architectures where you need to find which downstream service is causing problems.

Transaction Search

Transaction Search lets you find individual telemetry items:

  • Search by operation ID to see an entire request lifecycle
  • Filter by type (request, dependency, exception, trace)
  • Filter by time range, result code, or custom properties
  • Click any item to see its full details and related telemetry

This is your go-to tool when investigating a specific user complaint or incident.

Failures Blade Walkthrough

The Failures blade gives you a pre-built view of what's going wrong:

  1. Top-level view — Shows failure rate trend over time
  2. Operations tab — Which endpoints are failing most
  3. Dependencies tab — Which outbound calls are failing
  4. Exceptions tab — Which exception types are most common
  5. Drill into any item — See individual occurrences with full stack traces
  6. End-to-end transaction — Follow a failed request through all its dependencies

Relationship Between App Insights and Log Analytics

Application Insights
    │
    │  Stores all telemetry in →
    │
    ▼
Log Analytics Workspace
    │
    ├── AppRequests table
    ├── AppDependencies table
    ├── AppExceptions table
    ├── AppTraces table
    ├── AppEvents table (custom events)
    └── AppMetrics table (custom metrics)

App Insights is a lens on top of Log Analytics. All App Insights data lives in your workspace. You can:

  • Query App Insights data using KQL in Log Analytics
  • Join App Insights data with infrastructure logs
  • Create alerts on App Insights tables using log alert rules
  • Build workbooks combining App Insights and resource logs

When to Use App Insights vs Raw Log Analytics

ScenarioUse App InsightsUse Log Analytics
Monitor app performance (latency, errors)
Investigate a specific failed request
View application topology
Correlate app errors with infrastructure logs
Query across multiple apps and resources
Build complex KQL reports
Set up availability tests
Audit who changed Azure resources
Track custom business metrics
Long-term log retention and compliance

In practice, you use both. App Insights for day-to-day app monitoring; Log Analytics for cross-cutting queries and compliance.

Common Mistakes

  • Using instrumentation key instead of connection string — Always use connection strings for new apps.
  • Forgetting to link to a workspace — Classic (standalone) App Insights resources are deprecated. Always create workspace-based resources.
  • Not enabling sampling — High-traffic apps can generate expensive volumes. Adaptive sampling is on by default in SDKs; don't disable it without understanding the cost impact.
  • Ignoring dependency tracking — Most app slowness comes from dependencies (DB, HTTP calls), not the app itself. Make sure dependency tracking is enabled.
  • Not setting cloud role name — In multi-service apps, set cloud_RoleName so Application Map shows distinct nodes per service.

Tips

  • Use auto-instrumentation first. Only add the SDK when you need custom telemetry or finer control.
  • Set up availability tests (ping tests) from multiple regions to detect outages before users report them.
  • Use the "Smart Detection" feature — it automatically finds anomalies in failure rates and response times.
  • Export data to continuous export or diagnostic settings for long-term archival beyond workspace retention.

Key Takeaways

  • Application Insights monitors your application code: requests, dependencies, exceptions, and custom events.
  • Use connection strings (not instrumentation keys) for all new applications.
  • Auto-instrumentation on App Service requires zero code changes — enable it in the portal or via CLI.
  • All App Insights data is stored in a Log Analytics workspace and queryable via KQL.
  • Live Metrics, Application Map, and the Failures blade are your primary investigation tools.
  • App Insights is for app-level monitoring; Log Analytics is for cross-resource queries and infrastructure logs. Use both together.
  • Always create workspace-based App Insights resources (classic is deprecated).