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

问题描述 投票:0回答:2

我们有一个Azure DevOps版本管道,它在一个位置设置我们所有的Azure资源。我可以使用ARM模板成功创建所有内容,但我很难将App Service与App Insights资源相关联。

如果我是手动执行此操作,则会在App Service的AppInsights刀片中单击“启用站点扩展”按钮(在“通过站点扩展启用应用程序洞察”标题下,而不重新部署代码)。

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

Screenshot of Release Pipeline Step for Installing AppInsights

此外,我在我的发布管道中添加了“Azure App Service Manage”步骤,设置为“Enable Continuous Monitoring”:

Screenshot of Release Pipeline Step for Enabling Continuous Monitoring

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

Screenshot of Azure Portal showing extension is not turned on

有什么方法可以自动完成吗?是通过ARM模板,PowerShell脚本还是其他东西?

编辑:在“扩展”刀片中,我可以看到“Azure应用服务的Application Insights扩展”(v2.6.5)和“ASP.NET核心日志记录扩展”(v2.2.0),但我仍然被要求“转向”在网站扩展“在”Aplication Insights“刀片。

azure azure-devops azure-web-app-service azure-pipelines-release-pipeline appinsights
2个回答
1
投票

我想你需要做那样的事情:

    {
        "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": {
                }
            }
        ]
    }

我从来没有尝试过这个,但看起来正确,链接到我发现的例子:https://github.com/tomasr/webapp-appinsights/blob/master/WebSite.json


0
投票

在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"
            },
            {
              "name": "XDT_MicrosoftApplicationInsights_Mode",
              "value": "recommended"
            },
            {
              "name": "InstrumentationEngine_EXTENSION_VERSION",
              "value": "~1"
            },
            {
              "name": "DiagnosticServices_EXTENSION_VERSION",
              "value": "~3"
            },
            {
              "name": "APPINSIGHTS_PROFILERFEATURE_VERSION",
              "value": "1.0.0"
            },
            {
              "name": "XDT_MicrosoftApplicationInsights_BaseExtensions",
              "value": "~1"
            }
          ]
        }
      }
    }

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

© www.soinside.com 2019 - 2024. All rights reserved.