可配置的Application Insights仪表键 [英] Configurable Application Insights Instrumentation Key

查看:97
本文介绍了可配置的Application Insights仪表键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何最好地使Application Inisghts的工具密钥可配置,以允许Azure管理员管理MVC5 Web应用程序的App Services部署的设置? MVC应用程序初始化中是否有某个事件应该在此完成,或者几乎可以在任何时候进行?我也在使用跟踪侦听器集成.

How can I best make the Application Inisghts' Instrumentation Key configurable in a way that allows an Azure Administrator to manage the settings for an App Services deployment of an MVC5 web application? Is there a certain event in an MVC application initialization where this should be done or is it okay to do it at pretty much any point? I am using the Trace Listener integration as well.

默认情况下,在ApplicationInsights.config文件中设置了Instrumentation Key(iKey).此外,如果包括JavaScript部分,则会在_Layout.cshtml文件中再次设置iKey.这是需要管理iKey的两个不同地方.

By default, the Instrumentation Key (iKey) is set in the ApplicationInsights.config file. Additionally, if you include the JavaScript portions, the iKey is again set in the _Layout.cshtml file. This is two different places with an iKey that you need to manage.

我希望能够通过Azure门户的应用程序服务-> 应用程序设置选项卡来管理此密钥.原因是:

I want to be able to manage this key via the App Services -> Application settings tab of the Azure Portal. The reasons are:

  1. 我想部署此应用程序的多个实例,每个实例都有自己的唯一iKey
  2. 我想定期更改此iKey(因为原因)
  3. 我既不想将此iKey存储在我们的代码存储库中(也可以将"dev" iKey存储在代码存储库中),也不希望由我们的构建自动化来管理它(同样,因为原因) )
  1. I want to deploy multiple instances of this applications, each with its own unique iKey
  2. I want to change this iKey periodically (because reasons)
  3. I don't want this iKey stored in our code repository (it's okay for a "dev" iKey to be in code repo) nor do I want it to be managed by our build automation (again, because reasons)

推荐答案

您指定的所有方法都很棒.我们的建议是使用web.config应用程序设置,并在global.asax.cs中使用它进行标准初始化.在我们初始化为OnBeginRequest()之前,不会在遥测之前发送遥测信息.

All of the methods you specified are great. Our recommendation is to use a web.config app setting and using this in the global.asax.cs for standard initialization. No telemetry will be sent before the initlization as we hook into OnBeginRequest().

https://docs.microsoft.com/zh-cn/azure/application-insights/app-insights-api-custom-events-metrics#a-namedynamic-ikeya-dynamic-instrumentation -键

另一种可行的方法是设置APPINSIGHTS_INSTRUMENTATIONKEY环境变量,该环境变量由SDK拾取.当然,这取决于您是否在同一台计算机上有多个应用程序.

Another method that might work well is to set the APPINSIGHTS_INSTRUMENTATIONKEY environment variable as it's picked up by the SDK. Of course that depends on if you have multiple apps on the same machine.

查看全文

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆