4

Why doesn't app insights turn on automatically after the release?

After executing the automated release, I'm getting this when navigating to app insights in the portal:

enter image description here

Here's how I've defined this in my ARM template:

{
  "type": "microsoft.insights/components",
  "kind": "web",
  "name": "[parameters('webAppName')]",
  "apiVersion": "2015-05-01",
  "location": "[parameters('location')]",
  "tags": {
    "[concat('hidden-link:', resourceGroup().id, '/providers/Microsoft.Web/sites/', parameters('webAppName'))]": "Resource",
    "displayName": "[parameters('webAppName')]"
  },
  "properties": {
    "Application_Type": "web"
  },
  "dependsOn": []
}

What am I doing wrong? Why isn't app insights automatically turned on?

Please note that I've added the following appsettings:

enter image description here

Alex Gordon
  • 57,446
  • 287
  • 670
  • 1,062

2 Answers2

9

In order for the Azure Portal to show an active integration with Application Insights, you need to set two app settings. The reason is that you also need to configure the Application Insights Agent Extension.

Note that setting the InstrumentationKey(deprecated) or connection string might be enough for your application to send telemetry to ApplicationInsights, e.g. if you are using ASP.NET Core and the corresponding Nuget package. But you will need both settings for the portal to show the active integration.

{
    "resources": [
        {
            "name": "[parameters('name')]",
            "type": "Microsoft.Web/sites",
            "properties": {
                "siteConfig": {
                    "appSettings": [
                        {
                            "name": "APPLICATIONINSIGHTS_CONNECTION_STRING",
                            "value": "[reference('microsoft.insights/components/AppMonitoredSite', '2015-05-01').ConnectionString]"
                        },
                        {
                            "name": "ApplicationInsightsAgent_EXTENSION_VERSION",
                            "value": "~2"
                        }
                    ]
                },
                "name": "[parameters('name')]",
                "serverFarmId": "[concat('/subscriptions/', parameters('subscriptionId'),'/resourcegroups/', parameters('serverFarmResourceGroup'), '/providers/Microsoft.Web/serverfarms/', parameters('hostingPlanName'))]",
                "hostingEnvironment": "[parameters('hostingEnvironment')]"
            },
            "dependsOn": [
                "[concat('Microsoft.Web/serverfarms/', parameters('hostingPlanName'))]",
                "microsoft.insights/components/AppMonitoredSite"
            ],
            "apiVersion": "2016-03-01",
            "location": "[parameters('location')]"
        },
        {
            "apiVersion": "2016-09-01",
            "name": "[parameters('hostingPlanName')]",
            "type": "Microsoft.Web/serverfarms",
            "location": "[parameters('location')]",
            "properties": {
                "name": "[parameters('hostingPlanName')]",
                "workerSizeId": "[parameters('workerSize')]",
                "numberOfWorkers": "1",
                "hostingEnvironment": "[parameters('hostingEnvironment')]"
            },
            "sku": {
                "Tier": "[parameters('sku')]",
                "Name": "[parameters('skuCode')]"
            }
        },
        {
            "apiVersion": "2015-05-01",
            "name": "AppMonitoredSite",
            "type": "microsoft.insights/components",
            "location": "West US 2",
            "properties": {
                "ApplicationId": "[parameters('name')]",
                "Request_Source": "IbizaWebAppExtensionCreate"
            }
        }
    ],
    "parameters": {
        "name": {
            "type": "string"
        },
        "hostingPlanName": {
            "type": "string"
        },
        "hostingEnvironment": {
            "type": "string"
        },
        "location": {
            "type": "string"
        },
        "sku": {
            "type": "string"
        },
        "skuCode": {
            "type": "string"
        },
        "workerSize": {
            "type": "string"
        },
        "serverFarmResourceGroup": {
            "type": "string"
        },
        "subscriptionId": {
            "type": "string"
        }
    },
    "$schema": "https://schema.management.azure.com/schemas/2014-04-01-preview/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0"
}

See also my other answer on this: Azure Cli How to enable Application Insights for webapp

Edit: updated based on the new information in the answer by BearOakheart.

Alex AIT
  • 17,361
  • 3
  • 36
  • 73
1

The accepted answer is outdated. It's not recommended to use APPINSIGHTS_INSTRUMENTATIONKEY with APPLICATIONINSIGHTS_CONNECTION_STRING. Whichever is provided last wins.

Using instrumentation key is deprecated, we should transition to using APPLICATIONINSIGHTS_CONNECTION_STRING instead.

Otherwise provided answer holds true. More info here:

https://learn.microsoft.com/en-us/azure/azure-monitor/app/migrate-from-instrumentation-keys-to-connection-strings

BearOakheart
  • 266
  • 3
  • 7
  • your answer is wrong. as of 13.02.2023, If you don't set up the APPINSIGHTS_INSTRUMENTATIONKEY the insights won't be linked with the app as seen in Azure Portal. Original Alex AIT answer is still correct, both settings are required. – Wojtas.Zet Feb 13 '23 at 16:50
  • 1
    Can you provide information how the answer is wrong? We have already moved to APPLICATIONINSIGHTS_CONNECTION_STRING without any issues on production workloads. – BearOakheart Apr 18 '23 at 12:45
  • I think this answer is correct. Refer to this page, which states reliability, security, privacy improvements of using a connection string: https://learn.microsoft.com/en-us/azure/azure-monitor/app/migrate-from-instrumentation-keys-to-connection-strings – Jeremy Jun 20 '23 at 16:00
  • Do you call add application insights in code? – Marcel Jun 27 '23 at 19:27
  • Documentation is wrong. Until I added the APPINSIGHTS_INSTRUMENTATIONKEY string it didn't work, simple as that. I am leaving this comment, so someone hitting this issue wont get frustrated. Azure is ever changing so it might be resolved now, but I have no time to check. – Wojtas.Zet Jul 04 '23 at 14:15