我有一个Azure云服务,它只有一个工作人员角色,每次部署、启动和运行都不会失败,但是我遇到了一些间歇性的问题,我想用Application来诊断。我遵循这篇文章和这里的指示。
在安装了nugget包并添加了一行代码之后,我以调试和发布模式在本地运行了云服务,并且能够看到AI信息被报告给Application资源。所以我打包了它,并将新的配置上传到我的云服务中。
但是,从云开始,工作人员的角色不会真正开始--进入循环死亡螺旋,在“诊断和解决问题”刀片中,我得到以下错误的变化,总是关于“System.Threading.AsyncLocal‘1’‘1’,并且无法加载RoleEntryPoint。”遵循这篇文章并没有给出更多的信息,因为这个错误很大程度上告诉了我为什么它一直在循环利用,而没有提供任何关于如何处理它的线索。
生产- WebReportDownloader_IN_0: BusyRole等待角色开始.未能加载角色入口点。System.TypeLoadException:无法从程序集'mscorlib、Version=4.0.0.0、Culture=neutral、PublicKeyToken=b77a5c561934e089‘加载'System.Threading.AsyncLocal`1’类型。在Microsoft.ApplicationInsights.Extensibility.SdkInternalOperationsMonitor.Exit() at Microsoft.ApplicationInsights.Extensibility.Implementation.TelemetryConfigurationFactory.Initialize(TelemetryConfiguration configuration、TelemetryModules模块、String serializedConfiguration) at Microsoft.ApplicationInsights.Extensibility.TelemetryConfiguration.get_Active() at WebReportDownloader..ctor()在C:\Users\User\Source\Repos\Program\WebReportDownloader\WebReportDownloader.cs:line 21 -内部异常堆栈跟踪的末端-在System.RuntimeTypeHandle.CreateInstance(RuntimeType类型、布尔publicOnly、布尔noCheck、布尔& canBeCached、RuntimeMethodHandleInternal& ctor、布尔& bNeedSecurityCheck)的System.RuntimeType.CreateInstanceSlow(布尔publicOnly、布尔skipCheckThis )System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly的布尔fillCache,StackCrawlMark& stackMark,Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment.InitializeRoleInternal(RoleType roleTypeEnum)的System.Activator.CreateInstance(类型类型,布尔nonPublic)的System.Activator.CreateInstance(类型),StackCrawlMark& stackMark)的布尔fillCache,StackCrawlMark&stackMark,最后退出时间: 2017/09/14,15:28:21.944。最后退出代码: 0。
通常,我可以从搜索异常和/或细节中得到足够的提示,但这一次我找不到任何类似于我的问题的东西。我所能猜到的是,一些很小但很关键的东西与我的配置不协调,但是我还无法根据我上面链接的说明来确定我已经偏离了轨道。
我的ServiceConfiguration.Cloud文件。
<?xml version="1.0" encoding="utf-8"?>
<ServiceConfiguration serviceName="WebReportDownloader" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceConfiguration" osFamily="4" osVersion="*" schemaVersion="2015-04.2.6">
<Role name="WebReportDownloader">
<Instances count="2" />
<ConfigurationSettings>
<Setting name="Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString" value="UseDevelopmentStorage=true" />
<Setting name="Microsoft.WindowsAzure.Plugins.RemoteAccess.Enabled" value="true" />
<Setting name="Microsoft.WindowsAzure.Plugins.RemoteAccess.AccountUsername" value="admin" />
<Setting name="Microsoft.WindowsAzure.Plugins.RemoteAccess.AccountEncryptedPassword" value="ENCRYPTEDVALUE" />
<Setting name="Microsoft.WindowsAzure.Plugins.RemoteAccess.AccountExpiration" value="2018-09-01T23:59:59.0000000-04:00" />
<Setting name="Microsoft.WindowsAzure.Plugins.RemoteForwarder.Enabled" value="true" />
<Setting name="APPINSIGHTS_INSTRUMENTATIONKEY" value="KEYVALUE" />
</ConfigurationSettings>
<Certificates>
<Certificate name="Microsoft.WindowsAzure.Plugins.RemoteAccess.PasswordEncryption" thumbprint="847EEDE0084CF57A5A774CAE9E700713726CC856" thumbprintAlgorithm="sha1" />
</Certificates>
</Role>
</ServiceConfiguration>
我的ApplicationInsights.config..。
<?xml version="1.0" encoding="utf-8"?>
<ApplicationInsights xmlns="http://schemas.microsoft.com/ApplicationInsights/2013/Settings">
<TelemetryInitializers>
<Add Type="Microsoft.ApplicationInsights.DependencyCollector.HttpDependenciesParsingTelemetryInitializer, Microsoft.AI.DependencyCollector"/>
<Add Type="Microsoft.ApplicationInsights.WindowsServer.AzureRoleEnvironmentTelemetryInitializer, Microsoft.AI.WindowsServer"/>
<Add Type="Microsoft.ApplicationInsights.WindowsServer.AzureWebAppRoleEnvironmentTelemetryInitializer, Microsoft.AI.WindowsServer"/>
<Add Type="Microsoft.ApplicationInsights.WindowsServer.BuildInfoConfigComponentVersionTelemetryInitializer, Microsoft.AI.WindowsServer"/>
</TelemetryInitializers>
<TelemetryModules>
<Add Type="Microsoft.ApplicationInsights.DependencyCollector.DependencyTrackingTelemetryModule, Microsoft.AI.DependencyCollector">
<ExcludeComponentCorrelationHttpHeadersOnDomains>
<!--
Requests to the following hostnames will not be modified by adding correlation headers.
This is only applicable if Profiler is installed via either StatusMonitor or Azure Extension.
Add entries here to exclude additional hostnames.
NOTE: this configuration will be lost upon NuGet upgrade.
-->
<Add>core.windows.net</Add>
<Add>core.chinacloudapi.cn</Add>
<Add>core.cloudapi.de</Add>
<Add>core.usgovcloudapi.net</Add>
<Add>localhost</Add>
<Add>127.0.0.1</Add>
</ExcludeComponentCorrelationHttpHeadersOnDomains>
</Add>
<Add Type="Microsoft.ApplicationInsights.Extensibility.PerfCounterCollector.PerformanceCollectorModule, Microsoft.AI.PerfCounterCollector">
<!--
Use the following syntax here to collect additional performance counters:
<Counters>
<Add PerformanceCounter="\Process(??APP_WIN32_PROC??)\Handle Count" ReportAs="Process handle count" />
...
</Counters>
PerformanceCounter must be either \CategoryName(InstanceName)\CounterName or \CategoryName\CounterName
NOTE: performance counters configuration will be lost upon NuGet upgrade.
The following placeholders are supported as InstanceName:
??APP_WIN32_PROC?? - instance name of the application process for Win32 counters.
??APP_W3SVC_PROC?? - instance name of the application IIS worker process for IIS/ASP.NET counters.
??APP_CLR_PROC?? - instance name of the application CLR process for .NET counters.
-->
</Add>
<Add Type="Microsoft.ApplicationInsights.Extensibility.PerfCounterCollector.QuickPulse.QuickPulseTelemetryModule, Microsoft.AI.PerfCounterCollector"/>
<Add Type="Microsoft.ApplicationInsights.WindowsServer.DeveloperModeWithDebuggerAttachedTelemetryModule, Microsoft.AI.WindowsServer"/>
<Add Type="Microsoft.ApplicationInsights.WindowsServer.UnhandledExceptionTelemetryModule, Microsoft.AI.WindowsServer"/>
<Add Type="Microsoft.ApplicationInsights.WindowsServer.UnobservedExceptionTelemetryModule, Microsoft.AI.WindowsServer">
<!--</Add>
<Add Type="Microsoft.ApplicationInsights.WindowsServer.FirstChanceExceptionStatisticsTelemetryModule, Microsoft.AI.WindowsServer">-->
</Add>
</TelemetryModules>
<TelemetryProcessors>
<Add Type="Microsoft.ApplicationInsights.Extensibility.PerfCounterCollector.QuickPulse.QuickPulseTelemetryProcessor, Microsoft.AI.PerfCounterCollector"/>
<Add Type="Microsoft.ApplicationInsights.Extensibility.AutocollectedMetricsExtractor, Microsoft.ApplicationInsights"/>
<Add Type="Microsoft.ApplicationInsights.WindowsServer.TelemetryChannel.AdaptiveSamplingTelemetryProcessor, Microsoft.AI.ServerTelemetryChannel">
<MaxTelemetryItemsPerSecond>5</MaxTelemetryItemsPerSecond>
<ExcludedTypes>Event</ExcludedTypes>
</Add>
<Add Type="Microsoft.ApplicationInsights.WindowsServer.TelemetryChannel.AdaptiveSamplingTelemetryProcessor, Microsoft.AI.ServerTelemetryChannel">
<MaxTelemetryItemsPerSecond>5</MaxTelemetryItemsPerSecond>
<IncludedTypes>Event</IncludedTypes>
</Add>
</TelemetryProcessors>
<TelemetryChannel Type="Microsoft.ApplicationInsights.WindowsServer.TelemetryChannel.ServerTelemetryChannel, Microsoft.AI.ServerTelemetryChannel"/>
<!--
Learn more about Application Insights configuration with ApplicationInsights.config here:
http://go.microsoft.com/fwlink/?LinkID=513840
Note: If not present, please add <InstrumentationKey>Your Key</InstrumentationKey> to the top of this file.
--></ApplicationInsights>
以及我的"OnStart()“方法,其中我实际上设置了InstrumentationKey..。
public override bool OnStart()
{
// Set the maximum number of concurrent connections
ServicePointManager.DefaultConnectionLimit = 12;
TelemetryConfiguration.Active.InstrumentationKey = RoleEnvironment.GetConfigurationSettingValue("APPINSIGHTS_INSTRUMENTATIONKEY");
// For information on handling configuration changes
// see the MSDN topic at https://go.microsoft.com/fwlink/?LinkId=166357.
bool result = base.OnStart();
Trace.TraceInformation("WebReportDownloader has been started");
return result;
}
我将感激任何洞察力(哈!)或者任何人都能提供的指导。
更新:
通过进一步的实验,我确定每当我试图直接调用ApplicationInsight程序集(例如创建遥测客户端或直接设置ApplicationInsights资源键时),或者当ApplicationInsight TraceListener由于跟踪而被调用时,下面的异常将被调用
无法从程序集'mscorlib、Version=4.0.0.0、Culture=neutral、PublicKeyToken=b77a5c561934e089‘加载“类型”。
如果我执行运行时工具,我可以获得一些基本的跟踪和日志到我的洞察力资源,但试图获得更多的东西仍然逃避我。
此外,我目前的目标是.NET 4.6.1 (我之前没有提到的信息)。
发布于 2017-10-12 14:47:19
在经过大量的Azure支持后,我终于能够设置一个屏幕共享会话。这位乐于助人的绅士几乎立即关注了这个问题:,因为我的工作角色项目的目标是.NET 4.6.1,,ServiceConfiguration文件( .Cloud.cscfg和.Local.cscfg),需要针对osFamily 5。
VS17向导生成的默认值将其设置为osFamily=4,如下所示.
但是,要使一切正常运行,我需要的是瞄准osFamily=5,如下所示.
这一小的更改允许web角色在实例化TelemetryClient的同时正确部署。
发布于 2017-09-21 08:23:13
根据您的描述,我创建了Azure Cloud项目,并在.NET Framework4.5上添加了单个工作者角色目标,然后安装了Microsoft.ApplicationInsights.WindowsServer 2.4.1,并添加了您刚才提到的用于设置检测键的代码,如下所示:
WorkerRole.cs
public class WorkerRole : RoleEntryPoint
{
private readonly CancellationTokenSource cancellationTokenSource = new CancellationTokenSource();
private readonly ManualResetEvent runCompleteEvent = new ManualResetEvent(false);
public override void Run()
{
Trace.TraceInformation("WorkerRoleB is running");
try
{
this.RunAsync(this.cancellationTokenSource.Token).Wait();
}
finally
{
this.runCompleteEvent.Set();
}
}
public override bool OnStart()
{
// Set the maximum number of concurrent connections
ServicePointManager.DefaultConnectionLimit = 12;
TelemetryConfiguration.Active.InstrumentationKey = RoleEnvironment.GetConfigurationSettingValue("APPINSIGHTS_INSTRUMENTATIONKEY");
// For information on handling configuration changes
// see the MSDN topic at https://go.microsoft.com/fwlink/?LinkId=166357.
bool result = base.OnStart();
Trace.TraceInformation("WorkerRoleB has been started");
return result;
}
public override void OnStop()
{
Trace.TraceInformation("WorkerRoleB is stopping");
this.cancellationTokenSource.Cancel();
this.runCompleteEvent.WaitOne();
base.OnStop();
Trace.TraceInformation("WorkerRoleB has stopped");
}
private async Task RunAsync(CancellationToken cancellationToken)
{
// TODO: Replace the following with your own logic.
while (!cancellationToken.IsCancellationRequested)
{
Trace.TraceInformation("Working");
await Task.Delay(1000);
}
}
}
在部署到Azure Cloud之后,它可以按预期工作,我可以从AI中检索诊断数据如下:
注意:( 在每个项目中安装SDK )声明需要将要复制的ApplicationInsights.config
文件始终复制到输出目录。
此外,您还可以在运行时参考快速启动和您的应用程序来缩小这个问题。此外,如果我遗漏了什么或者您做了其他一些特殊代码,您可以更新您的问题,以便我们解决这个问题。
https://stackoverflow.com/questions/46329504
复制相似问题