Skip to content
Back to Cloud Services

Application Insights

Application Performance Monitoring (APM) for live apps: request tracing, dependency maps, exception capture, live metrics, and log analytics via KQL.

AzureIntermediate

Why

App Insights is auto-instrumented into App Service, Functions, and AKS with one setting, giving you request latency, failure rates, dependency calls (SQL, HTTP), and distributed tracing for free. It stores data in Log Analytics where you query with Kusto (KQL) and alert on any metric. Azure holds 21% cloud market share (Synergy Research Q4 2024).

Azure is the default for enterprises with Microsoft 365 / Active Directory estates — 95% of Fortune 500 use Azure. AKS and Cosmos DB are first-class for .NET workloads.

When

Enable App Insights on every Azure-hosted app from day one — the overhead is minimal and you cannot retroactively collect telemetry for past incidents. For custom metrics or business events, use trackMetric/trackEvent.

For log-heavy workloads, sample aggressively to control cost.

How

1. Create an Application Insights resource (or enable it on App Service/Functions which auto-creates one). 2. Get the instrumentation key or connection string. 3. Add the SDK (@microsoft/applicationinsights-web for browser, applicationinsights for Node.js). 4. Auto-collect requests, dependencies, exceptions; add custom events/metrics as needed. 5. Query telemetry in the Log Analytics workspace with KQL. 6. Set up alerts on failure rate, latency, or custom metrics. ```bash az monitor app-insights component create --name myai --app myapp --resource-group rg --location eastus az monitor app-insights component show --name myai --resource-group rg --query "connectionString" ```

Example

Node.js auto-instrumentation plus a custom business event, and a KQL query for slow requests: ```ts import appInsights from "applicationinsights"; appInsights.setup(process.env.AI_CONNECTION_STRING!).start(); const client = appInsights.defaultClient; client.trackEvent({ name: "OrderPlaced", properties: { sku: "A1", qty: 3 } }); client.trackMetric({ name: "CartValue", value: 99.95 }); ``` ```kusto // requests slower than 1s in the last hour, grouped by operation requests | where timestamp > ago(1h) and duration > 1000 | summarize count(), avgDuration=avg(duration) by operation_Name | order by avgDuration desc ```

Common Problems

  • ⚠No data showing — the connection string/instrumentation key is wrong or the SDK was not started; call .start() and verify the connection string in the portal.
  • ⚠High cost from excessive telemetry — enable adaptive sampling (default in Node.js SDK) or fixed sampling at 5-10% for high-volume apps to cap ingestion cost.
  • ⚠Distributed trace breaks across services — each service must use the same connection string and propagate the traceparent header; the SDK does this automatically for HTTP calls.

Best Practices

  • ✓Enable auto-instrumentation via the App Service/Functions setting instead of manually adding the SDK — it covers requests, dependencies, and logs with zero code.
  • ✓Use sampling for high-volume apps (5-10%) to control Log Analytics cost while keeping statistically significant traces for slow/failing requests.
  • ✓Write KQL alert rules for 'failure rate > 5% over 5 min' and 'p95 latency > 2s' so you are paged before users complain.

FAQ

What is Application Insights and what problem does it solve?

Application Performance Monitoring (APM) for live apps: request tracing, dependency maps, exception capture, live metrics, and log analytics via KQL. It lets developers deploy, store, and scale without self-managing infrastructure — a core reference for cloud service selection.

How do I get started with Application Insights in 5 minutes?

Two steps to run it: (1) Create an Application Insights resource (or enable it on App Service/Functions which auto-creates one).; (2) Get the instrumentation key or connection string.. Validate on the free tier first, then wire into production.

What is the #1 pitfall with Application Insights?

The most frequent issue is: No data showing — the connection string/instrumentation key is wrong or the SDK was not started; call .start() and verify the connection string in the portal.. Run a pre-launch checklist item by item, and add policy/config scanning in CI.

What are the best practices for Application Insights?

Best practices for Application Insights include: Enable auto-instrumentation via the App Service/Functions setting instead of manually adding the SDK — it covers requests, dependencies, and logs with zero code.; Use sampling for high-volume apps (5-10%) to control Log Analytics cost while keeping statistically significant traces for slow/failing requests.; Write KQL alert rules for 'failure rate > 5% over 5 min' and 'p95 latency > 2s' so you are paged before users complain.. The first one — "Enable auto-instrumentation via the App Service/Functions setting instead of manually adding the SDK — it covers requests, dependencies, and logs with zero code." — should be a team default baked into your IaC templates.

How do I control cost and avoid bill surprises with Application Insights?

Three ways to prevent overspend: (1) tag every resource with env/team and enable billing alarms; (2) set budget thresholds to trigger Slack/email alerts; (3) review idle resources in Cost Explorer regularly and clean them up. Most Application Insights options offer a free tier — validate within free quota before scaling.