Edit

Share via


Application Insights for Azure virtual machines (VMs) and virtual machine scale sets

Enable Azure Monitor Application Insights monitoring through autoinstrumentation for Internet Information Server (IIS)-hosted ASP.NET and ASP.NET Core applications on Azure Virtual Machines and Azure Virtual Machine Scale Sets. Deploy the Application Insights Agent with a virtual machine extension. The agent autocollects the same dependency signals as the SDK. Use PowerShell to automate large-scale deployments.

Note

For a complete list of supported autoinstrumentation scenarios, see Supported environments, languages, and resource providers.

Prerequisites

Before you install the Application Insights Agent extension, you need a connection string. Create a new Application Insights resource or copy the connection string from an existing one.

Enable monitoring for virtual machines

You can use the Azure portal or PowerShell to enable monitoring for VMs.

  1. In the Azure portal, go to your Application Insights resource. Copy your connection string to the clipboard.

    Screenshot that shows the connection string.

  2. Go to your virtual machine. Under the Settings section in the menu on the left side, select Extensions + applications > Add.

    Screenshot that shows the Extensions + applications pane with the Add button.

  3. Select Application Insights Agent > Next.

    Screenshot that shows the Install an Extension pane with the Next button.

  4. Paste the connection string you copied in step 1 and select Review + create.

    Screenshot that shows the Create tab with the Review + create button.

instrumentationKeyMap (extension settings)

Important

InstrumentationKeyMap is an advanced routing feature that maps Internet Information Services (IIS) apps on the same machine to Application Insights resources. The feature applies to IIS-hosted ASP.NET and ASP.NET Core apps that the Application Insights Agent autoinstruments.

How matching works

  • The map defines an ordered list of rules named filters. The first matching rule takes effect. Place specific rules first and finish with a catch-all rule.
  • Each rule can assign a different Application Insights resource to matching apps. Prefer connection strings in supported scenarios because instrumentation keys are legacy.

Available filters

  • MachineFilter or machineFilter: C# regular expression that matches the computer or virtual machine (VM) name. .* matches all names.
  • AppFilter or appFilter: C# regular expression that matches the IIS site name (HostingEnvironment.SiteName). This filter is required when VirtualPathFilter or virtualPathFilter isn't provided.
  • VirtualPathFilter or virtualPathFilter: C# regular expression that matches the IIS virtual path (HostingEnvironment.ApplicationVirtualPath). Use this filter to target a single app under a site.

Terminology mapping

  • PowerShell cmdlets use MachineFilter, AppFilter, and VirtualPathFilter.
  • Azure VM and Virtual Machine Scale Sets extension JSON uses machineFilter, appFilter, and virtualPathFilter, and sets the resource with instrumentationSettings.

Tip

Include a final rule that matches all apps, such as .*, and apply a default resource to make the behavior explicit.

Where it goes for the VM and Virtual Machine Scale Sets extension

Place the map under redfieldConfiguration.instrumentationKeyMap.filters in the extension's public settings (-SettingString for VMs, -Setting for Virtual Machine Scale Sets). Property names are lower camel case. Set the target resource per rule with instrumentationSettings.connectionString.

{
  "redfieldConfiguration": {
    "instrumentationKeyMap": {
      "filters": [
        {
          "machineFilter": ".*",
          "appFilter": ".*",
          "instrumentationSettings": {
            "connectionString": "<your-APPLICATIONINSIGHTS_CONNECTION_STRING>"
          }
        }
      ]
    }
  }
}

Enable monitoring for virtual machine scale sets

You can use the Azure portal or PowerShell to enable monitoring for virtual machine scale sets.

Follow the prior steps for VMs, but go to your virtual machine scale sets instead of your VM.

Troubleshooting

Use these troubleshooting tips for the Application Insights Monitoring Agent extension. The tips apply to .NET applications on Azure Virtual Machines and Azure Virtual Machine Scale Sets.

If you have trouble deploying the extension, review the execution output that the extension logs to files in the following directories:

C:\WindowsAzure\Logs\Plugins\Microsoft.Azure.Diagnostics.ApplicationMonitoringWindows\<version>\

If your extension deployed successfully but you're unable to see telemetry, it could be one of the following issues covered in Agent troubleshooting:

  • Conflicting dynamic link libraries (DLLs) in an app's bin directory
  • Conflict with IIS shared configuration

Test connectivity between your application host and the ingestion service

Application Insights SDKs and agents send telemetry to get ingested as REST calls to our ingestion endpoints. You can test connectivity from your web server or application host machine to the ingestion service endpoints by using raw REST clients from PowerShell or curl commands. See Troubleshoot missing application telemetry in Azure Monitor Application Insights.

Release notes

2.8.44

  • Updated Application Insights .NET/.NET Core SDK to 2.20.1 - red field.
  • Enabled SQL query collection.
  • Enabled support for Microsoft Entra authentication.

2.8.42

Updated Application Insights .NET/.NET Core SDK to 2.18.1 - red field.

2.8.41

Added the ASP.NET Core autoinstrumentation feature.

Next steps