代码之家  ›  专栏  ›  技术社区  ›  jdmac020

为什么应用程序洞察力阻止启动我的工作者角色?

  •  2
  • jdmac020  · 技术社区  · 9 年前

    this article 以及 here .

    在安装了nugget包并添加了一行代码之后,我在调试和发布模式下本地运行了云服务,并且能够看到AI信息被报告给Application Insights资源。因此,我将其打包并将新配置上传到我的云服务。

    this article 这一错误基本上告诉了我为什么它会继续回收,但没有任何关于如何处理它的线索。

    生产-WebReportDownloader_IN_0:BusyRole

    通常我可以从搜索异常和/或详细信息中得到足够的提示,但这次我找不到任何与我的问题类似的东西。我所能猜到的是,我的配置出现了一些小但关键的错误,但我还无法根据上面链接的说明确定我偏离了轨道的地方。

    我的服务配置。云文件。。。

        <?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>
    

    还有我的申请书。配置。。。

    <?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;
            }
    

    如果有任何见解,我将不胜感激(哈!)或者任何人都可以提供的指导。。。

    通过进一步的实验,我确定每当我试图直接调用Application Insights程序集时(例如在创建遥测客户端或直接设置ApplicationInsights资源键时),或者在由于跟踪而调用ApplicationInsights TraceListener时,都会调用下面的异常

    此外,我目前的目标是。NET 4.6.1(我之前忽略提及的信息)。

    2 回复  |  直到 9 年前
        1
  •  4
  •   jdmac020    9 年前

    在Azure的支持下,我终于能够建立一个屏幕共享会话。这位乐于助人的绅士几乎立即把注意力集中在这个问题上: 服务配置文件(Cloud.cscfg和.Local.cscfg) .

    VS17向导生成的默认值将其设置为osFamily=4,如下所示。。。

    .NET 4.5.2 configuration

    .NET 4.6.1 configuration

    这一小改动允许web角色在实例化遥测客户端时正确部署。

        2
  •  0
  •   Bruce Chen    9 年前

    Microsoft.ApplicationInsights.WindowsServer 2.4.1 刚才添加了您提到的用于设置插装键的代码,如下所示:

    WorkerRole。反恐精英

    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云服务后,它可以按预期工作,我可以从AI检索诊断数据,如下所示:

    enter image description here

    像 Install the SDK in each project 声明您需要设置 ApplicationInsights.config

    quick start 并在运行时检测应用程序以缩小此问题。此外,如果我错过了一些东西,或者你做了一些其他特殊代码,你可以更新你的问题,让我们解决这个问题。