我们有一个Azure DevOps发布管道,该管道在一个位置设置了我们所有的Azure资源。我可以使用ARM模板成功创建所有内容,但是我正在努力将App Service与App Insights资源链接起来。
如果我是手动进行操作,请单击App Service的AppInsights刀片中的“打开站点扩展”按钮(在“通过站点扩展启用应用程序见解而无需重新部署代码”标题下)。
我尝试在发布管道中添加“ Azure App Service管理”步骤,设置为安装“ Azure App Service的Application Insights扩展”扩展:
此外,我已经在发布管道中添加了“ Azure App Service管理”步骤,并将其设置为“启用连续监视”:
但是结果仍然是AppInsights已连接,但未安装扩展:
有什么办法可以自动执行此操作?通过ARM模板,PowerShell脚本还是其他?
编辑:在“扩展”刀片中,我可以看到“ Azure App Service的Application Insights扩展”(v2.6.5)和“ ASP.NET Core日志记录扩展”(v2.2.0) ,但仍然要求我在“ Aplication Insights”刀片中“打开网站扩展”。
答案 0 :(得分:1)
为了让 Azure 门户显示与 Application Insights 的主动集成,您需要设置三个应用设置。
{
"resources": [
{
"name": "[parameters('name')]",
"type": "Microsoft.Web/sites",
"properties": {
"siteConfig": {
"appSettings": [
{
"name": "APPINSIGHTS_INSTRUMENTATIONKEY",
"value": "[reference('microsoft.insights/components/AppMonitoredSite', '2015-05-01').InstrumentationKey]"
},
{
"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"
}
另见我对此的其他回答:Azure Cli How to enable Application Insights for webapp
答案 1 :(得分:0)
我认为您需要执行以下操作:
{
"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
答案 2 :(得分: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上的文档
答案 3 :(得分:0)
请确保您的应用设置密钥为APPINSIGHTS_INSTRUMENTATIONKEY
,而不是ApplicationInsights:InstrumentationKey
。 MS文档中的某处给人的印象是您可以使用任何一个。实际上,情况并非如此,在Azure中,您需要使用前者,否则将不会为服务器端见解启用Application Insights。