Skip to main content

Install .NET agents with Azure Resource Manager

This topic describes the most popular methods for instrumenting .NET Framework and .NET Core applications through automation with Azure Resource Manager (ARM) templates and Azure.

You can only configure site extensions either directly through the Azure Portal with an ARM policy or through Azure’s REST API. All methods described in this topic use one of these methods. Only REST API and Azure ARM policies allow for automated deployments.

Before you begin

  • Verify that Contrast supports your preferred OS and runtime stack for the .NET Framework and .NET Core agents

  • Ensure you have login access to Contrast.

  • Only configure a Contrast site extension with backend HTTP services and not WebJobs or UI app services.

  • The methods in this topic do not work if you are deploying an App service using Docker.

Step 1: Download an agent configuration file

  1. Download a configuration file from Contrast.

    1. In the Contrast web interface, select Add New.

    2. Select the Application card.

    3. Follow the displayed instructions to get the required values and download a YAML configuration file.

  2. To automate your ARM templates more fully, get your Contrast API credentials, either from the contrast_security.yml file that you downloaded or from the Contrast web interface (user menu > Organization Settings > Agent). These credentials are:

    Configuration setting

    Contrast label

    CONTRAST__API__API_KEY

    API Key

    CONTRAST__API__URL

    Contrast Agent URL

    CONTRAST__API__USER_NAME

    Contrast Agent Username

    CONTRAST__API__SERVICE_KEY

    Agent Service Key

Step 2: Edit the ARM template

Add the highlighted Contrast configuration values to the ARM template, as shown in the following examples.

.NET Core-specific configuration and .NET Framework-specific configuration provide additional configuration details.

  • .NET Core

    {
       "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
       "contentVersion": "1.0.0.0",
       "parameters": {
           "sites_name": {
               "defaultValue": "APP_NAME",
               "type": "String"
           }
       },
       "variables": {
       },
       "resources": [
           {
               "type": "Microsoft.Web/sites",
               "apiVersion": "2018-11-01",
               "name": "[parameters('sites_name')]",
               "location": "East US",
               "kind": "app",
               "properties": {
                   "siteConfig": {
                       "appSettings": [
                           {
                               "name": "CONTRAST__API__API_KEY",
                               "value": "<CONTRAST__API__API_KEY>",
                               "slotSetting": false
                           },
                           {
                               "name": "CONTRAST__API__SERVICE_KEY",
                               "value": "<CONTRAST__API__SERVICE_KEY>",
                               "slotSetting": false
                           },
                           {
                               "name": "CONTRAST__API__URL",
                               "value": "<CONTRAST__API__URL>",
                               "slotSetting": false
                           },
                           {
                               "name": "CONTRAST__API__USER_NAME",
                               "value": "<CONTRAST__API__USER_NAME>",
                               "slotSetting": false
                           },
                           {
                               "name": "CORECLR_ENABLE_PROFILING",
                               "value": "1",
                               "slotSetting": false
                           },
                           {
                               "name": "CORECLR_PROFILER",
                               "value": "{8B2CE134-0948-48CA-A4B2-80DDAD9F5791}",
                               "slotSetting": false
                           },
                           {
                               "name": "CORECLR_PROFILER_PATH_32",
                               "value": D:\\home\\SiteExtensions\\Contrast.NetCore.Azure.SiteExtension\\ContrastNetCoreAppService\\contrast\\runtimes\\win-x86\\native\\ContrastProfiler.dll",
                               "slotSetting": false
                           },
                           {
                               "name": "CORECLR_PROFILER_PATH_64",
                               "value": D:\\home\\SiteExtensions\\Contrast.NetCore.Azure.SiteExtension\\ContrastNetCoreAppService\\\contrast\\runtimes\\win-x64\\native\\ContrastProfiler.dll",
                               "slotSetting": false
                           }
                       ]
                   }
               },
               "resources": [
                   {
                       "name": "Contrast.NetCore.Azure.SiteExtension",
                       "type": "siteextensions",
                       "apiVersion": "2018-02-01",
                       "dependsOn": [
                           "[resourceId('Microsoft.Web/Sites', parameters('sites_name'))]"
                       ]
                   }
               ]
           }
       ]
    }
  • .NET Framework

    {
       "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
       "contentVersion": "1.0.0.0",
       "parameters": {
           "sites_name": {
               "defaultValue": "APP_NAME",
               "type": "String"
           }
       },
       "variables": {
       },
       "resources": [
           {
               "type": "Microsoft.Web/sites",
               "apiVersion": "2018-11-01",
               "name": "[parameters('sites_name')]",
               "location": "East US",
               "kind": "app",
               "properties": {
                   "siteConfig": {
                       "appSettings": [
                           {
                               "name": "CONTRAST__API__API_KEY",
                               "value": "<CONTRAST__API__API_KEY>",
                               "slotSetting": false
                           },
                           {
                               "name": "CONTRAST__API__SERVICE_KEY",
                               "value": "<CONTRAST__API__SERVICE_KEY>",
                               "slotSetting": false
                           },
                           {
                               "name": "CONTRAST__API__URL",
                               "value": "<CONTRAST__API__URL>",
                               "slotSetting": false
                           },
                           {
                               "name": "CONTRAST__API__USER_NAME",
                               "value": "<CONTRAST__API__USER_NAME>",
                               "slotSetting": false
                           },
                           {
                               "name": "COR_ENABLE_PROFILING",
                               "value": "1",
                               "slotSetting": false
                           },
                           {
                               "name": "COR_PROFILER",
                               "value": "{EFEB8EE0-6D39-4347-A5FE-4D0C88BC5BC1}",
                               "slotSetting": false
                           },
                           {
                               "name": "COR_PROFILER_PATH_32",
                               "value": "D:\\home\\SiteExtensions\\Contrast.NET.Azure.SiteExtension\\ContrastAppService\\ContrastProfiler-32.dll",
                               "slotSetting": false
                           },
                           {
                               "name": "COR_PROFILER_PATH_64",
                               "value": "D:\\home\\SiteExtensions\\Contrast.NET.Azure.SiteExtension\\ContrastAppService\\ContrastProfiler-64.dll",
                               "slotSetting": false
                           }
                       ]
                   }
               },
               "resources": [
                   {
                       "name": "Contrast.NET.Azure.SiteExtension",
                       "type": "siteextensions",
                       "apiVersion": "2018-02-01",
                       "dependsOn": [
                           "[resourceId('Microsoft.Web/Sites', parameters('sites_name'))]"
                       ]
                   }
               ]
           }
       ]
    }

Step 3: Deploy the application from the ARM template

Use one of these methods in the Azure documentation: