代码之家  ›  专栏  ›  技术社区  ›  Paul

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

  •  0
  • Paul  · 技术社区  · 6 年前

    我们有一个Azure DevOps发布管道,它在一个位置设置我们所有的Azure资源。我可以用ARM模板成功地创建所有东西,但我正在努力将应用服务与AppInsights资源链接起来。

    如果我是手动操作,我会单击App服务的App Insights刀片中的“打开站点扩展”按钮(在“通过站点扩展启用Application Insights而不重新部署代码”标题下)。

    我已尝试将“Azure应用程序服务管理”步骤添加到我的发布管道,设置为安装“Application Insights extension for Azure应用程序服务”扩展:

    Screenshot of Release Pipeline Step for Installing AppInsights

    此外,我在发布管道中添加了一个“Azure应用服务管理”步骤,设置为“启用持续监视”:

    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),但仍然要求我在“应用程序洞察”刀片中“打开站点扩展”。

    1 回复  |  直到 5 年前
        1
  •  4
  •   Markus    6 年前

    在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

        2
  •  2
  •   4c74356b41    6 年前

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

        {
            "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

        3
  •  0
  •   Stuart Hallows    5 年前

    确保你的应用设置密钥是 APPINSIGHTS_INSTRUMENTATIONKEY 而不是 ApplicationInsights:InstrumentationKey . 在MS文档的某个地方,它给人的印象是你可以使用这两种方法。事实上不是这样的,在天青你 需要 若要使用前者,则不会为服务器端洞察启用应用程序洞察。