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 Type | What It Captures | Example |
|---|---|---|
| Requests | Incoming HTTP requests to your app | GET /api/users → 200, 45ms |
| Dependencies | Outbound calls your app makes | SQL query to orders DB → 120ms |
| Exceptions | Unhandled errors and caught exceptions | NullReferenceException in UserService |
| Traces | Custom log messages (ILogger, console.log) | "Processing order #12345" |
| Custom Events | Business events you define | "UserSignedUp", "OrderPlaced" |
| Page Views | Browser-side page loads (JS SDK) | /checkout loaded in 2.3s |
| Availability | Synthetic ping tests from Azure regions | Homepage responding from 5 locations |
Connection Strings vs Instrumentation Keys
| Aspect | Instrumentation Key (legacy) | Connection String (current) |
|---|---|---|
| Format | Single GUID | Full URI with endpoint + key |
| Endpoint control | No (hardcoded to global endpoint) | Yes (supports regional, private link) |
| Status | Deprecated (still works) | Recommended for all new apps |
| Example | 00000000-0000-0000-0000-000000000000 | InstrumentationKey=...;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
- Open your App Service → Settings → Application Insights
- Click Turn on Application Insights
- Select an existing App Insights resource or create new
- Choose collection level (Recommended = full telemetry)
- 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
| Language | Auto-Instrumentation | SDK Available | Notes |
|---|---|---|---|
| .NET / ASP.NET Core | ✅ Yes (App Service, VM) | ✅ Yes | Best support, richest telemetry |
| Java | ✅ Yes (App Service, VM) | ✅ Yes | Java agent auto-collects dependencies |
| Node.js | ✅ Yes (App Service) | ✅ Yes | Set 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 SDK | OpenTelemetry recommended |
| PHP | ❌ No | ❌ Limited | Use 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:
- Top-level view — Shows failure rate trend over time
- Operations tab — Which endpoints are failing most
- Dependencies tab — Which outbound calls are failing
- Exceptions tab — Which exception types are most common
- Drill into any item — See individual occurrences with full stack traces
- 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
| Scenario | Use App Insights | Use 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_RoleNameso 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).