如何从发布管道/ ARM模板设置应用程序见解

Pau*_*aul 5 azure azure-application-insights azure-web-app-service azure-devops azure-pipelines-release-pipeline

我们有一个Azure DevOps发布管道,该管道在一个位置设置了我们所有的Azure资源。我可以使用ARM模板成功创建所有内容,但是我正在努力将App Service与App Insights资源链接起来。

如果是手动执行的操作,请单击App Service的AppInsights刀片中的“打开网站扩展”按钮(在标题“通过网站扩展启用应用程序见解而无需重新部署代码”下)。

我尝试在发布管道中添加“ Azure App Service管理”步骤,设置为安装“ Azure App Service的Application Insights扩展”扩展:

安装AppInsights的发布管道步骤的屏幕快照

另外,我在发布管道中添加了“ Azure App Service管理”步骤,设置为“启用连续监视”:

启用持续监视的发布管道步骤的屏幕快照

但是结果仍然是AppInsights已连接,但未安装扩展:

显示扩展名未打开的Azure Portal的屏幕截图

有什么办法可以自动执行此操作吗?通过ARM模板,PowerShell脚本还是其他?

编辑:在“扩展”刀片中,我可以看到“ Azure App Service的Application Insights扩展”(v2.6.5)和“ ASP.NET Core Logging扩展”(v2.2.0),但是仍然需要“打开”网站上的网站扩展”中的“ Aplication Insights”边栏。

Mar*_*kus 11

在 ARM 模板中,您可以执行以下操作:

{
  "type": "Microsoft.Web/sites",
  "apiVersion": "2018-02-01",
  "name": "[variables('web_app_service_name')]",
  "location": "[resourceGroup().location]",
  "dependsOn": [
    "[resourceId('Microsoft.Web/serverfarms', variables('plan_name'))]",
    "[resourceId('Microsoft.Insights/components', variables('app_insights_name'))]"
  ],
  "kind": "app",
  "properties": {
    "siteConfig": {
      "appSettings": [
        {
          "name": "APPINSIGHTS_INSTRUMENTATIONKEY",
          "value": "[reference(variables('app_insights_name'), '2015-05-01').InstrumentationKey]"
        },
        {
          "name": "ApplicationInsightsAgent_EXTENSION_VERSION",
          "value": "~2"
        }
      ]
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

请参阅https://docs.microsoft.com/en-us/azure/azure-monitor/app/azure-web-apps#automate-monitoring上的文档

  • 我遇到了与 ARM 未自动启用 AppInsights 相同的问题。我首先添加了 ApplicationInsightsAgent_EXTENSION_VERSION=~2。按照上述故障排除指南,我发现 IKeyExists = false。设置 APPINSIGHTS_INSTRUMENTATIONKEY 固定 IKeyExists = true。这两个更改足以解决我的问题。 (2认同)

4c7*_*b41 2

我认为你需要做这样的事情:

    {
        "apiVersion": "2015-08-01",
        "name": "[parameters('webSiteName')]",
        "type": "Microsoft.Web/sites",
        "location": "[resourceGroup().location]",
        "tags": {
            "[concat('hidden-related:', resourceGroup().id, '/providers/Microsoft.Web/serverfarms/', parameters('hostingPlanName'))]": "Resource",
            "displayName": "Website"
        },
        "dependsOn": [
            "[resourceId('Microsoft.Web/serverfarms/', parameters('hostingPlanName'))]",
            "[resourceId('microsoft.insights/components/', parameters('appInsightsName'))]"
        ],
        "properties": {
            "name": "[parameters('webSiteName')]",
            "serverFarmId": "[resourceId('Microsoft.Web/serverfarms', parameters('hostingPlanName'))]"
        },
        "resources": [
            {
                "apiVersion": "2015-08-01",
                "name": "appsettings",
                "type": "config",
                "dependsOn": [
                    "[resourceId('Microsoft.Web/Sites', parameters('webSiteName'))]",
                    "Microsoft.ApplicationInsights.AzureWebSites"
                ],
                "properties": {
                    "APPINSIGHTS_INSTRUMENTATIONKEY": "[reference(concat('microsoft.insights/components/', parameters('appInsightsName'))).InstrumentationKey]"
                }
            },
            {
                // this bit installs application insights extension
                "apiVersion": "2015-08-01",
                "name": "Microsoft.ApplicationInsights.AzureWebSites",
                "type": "siteextensions",
                "dependsOn": [
                    "[resourceId('Microsoft.Web/Sites', parameters('webSiteName'))]"
                ],
                "properties": {
                }
            }
        ]
    }
Run Code Online (Sandbox Code Playgroud)

我从未真正尝试过这个,但看起来是正确的,链接到我找到的示例: https: //github.com/tomasr/webapp-appinsights/blob/master/WebSite.json