Profile web apps running on an Azure virtual machine or a virtual machine scale set by using Application Insights Profiler

Note

This article has been updated to use the new Azure PowerShell Az module. You can still use the AzureRM module, which will continue to receive bug fixes until at least December 2020. To learn more about the new Az module and AzureRM compatibility, see Introducing the new Azure PowerShell Az module. For Az module installation instructions, see Install Azure PowerShell.

You can also deploy Azure Application Insights Profiler on these services:

Deploy Profiler on a virtual machine or a virtual machine scale set

This article shows you how to get Application Insights Profiler running on your Azure virtual machine (VM) or Azure virtual machine scale set. Profiler is installed with the Azure Diagnostics extension for VMs. Configure the extension to run Profiler, and build the Application Insights SDK into your application.

  1. Add the Application Insights SDK to your ASP.NET application.

    To view profiles for your requests, you must send request telemetry to Application Insights.

  2. Install Azure Diagnostics extension on your VM. For full Resource Manager template examples, see:

    • Virtual machine

    • Virtual machine scale set

      The key part is the ApplicationInsightsProfilerSink in the WadCfg. To have Azure Diagnostics enable Profiler to send data to your iKey, add another sink to this section.

      "SinksConfig": {
        "Sink": [
          {
            "name": "ApplicationInsightsSink",
            "ApplicationInsights": "85f73556-b1ba-46de-9534-606e08c6120f"
          },
          {
            "name": "MyApplicationInsightsProfilerSink",
            "ApplicationInsightsProfiler": "85f73556-b1ba-46de-9534-606e08c6120f"
          }
        ]
      },
      
  3. Deploy the modified environment deployment definition.

    Applying the modifications usually involves a full template deployment or a cloud service-based publish through PowerShell cmdlets or Visual Studio.

    The following PowerShell commands are an alternate approach for existing virtual machines that touch only the Azure Diagnostics extension. Add the previously mentioned ProfilerSink to the config that's returned by the Get-AzVMDiagnosticsExtension command. Then pass the updated config to the Set-AzVMDiagnosticsExtension command.

    $ConfigFilePath = [IO.Path]::GetTempFileName()
    # After you export the currently deployed Diagnostics config to a file, edit it to include the ApplicationInsightsProfiler sink.
    (Get-AzVMDiagnosticsExtension -ResourceGroupName "MyRG" -VMName "MyVM").PublicSettings | Out-File -Verbose $ConfigFilePath
    # Set-AzVMDiagnosticsExtension might require the -StorageAccountName argument
    # If your original diagnostics configuration had the storageAccountName property in the protectedSettings section (which is not downloadable), be sure to pass the same original value you had in this cmdlet call.
    Set-AzVMDiagnosticsExtension -ResourceGroupName "MyRG" -VMName "MyVM" -DiagnosticsConfigurationPath $ConfigFilePath
    
  4. If the intended application is running through IIS, enable the IIS Http Tracing Windows feature.

    a. Establish remote access to the environment, and then use the Add Windows features window. Or run the following command in PowerShell (as administrator):

    Enable-WindowsOptionalFeature -FeatureName IIS-HttpTracing -Online -All
    

    b. If establishing remote access is a problem, you can use the Azure CLI to run the following command:

    az vm run-command invoke -g MyResourceGroupName -n MyVirtualMachineName --command-id RunPowerShellScript --scripts "Enable-WindowsOptionalFeature -FeatureName IIS-HttpTracing -Online -All"
    
  5. Deploy your application.

Set Profiler Sink using Azure Resource Explorer

We don't yet have a way to set the Application Insights Profiler sink from the portal. Instead of using powershell like described above, you can use Azure Resource Explorer to set the sink. But note, if you deploy the VM again, the sink will be lost. You'll need to update the config you use when deploying the VM to preserve this setting.

  1. Check that the Windows Azure Diagnostics extension is installed by viewing the extensions installed for your virtual machine.

    Check if WAD extension is installed

  2. Find the VM Diagnostics extension for your VM. Expand your resource group, Microsoft.Compute virtualMachines, virtual machine name, and extensions.

    Navigate to WAD config in Azure Resource Explorer

  3. Add the Application Insights Profiler sink to the SinksConfig node under WadCfg. If you don't already have a SinksConfig section, you may need to add one. Be sure to specify the proper Application Insights iKey in your settings. You'll need to switch the explorers mode to Read/Write in the upper right corner and Press the blue 'Edit' button.

    Add Application Insights Profiler Sink

  4. When you're done editing the config, press 'Put'. If the put is successful, a green check will appear in the middle of the screen.

    Send put request to apply changes

Can Profiler run on on-premises servers?

We have no plan to support Application Insights Profiler for on-premises servers.

Next steps

  • Generate traffic to your application (for example, launch an availability test). Then, wait 10 to 15 minutes for traces to start to be sent to the Application Insights instance.
  • See Profiler traces in the Azure portal.
  • For help with troubleshooting Profiler issues, see Profiler troubleshooting.