App Service auto-instrumentation vs the SDK: which one to run
Auto-instrumentation turns Application Insights on from the platform, with a portal switch or an app setting and no code change: App Service attaches an agent for .NET, Java, Node.js and Python, Azure Functions is instrumented by default, and AKS injects OpenTelemetry instrumentation into Java and Node.js pods. Use it when requests, dependencies and exceptions are all you need. Move to code (the Microsoft OpenTelemetry Distro, SDK 3.x, or the Java agent's configuration) when you need custom telemetry, enrichment or your own sampling, and then switch the platform agent off.
“Codeless”, “agent-based” and “auto-instrumentation” all mean the same thing in Microsoft’s docs: the platform loads monitoring into your process at startup, configured by app settings rather than by code you ship. It’s the quickest way to get the Performance and Failures views and Application Map working, and the right answer for many apps. Its limits show up the first time you want something the platform doesn’t expose.
Where auto-instrumentation exists
Microsoft’s support matrix, checked for this guide:
| Host | .NET Framework | .NET | Java | Node.js | Python |
|---|---|---|---|---|---|
| App Service, Windows, code | Yes | Yes, on by default | Yes, on by default | Yes, on by default | No |
| App Service, Linux, code | No | Yes, on by default | Yes, on by default | Yes, on by default | Yes |
| App Service, Linux containers | No | Yes | Yes | Yes | No |
| Azure Functions | Yes, on by default | Yes, on by default | Yes, on by default | Yes, on by default | Yes, on by default |
| AKS | No | Preview | Yes | Yes | Preview |
Windows containers on App Service are a preview for .NET Framework, .NET, Java and Node.js. Container deployments are single-container only; multi-container and sidecar apps need code-based instrumentation. Azure Container Apps is different again: its managed OpenTelemetry agent forwards what your app emits, so you still add an OpenTelemetry SDK, and the Application Insights destination accepts logs and traces but not metrics. Container Apps describes that agent as a preview.
App Service: what the switch does
In the portal, open the app, select Application Insights > Enable, pick a resource and select Apply monitoring settings. App Service restarts the app. For templates and pipelines, the same thing is four app settings.
App settings that turn on auto-instrumentation for an ASP.NET Core app on Linux (use ~2 on Windows):
"appSettings": [
{ "name": "APPLICATIONINSIGHTS_CONNECTION_STRING", "value": "<connection string>" },
{ "name": "ApplicationInsightsAgent_EXTENSION_VERSION", "value": "~3" },
{ "name": "XDT_MicrosoftApplicationInsights_Mode", "value": "recommended" },
{ "name": "XDT_MicrosoftApplicationInsights_PreemptSdk", "value": "1" }
]
What you get depends on the stack:
- ASP.NET Core. Recommended collects requests, dependencies, exceptions and browser monitoring (the JavaScript snippet, on by default; set
APPINSIGHTS_JAVASCRIPT_ENABLEDtofalseto stop it). Microsoft is explicit that App Service offers no extra settings here: changing sampling, enrichment or custom telemetry means code-based instrumentation. Trimmed self-contained deployments aren’t supported. - ASP.NET on .NET Framework. Basic or Recommended; only Recommended adds CPU, memory and I/O trends and correlation across request and dependency boundaries. Adaptive sampling is tuned with app settings such as
MicrosoftAppInsights_AdaptiveSamplingTelemetryProcessor_MaxTelemetryItemsPerSecond, and setting..._MinSamplingPercentageto100turns it off. SQL command text needsInstrumentationEngine_EXTENSION_VERSION=~1plusXDT_MicrosoftApplicationInsights_BaseExtensions=~1, and both can lengthen cold starts. - Java. App Service attaches the Java 3.x agent, which collects requests, dependencies, logs (Log4j, Logback, JBoss Logging,
java.util.logging), Micrometer metrics and heartbeats. Configure it withAPPLICATIONINSIGHTS_CONFIGURATION_CONTENT(inline JSON) orAPPLICATIONINSIGHTS_CONFIGURATION_FILE. On Windows, also setXDT_MicrosoftApplicationInsights_Java=1. - Node.js. Requests, dependencies, exceptions, traces and heartbeats. Microsoft lists Node.js auto-instrumentation as a public preview; on Windows it also needs
XDT_MicrosoftApplicationInsights_NodeJS=1. - Python. Linux, deployed as code, Python 3.9 through 3.13. It instruments Django, FastAPI, Flask, psycopg2, requests, urllib and urllib3 plus the root logger, and takes standard
OTEL_*settings (OTEL_SERVICE_NAME,OTEL_TRACES_SAMPLER_ARG,OTEL_PYTHON_DISABLED_INSTRUMENTATIONS). Live Metrics isn’t available.
Classic SDK 2.x
Auto-instrumentation on Windows servers started with Status Monitor. Its replacement is the Application Insights Agent, the PowerShell module Az.ApplicationMonitor. The newest version on the PowerShell Gallery is 2.0.0, last published on February 10, 2023, and 2.0.0 is the release that added ASP.NET Core apps hosted in IIS. It supports ASP.NET and ASP.NET Core on IIS only; Java and Node.js need an SDK.
Enable-ApplicationInsightsMonitoring edits IIS’s applicationHost.config, writes an applicationinsights.ikey.config, and registers a module that loads the Application Insights SDK into each app as it starts. On Azure VMs and scale sets, the same agent ships as the Application Insights Agent VM extension. Its documentation lives in Microsoft’s archived Classic API 2.x pages, which carry the notice that the .NET 2.x SDK retires on March 31, 2027; Microsoft doesn’t state a separate date for the agent.
Enable the agent on an IIS server with one connection string for every site (run as administrator):
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope Process -Force
Install-Module -Name Az.ApplicationMonitor -AllowPrerelease -AcceptLicense
Enable-ApplicationInsightsMonitoring -ConnectionString 'InstrumentationKey=...;IngestionEndpoint=https://...'
# Restart IIS, then confirm which sites are instrumented:
Get-ApplicationInsightsMonitoringStatus
The status output answers the “both at once” question for IIS. A site whose process already loads Application Insights assemblies shows AppAlreadyInstrumented : true: the agent assumed the app was instrumented by hand and backed off. That makes the IIS agent safe to roll out across a farm where some apps already reference the SDK.
For Azure Cloud Services, Microsoft’s dependency-tracking table still lists a startup task that installs Status Monitor, with the SDK added to the app at build time.
Today: SDK 3.x and the Microsoft OpenTelemetry Distro
Code-based instrumentation is what Microsoft points you to as soon as the defaults aren’t enough. For a new .NET app that’s the Microsoft OpenTelemetry Distro; for an app on the 2.x SDK it’s an upgrade to SDK 3.x (AddApplicationInsightsTelemetry() keeps working). The SDK vs Distro guide compares them. Both read APPLICATIONINSIGHTS_CONNECTION_STRING, so the app setting App Service already created keeps doing its job.
Program.cs for an ASP.NET Core app moving from auto-instrumentation to the Distro:
using Microsoft.OpenTelemetry;
var builder = WebApplication.CreateBuilder(args);
// Reads APPLICATIONINSIGHTS_CONNECTION_STRING from the App Service app settings.
builder.UseMicrosoftOpenTelemetry(options =>
{
options.Exporters = ExportTarget.AzureMonitor;
});
var app = builder.Build();
app.Run();
Then set XDT_MicrosoftApplicationInsights_Mode to disabled (or choose Disabled in the portal) so the platform agent stops collecting. On App Service, Microsoft’s page names PreemptSdk as required for ASP.NET Core auto-instrumentation but doesn’t document which collector wins when an app also carries its own SDK or Distro, so don’t rely on either winning. AKS does document it: the injected instrumentation coexists with manual instrumentation and prevents duplicates, with manual instrumentation taking precedence for Node.js and auto-instrumentation taking precedence for Java.
Azure Functions
Functions is auto-instrumented as soon as APPLICATIONINSIGHTS_CONNECTION_STRING is set; the older APPINSIGHTS_INSTRUMENTATIONKEY setting is deprecated. The host samples by default, at up to 20 telemetry items per second, applied separately on each host that runs the app; the settings live in host.json.
host.json that keeps every execution and exception while sampling the rest:
{
"version": "2.0",
"logging": {
"applicationInsights": {
"samplingSettings": {
"isEnabled": true,
"maxTelemetryItemsPerSecond": 20,
"excludedTypes": "Request;Exception"
}
}
}
}
If your function code also uses the Application Insights SDK, Microsoft warns of unusual behaviour when its sampling differs from the host’s: keep them the same. Function executions are logged under the Host.Results category at Information, so a log level of Warning or higher for that category also removes rows from requests.
To move a function app to OpenTelemetry, add "telemetryMode": "OpenTelemetry" at the root of host.json and configure the worker in code. Once you do, the logging.applicationInsights section (sampling included) no longer applies, and log streaming in the portal isn’t supported.
Program.cs in a .NET isolated function app that exports OpenTelemetry to Application Insights:
builder.Services.AddOpenTelemetry()
.UseFunctionsWorkerDefaults()
.UseAzureMonitorExporter();
Check how many collectors you have
Two collectors on one app usually show up as two SDK version strings for the same role in the same hour. The sdkVersion column (SDKVersion in AppRequests) records which library sent each row:
requests
| where timestamp > ago(1h)
| summarize requests = sum(itemCount) by cloud_RoleName, sdkVersion
| order by cloud_RoleName asc
Duplicated request counts in the latency by operation query are the other giveaway. The sampling guide explains why the itemCount weighting matters here.
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
| No data after enabling | App not restarted, or stack not supported (trimmed .NET, Python in a container) | Restart; check the matrix above; use the Distro |
| Every request counted twice | Agent and in-app SDK or Distro both active | Set XDT_MicrosoftApplicationInsights_Mode to disabled |
| Custom events missing | Auto-instrumentation doesn’t send them | Add the Distro or SDK 3.x in code |
IIS site shows AppAlreadyInstrumented | SDK assemblies found in the process | Expected; the in-app SDK does the work |
Functions requests table thin | Host.Results filtered above Information, or sampling | Lower the level; exclude Request from sampling |
| Functions sampling setting ignored | telemetryMode set to OpenTelemetry | Configure sampling in the worker code |
| No Live Metrics for a Python web app | Not available for App Service Python auto-instrumentation | Use the Distro in code; see Live Metrics from code |
Frequently asked questions
Can I change sampling with App Service auto-instrumentation?
For ASP.NET apps on .NET Framework, yes, through app settings that start with MicrosoftAppInsights_AdaptiveSamplingTelemetryProcessor_. For ASP.NET Core, Microsoft says App Service has no extra settings, so sampling, enrichment and custom telemetry need code-based instrumentation. Python takes OTEL_TRACES_SAMPLER_ARG; Java uses its JSON configuration.
Do I need to restart anything after enabling it?
Yes. App Service restarts the app when you apply the monitoring settings, the IIS agent needs an IIS restart, and AKS auto-instrumentation only reaches pods after the deployment restarts. Microsoft also suggests restarting AKS deployments weekly so they pick up the latest injected instrumentation.
Why does the Application Insights Agent skip one of my IIS sites?
If it finds Application Insights assemblies already loaded in the site, it assumes the app is instrumented by hand and backs off. Get-ApplicationInsightsMonitoringStatus then shows AppAlreadyInstrumented true for that process, which is the expected result, not a failure.
Is Python supported by App Service auto-instrumentation?
Yes, on Linux only, for Python 3.9 through 3.13 deployed as code. Custom containers aren't supported, and Live Metrics isn't available for Python auto-instrumentation; use the Microsoft OpenTelemetry Distro in code if you need either.
Sources, checked
- Autoinstrumentation for Azure Monitor Application Insights
- Monitor Azure App Service (Application Insights settings per stack)
- Configure monitoring for Azure Functions
- Use OpenTelemetry with Azure Functions
- Set up codeless monitoring for AKS with Application Insights
- Collect and read OpenTelemetry data in Azure Container Apps
- Monitor .NET and Node.js applications with Application Insights (Classic API 2.x, Application Insights Agent)
- Az.ApplicationMonitor (PowerShell Gallery)