如何在 Azure 应用服务中指定分层应用设置?



appsettings.json允许我们指定分层设置:

"ApplicationInsights": {
"InstrumentationKey": "..."
}

在代码中,它们是这样消耗的 -config["ApplicationInsights:InstrumentationKey"]

但是,尝试在应用服务地形配置中提供ApplicationInsights:InstrumentationKey

app_settings = {
"ApplicationInsights:InstrumentationKey"   = data.azurerm_application_insights.instance.instrumentation_key
}

导致以下错误消息:

Error: Error updating Application Settings for App Service "app505-dfpg-qa2-web-eastus2-gateway-apsvc": web.AppsClient#UpdateApplicationSettings: Failure responding to request: StatusCode=400 -- Original Error: autorest/azure: Service returned an error. Status=400 Code="BadRequest" Message="AppSetting with name 'ApplicationInsights:InstrumentationKey' is not allowed." Details=[{"Message":"AppSetting with name 'ApplicationInsights:InstrumentationKey' is not allowed."},{"Code":"BadRequest"},{"ErrorEntity":{"Code":"BadRequest","ExtendedCode":"04072","Message":"AppSetting with name 'ApplicationInsights:InstrumentationKey' is not allowed.","MessageTemplate":"AppSetting with name '{0}' is not allowed.","Parameters":["ApplicationInsights:InstrumentationKey"]}}]

从外观上看,这蔚蓝在抱怨,而不是地形。

那么,如果有的话,该怎么做呢?

编辑 1

请注意,这只是一个例子。我同样可以要求以下分层设置:

"YabaDabaDoo": {
"YogiBear": "..."
}

如何在应用服务配置中提供它?

正如错误所示,不允许使用名为"ApplicationInsights:InstrumentationKey"的 AppSetup。通过将检测密钥添加到 Azure 应用程序的应用设置,将 Azure 函数或 Azure 应用服务与应用程序见解实例相关联。你应该使用

app_settings {
"APPINSIGHTS_INSTRUMENTATIONKEY" = "${data.azurerm_application_insights.instance.instrumentation_key}"
}

您可以在此示例中获取更多详细信息。

最新更新