azure - 通过 powershell 将应用程序见解链接到 Azure Web 应用程序

标签 azure powershell azure-application-insights azure-webapps

我正在尝试使用以下脚本通过 Powershell 将新的应用程序见解链接到现有的 Azure Web 应用程序。我能够创建新的应用洞察,但无法将新的应用洞察链接到现有的 Azure Web 应用。

$appInsights = New-AzResource -ResourceName 'MyWebsite09' -ResourceGroupName 'Test' `
-Tag @{ applicationType = 'web'; applicationName = 'sample1'} `
-ResourceType 'Microsoft.Insights/components' -Location 'North Central US' `
-PropertyObject @{'Application_Type'='web'} -Force

$appSetting = @{'APPINSIGHTS_INSTRUMENTATIONKEY'= $appInsights.Properties.InstrumentationKey}
Set-AzWebApp -Name 'sample1' -ResourceGroupName 'Test' -AppSettings $appSetting

最佳答案

以下是用于将应用程序见解与现有 Azure Web 应用程序链接起来的 Powershell 命令。由于您的代码不会启用应用程序洞察,请按照以下代码操作

$app = Get-AzWebApp -ResourceGroupName "AppMonitoredRG" -Name "AppMonitoredSite" -ErrorAction Stop
$newAppSettings = @{} # case-insensitive hash map
$app.SiteConfig.AppSettings | %{$newAppSettings[$_.Name] = $_.Value} # preserve non Application Insights application settings.
$newAppSettings["APPINSIGHTS_INSTRUMENTATIONKEY"] = "012345678-abcd-ef01-2345-6789abcd"; # set the Application Insights instrumentation key
$newAppSettings["APPLICATIONINSIGHTS_CONNECTION_STRING"] = "InstrumentationKey=012345678-abcd-ef01-2345-6789abcd"; # set the Application Insights connection string
$newAppSettings["ApplicationInsightsAgent_EXTENSION_VERSION"] = "~2"; # enable the ApplicationInsightsAgent
$app = Set-AzWebApp -AppSettings $newAppSettings -ResourceGroupName $app.ResourceGroup -Name $app.Name -ErrorAction Stop  

您可以 Refer 到此 MS DOC,以将应用程序见解完全链接到 Azure Web 应用程序。

或者,您甚至可以引用 SO 线程了解更多详细信息。

关于azure - 通过 powershell 将应用程序见解链接到 Azure Web 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68111325/

相关文章:

Azure VM 启动/停止日志

Azure DevOps - 小部件大小

azure - 将 Azure PaaS 网站与 SQL DB Iaas VM 连接。如何让它们在同一台机器上

powershell - 如何将powershell模块运送到生产环境?

Powershell:一劳永逸地正确着色 Get-Childitem 输出

c# - 测量方法执行时间的最佳方法

node.js - 在 AZURE 上上传 PERN 堆栈

powershell - 如何将哈希表传递给 PowerShell 中的函数?

node.js - 在服务器端 NodeJS Application Insights 事件中添加经过身份验证的用户 ID 信息

java - 从 jar 内的文件中发出解码对象