首先,在Vs上添加国际版Azure的遥测,参考Azure官方文档:

https://docs.azure.cn/en-us/azure-monitor/app/asp-net#step-1-add-the-application-insights-sdk 

我就不复制黏贴过来了。

而需要使用国内版遥测的最大问题是,默认Vs上是只能使用Global Azure的Application Insight,原因是vs安装后,默认环境是国际版Global的,所以当你在vs上登陆时,只能登陆国际版的账号。

一、修改全局Azure环境

所以我们要先修改我们本地环境的全局azure配置,官方文档如下:

https://docs.azure.cn/zh-cn/articles/azure-operations-guide/others/aog-portal-management-qa-vs2017-login#%E8%A7%A3%E5%86%B3%E6%96%B9%E6%A1%88

简述一下,需要手动在C:\Users\<user name>\AppData\Local\.IdentityService\AadConfigurations目录下,添加一个AadProvider.Configuration.json文件。

文件内容如下:

{
  "AuthenticationQueryParameters": null,
  "AsmEndPoint": "https://management.core.chinacloudapi.cn",
  "Authority": "https://login.chinacloudapi.cn/",
  "AzureResourceManagementEndpoint": "https://management.chinacloudapi.cn/",
  "AzureResourceManagementAudienceEndpoints": [ "https://management.core.chinacloudapi.cn/" ],
  "ClientIdentifier": "872cd9fa-d31f-45e0-9eab-6e460a02d1f1",
  "EnvironmentName": "Mooncake",
  "GraphEndpoint": "https://graph.chinacloudapi.cn",
  "MsaHomeTenantId": "f577cd82-810c-43f9-a1f6-0cc532871050",
  "NativeClientRedirect": "urn:ietf:wg:oauth:2.0:oob",
  "PortalEndpoint": "http://manage.windowsazure.cn",
  "ResourceEndpoint": "https://management.core.chinacloudapi.cn/",
  "ValidateAuthority": true,
  "VisualStudioOnlineEndpoint": "https://app.vssps.visualstudio.com/",
  "VisualStudioOnlineAudience": "499b84ac-1321-427f-aa17-267ca6975798"
}

  添加好文件后,我们现在可以在vs上用国内的Azure账号登录了。

 随后的在项目中用vs添加遥测的步骤,请参考官方文档:https://docs.azure.cn/en-us/azure-monitor/app/asp-net#step-1-add-the-application-insights-sdk 

注意,在Nuget包中,筛选“Microsoft.ApplicationInsights.Web”包,这个包一定要升级到最新版本,不然很可能会导致配置完的遥测无效。

 

二、修改applicationinsights.config配置文件

 说明:国际版的applicationinsight不需要修改以下配置。

对于国内版的ApplicationInsight,如果在操作完上述步骤后,网站打不开,或者网站打开了portal上看不到遥测数据,则需要进行下一步修改配置。

用以在ApplicationInsight.config中指定TelemetryChannel_Endpoint_Address.

请修改标注为黄色的配置

  1 <?xml version="1.0" encoding="utf-8"?>
  2 <ApplicationInsights xmlns="http://schemas.microsoft.com/ApplicationInsights/2013/Settings">
  3   
  4   <InstrumentationKey>a785b787-bd6a-c6c7-a48e-b8d47e28021f</InstrumentationKey>
  5   <TelemetryInitializers>
  6     <Add Type="Microsoft.ApplicationInsights.DependencyCollector.HttpDependenciesParsingTelemetryInitializer, Microsoft.AI.DependencyCollector"/>
  7     <Add Type="Microsoft.ApplicationInsights.WindowsServer.AzureRoleEnvironmentTelemetryInitializer, Microsoft.AI.WindowsServer"/>
  8     <Add Type="Microsoft.ApplicationInsights.WindowsServer.AzureWebAppRoleEnvironmentTelemetryInitializer, Microsoft.AI.WindowsServer"/>
  9     <Add Type="Microsoft.ApplicationInsights.WindowsServer.BuildInfoConfigComponentVersionTelemetryInitializer, Microsoft.AI.WindowsServer"/>
 10     <Add Type="Microsoft.ApplicationInsights.Web.WebTestTelemetryInitializer, Microsoft.AI.Web"/>
 11     <Add Type="Microsoft.ApplicationInsights.Web.SyntheticUserAgentTelemetryInitializer, Microsoft.AI.Web">
 12       <!-- Extended list of bots:
 13             search|spider|crawl|Bot|Monitor|BrowserMob|BingPreview|PagePeeker|WebThumb|URL2PNG|ZooShot|GomezA|Google SketchUp|Read Later|KTXN|KHTE|Keynote|Pingdom|AlwaysOn|zao|borg|oegp|silk|Xenu|zeal|NING|htdig|lycos|slurp|teoma|voila|yahoo|Sogou|CiBra|Nutch|Java|JNLP|Daumoa|Genieo|ichiro|larbin|pompos|Scrapy|snappy|speedy|vortex|favicon|indexer|Riddler|scooter|scraper|scrubby|WhatWeb|WinHTTP|voyager|archiver|Icarus6j|mogimogi|Netvibes|altavista|charlotte|findlinks|Retreiver|TLSProber|WordPress|wsr-agent|http client|Python-urllib|AppEngine-Google|semanticdiscovery|facebookexternalhit|web/snippet|Google-HTTP-Java-Client-->
 14       <Filters>search|spider|crawl|Bot|Monitor|AlwaysOn</Filters>
 15     </Add>
 16     <Add Type="Microsoft.ApplicationInsights.Web.ClientIpHeaderTelemetryInitializer, Microsoft.AI.Web"/>
 17     <Add Type="Microsoft.ApplicationInsights.Web.OperationNameTelemetryInitializer, Microsoft.AI.Web"/>
 18     <Add Type="Microsoft.ApplicationInsights.Web.OperationCorrelationTelemetryInitializer, Microsoft.AI.Web"/>
 19     <Add Type="Microsoft.ApplicationInsights.Web.UserTelemetryInitializer, Microsoft.AI.Web"/>
 20     <Add Type="Microsoft.ApplicationInsights.Web.AuthenticatedUserIdTelemetryInitializer, Microsoft.AI.Web"/>
 21     <Add Type="Microsoft.ApplicationInsights.Web.AccountIdTelemetryInitializer, Microsoft.AI.Web"/>
 22     <Add Type="Microsoft.ApplicationInsights.Web.SessionTelemetryInitializer, Microsoft.AI.Web"/>
 23   </TelemetryInitializers>
 24   <TelemetryModules>
 25 
 26      <Add Type="Microsoft.ApplicationInsights.Extensibility.PerfCounterCollector.QuickPulse.QuickPulseTelemetryModule, Microsoft.AI.PerfCounterCollector">
 27       <QuickPulseServiceEndpoint>https://quickpulse.applicationinsights.azure.cn/QuickPulseService.svc</QuickPulseServiceEndpoint>
 28 </Add>
 29 
 30     <Add Type="Microsoft.ApplicationInsights.DependencyCollector.DependencyTrackingTelemetryModule, Microsoft.AI.DependencyCollector">
 31       <ExcludeComponentCorrelationHttpHeadersOnDomains>
 32         <!-- 
 33         Requests to the following hostnames will not be modified by adding correlation headers.         
 34         Add entries here to exclude additional hostnames.
 35         NOTE: this configuration will be lost upon NuGet upgrade.
 36         -->
 37         <Add>core.windows.net</Add>
 38         <Add>core.chinacloudapi.cn</Add>
 39         <Add>core.cloudapi.de</Add>
 40         <Add>core.usgovcloudapi.net</Add>
 41       </ExcludeComponentCorrelationHttpHeadersOnDomains>
 42       <IncludeDiagnosticSourceActivities>
 43         <Add>Microsoft.Azure.EventHubs</Add>
 44         <Add>Microsoft.Azure.ServiceBus</Add>
 45       </IncludeDiagnosticSourceActivities>
 46     </Add>
 47     <Add Type="Microsoft.ApplicationInsights.Extensibility.PerfCounterCollector.PerformanceCollectorModule, Microsoft.AI.PerfCounterCollector">
 48       <!--
 49       Use the following syntax here to collect additional performance counters:
 50       
 51       <Counters>
 52         <Add PerformanceCounter="\Process(??APP_WIN32_PROC??)\Handle Count" ReportAs="Process handle count" />
 53         ...
 54       </Counters>
 55       
 56       PerformanceCounter must be either \CategoryName(InstanceName)\CounterName or \CategoryName\CounterName
 57       
 58       NOTE: performance counters configuration will be lost upon NuGet upgrade.
 59       
 60       The following placeholders are supported as InstanceName:
 61         ??APP_WIN32_PROC?? - instance name of the application process  for Win32 counters.
 62         ??APP_W3SVC_PROC?? - instance name of the application IIS worker process for IIS/ASP.NET counters.
 63         ??APP_CLR_PROC?? - instance name of the application CLR process for .NET counters.
 64       -->
 65     </Add>
 66     <Add Type="Microsoft.ApplicationInsights.Extensibility.PerfCounterCollector.QuickPulse.QuickPulseTelemetryModule, Microsoft.AI.PerfCounterCollector"/>
 67     <Add Type="Microsoft.ApplicationInsights.WindowsServer.AppServicesHeartbeatTelemetryModule, Microsoft.AI.WindowsServer"/>
 68     <Add Type="Microsoft.ApplicationInsights.WindowsServer.AzureInstanceMetadataTelemetryModule, Microsoft.AI.WindowsServer">
 69       <!--
 70       Remove individual fields collected here by adding them to the ApplicationInsighs.HeartbeatProvider 
 71       with the following syntax:
 72       
 73       <Add Type="Microsoft.ApplicationInsights.Extensibility.Implementation.Tracing.DiagnosticsTelemetryModule, Microsoft.ApplicationInsights">
 74         <ExcludedHeartbeatProperties>
 75           <Add>osType</Add>
 76           <Add>location</Add>
 77          <Add>name</Add>
 78           <Add>offer</Add>
 79           <Add>platformFaultDomain</Add>
 80           <Add>platformUpdateDomain</Add>
 81           <Add>publisher</Add>
 82           <Add>sku</Add>
 83           <Add>version</Add>
 84           <Add>vmId</Add>
 85           <Add>vmSize</Add>
 86           <Add>subscriptionId</Add>
 87           <Add>resourceGroupName</Add>
 88           <Add>placementGroupId</Add>
 89           <Add>tags</Add>
 90           <Add>vmScaleSetName</Add>
 91         </ExcludedHeartbeatProperties>
 92       </Add>
 93             
 94       NOTE: exclusions will be lost upon upgrade.
 95       -->
 96     </Add>
 97     <Add Type="Microsoft.ApplicationInsights.WindowsServer.DeveloperModeWithDebuggerAttachedTelemetryModule, Microsoft.AI.WindowsServer"/>
 98     <Add Type="Microsoft.ApplicationInsights.WindowsServer.UnhandledExceptionTelemetryModule, Microsoft.AI.WindowsServer"/>
 99     <Add Type="Microsoft.ApplicationInsights.WindowsServer.UnobservedExceptionTelemetryModule, Microsoft.AI.WindowsServer">
100       <!--</Add>
101     <Add Type="Microsoft.ApplicationInsights.WindowsServer.FirstChanceExceptionStatisticsTelemetryModule, Microsoft.AI.WindowsServer">-->
102     </Add>
103     <Add Type="Microsoft.ApplicationInsights.Web.RequestTrackingTelemetryModule, Microsoft.AI.Web">
104       <Handlers>
105         <!-- 
106         Add entries here to filter out additional handlers: 
107         
108         NOTE: handler configuration will be lost upon NuGet upgrade.
109         -->
110         <Add>Microsoft.VisualStudio.Web.PageInspector.Runtime.Tracing.RequestDataHttpHandler</Add>
111         <Add>System.Web.StaticFileHandler</Add>
112         <Add>System.Web.Handlers.AssemblyResourceLoader</Add>
113         <Add>System.Web.Optimization.BundleHandler</Add>
114         <Add>System.Web.Script.Services.ScriptHandlerFactory</Add>
115         <Add>System.Web.Handlers.TraceHandler</Add>
116         <Add>System.Web.Services.Discovery.DiscoveryRequestHandler</Add>
117         <Add>System.Web.HttpDebugHandler</Add>
118       </Handlers>
119     </Add>
120     <Add Type="Microsoft.ApplicationInsights.Web.ExceptionTrackingTelemetryModule, Microsoft.AI.Web"/>
121     <Add Type="Microsoft.ApplicationInsights.Web.AspNetDiagnosticTelemetryModule, Microsoft.AI.Web"/>
122   </TelemetryModules>
123 
124   <ApplicationIdProvider Type="Microsoft.ApplicationInsights.Extensibility.Implementation.ApplicationId.ApplicationInsightsApplicationIdProvider, Microsoft.ApplicationInsights">
125       <ProfileQueryEndpoint>https://dc.applicationinsights.azure.cn/api/profiles/{0}/appId</ProfileQueryEndpoint>
126   </ApplicationIdProvider>
127 
128    <TelemetrySinks>
129     <Add Name="default">
130       <TelemetryProcessors>
131         <Add Type="Microsoft.ApplicationInsights.Extensibility.PerfCounterCollector.QuickPulse.QuickPulseTelemetryProcessor, Microsoft.AI.PerfCounterCollector"/>
132         <Add Type="Microsoft.ApplicationInsights.Extensibility.AutocollectedMetricsExtractor, Microsoft.ApplicationInsights"/>
133         <Add Type="Microsoft.ApplicationInsights.WindowsServer.TelemetryChannel.AdaptiveSamplingTelemetryProcessor, Microsoft.AI.ServerTelemetryChannel">
134           <MaxTelemetryItemsPerSecond>5</MaxTelemetryItemsPerSecond>
135           <ExcludedTypes>Event</ExcludedTypes>
136         </Add>
137         <Add Type="Microsoft.ApplicationInsights.WindowsServer.TelemetryChannel.AdaptiveSamplingTelemetryProcessor, Microsoft.AI.ServerTelemetryChannel">
138           <MaxTelemetryItemsPerSecond>5</MaxTelemetryItemsPerSecond>
139           <IncludedTypes>Event</IncludedTypes>
140         </Add>
141       </TelemetryProcessors>
142       
143       <TelemetryChannel Type="Microsoft.ApplicationInsights.WindowsServer.TelemetryChannel.ServerTelemetryChannel, Microsoft.AI.ServerTelemetryChannel">
144          <EndpointAddress>https://dc.applicationinsights.azure.cn/v2/track</EndpointAddress>
145       </TelemetryChannel>
146 
147     </Add>
148   </TelemetrySinks>
149 <!-- 
150     Learn more about Application Insights configuration with ApplicationInsights.config here: 
151     http://go.microsoft.com/fwlink/?LinkID=513840
152     
153     Note: If not present, please add <InstrumentationKey>Your Key</InstrumentationKey> to the top of this file.
154   --></ApplicationInsights>

 

 

 

三、如果在vs中右键找不到application insight配置选项时的解决方案。

选择扩展-管理扩展

 

 

在漫游扩展管理器中,搜索Insight,下载两个Developer Analytics Tools

 

 

 然后在已安装中搜索insight,确保两个developer Analytics Tools都时已开启状态。

 

posted on 2020-06-01 14:08  慕凡尘  阅读(526)  评论(0编辑  收藏  举报