Application Insight Snapshot Debugger:未从.NET Full Framework网站推送快照

时间:2019-03-22 13:34:00

标签: asp.net azure azure-application-insights

我创建了一个全新的Web应用程序.NET Full Framework 4.7.2,添加了Application Insights Snapshot Collector,但是没有将快照推送到服务器。

我什至没有得到他们提到的hereDon't see the snapshot? troubleshoot链接。

我使用.NET Core应用程序测试了集成密钥,该密钥可以按预期工作,甚至我在该文档中提到的%TEMP%\Dumps64上都获得了日志。

使用.NET Framework应用程序时,在%TEMP%文件夹中看不到任何活动。异常被推送到Application Insights,因此集成密钥有效且捕获了异常。

这些是我添加的软件包:

<package id="Microsoft.ApplicationInsights" version="2.9.1" targetFramework="net472" />
<package id="Microsoft.ApplicationInsights.Agent.Intercept" version="2.4.0" targetFramework="net472" />
<package id="Microsoft.ApplicationInsights.DependencyCollector" version="2.9.1" targetFramework="net472" />
<package id="Microsoft.ApplicationInsights.PerfCounterCollector" version="2.9.1" targetFramework="net472" />
<package id="Microsoft.ApplicationInsights.SnapshotCollector" version="1.3.3" targetFramework="net472" />
<package id="Microsoft.ApplicationInsights.TraceListener" version="2.9.1" targetFramework="net472" />
<package id="Microsoft.ApplicationInsights.Web" version="2.9.1" targetFramework="net472" />
<package id="Microsoft.ApplicationInsights.WindowsServer" version="2.9.1" targetFramework="net472" />
<package id="Microsoft.ApplicationInsights.WindowsServer.TelemetryChannel" version="2.9.1" targetFramework="net472" />

这就是我的ApplicationInsights.config的样子:

<?xml version="1.0" encoding="utf-8"?>
<ApplicationInsights xmlns="http://schemas.microsoft.com/ApplicationInsights/2013/Settings">
  <InstrumentationKey>[MY INTEGRATION KEY IS HERE]</InstrumentationKey>
  <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"/>
    <Add Type="Microsoft.ApplicationInsights.Web.WebTestTelemetryInitializer, Microsoft.AI.Web"/>
    <Add Type="Microsoft.ApplicationInsights.Web.SyntheticUserAgentTelemetryInitializer, Microsoft.AI.Web">
      <!-- Extended list of bots:
            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-->
      <Filters>search|spider|crawl|Bot|Monitor|AlwaysOn</Filters>
    </Add>
    <Add Type="Microsoft.ApplicationInsights.Web.ClientIpHeaderTelemetryInitializer, Microsoft.AI.Web"/>
    <Add Type="Microsoft.ApplicationInsights.Web.OperationNameTelemetryInitializer, Microsoft.AI.Web"/>
    <Add Type="Microsoft.ApplicationInsights.Web.OperationCorrelationTelemetryInitializer, Microsoft.AI.Web"/>
    <Add Type="Microsoft.ApplicationInsights.Web.UserTelemetryInitializer, Microsoft.AI.Web"/>
    <Add Type="Microsoft.ApplicationInsights.Web.AuthenticatedUserIdTelemetryInitializer, Microsoft.AI.Web"/>
    <Add Type="Microsoft.ApplicationInsights.Web.AccountIdTelemetryInitializer, Microsoft.AI.Web"/>
    <Add Type="Microsoft.ApplicationInsights.Web.SessionTelemetryInitializer, Microsoft.AI.Web"/>
  </TelemetryInitializers>
  <!-- 
    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.
  -->
  <TelemetrySinks>
    <Add Name="default">
      <TelemetryProcessors>
        <Add Type="Microsoft.ApplicationInsights.Extensibility.PerfCounterCollector.QuickPulse.QuickPulseTelemetryProcessor, Microsoft.AI.PerfCounterCollector"/>
        <Add Type="Microsoft.ApplicationInsights.SnapshotCollector.SnapshotCollectorTelemetryProcessor, Microsoft.ApplicationInsights.SnapshotCollector">
          <!-- The default is true, but you can disable Snapshot Debugging by setting it to false -->
          <IsEnabled>true</IsEnabled>
          <!-- Snapshot Debugging is usually disabled in developer mode, but you can enable it by setting this to true. -->
          <!-- DeveloperMode is a property on the active TelemetryChannel. -->
          <IsEnabledInDeveloperMode>true</IsEnabledInDeveloperMode>
        </Add>
        <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"/>
    </Add>
  </TelemetrySinks>
  <TelemetryModules>
    <Add Type="Microsoft.ApplicationInsights.DependencyCollector.DependencyTrackingTelemetryModule, Microsoft.AI.DependencyCollector">
      <ExcludeComponentCorrelationHttpHeadersOnDomains>
        <!-- 
        Requests to the following hostnames will not be modified by adding correlation headers.         
        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>
      </ExcludeComponentCorrelationHttpHeadersOnDomains>
      <IncludeDiagnosticSourceActivities>
        <Add>Microsoft.Azure.EventHubs</Add>
        <Add>Microsoft.Azure.ServiceBus</Add>
      </IncludeDiagnosticSourceActivities>
    </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.AppServicesHeartbeatTelemetryModule, Microsoft.AI.WindowsServer"/>
    <Add Type="Microsoft.ApplicationInsights.WindowsServer.AzureInstanceMetadataTelemetryModule, Microsoft.AI.WindowsServer">
      <!--
      Remove individual fields collected here by adding them to the ApplicationInsighs.HeartbeatProvider 
      with the following syntax:

      <Add Type="Microsoft.ApplicationInsights.Extensibility.Implementation.Tracing.DiagnosticsTelemetryModule, Microsoft.ApplicationInsights">
        <ExcludedHeartbeatProperties>
          <Add>osType</Add>
          <Add>location</Add>
          <Add>name</Add>
          <Add>offer</Add>
          <Add>platformFaultDomain</Add>
          <Add>platformUpdateDomain</Add>
          <Add>publisher</Add>
          <Add>sku</Add>
          <Add>version</Add>
          <Add>vmId</Add>
          <Add>vmSize</Add>
          <Add>subscriptionId</Add>
          <Add>resourceGroupName</Add>
          <Add>placementGroupId</Add>
          <Add>tags</Add>
          <Add>vmScaleSetName</Add>
        </ExcludedHeartbeatProperties>
      </Add>

      NOTE: exclusions will be lost upon upgrade.
      -->
    </Add>
    <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>
    <Add Type="Microsoft.ApplicationInsights.Web.RequestTrackingTelemetryModule, Microsoft.AI.Web">
      <Handlers>
        <!-- 
        Add entries here to filter out additional handlers: 

        NOTE: handler configuration will be lost upon NuGet upgrade.
        -->
        <Add>Microsoft.VisualStudio.Web.PageInspector.Runtime.Tracing.RequestDataHttpHandler</Add>
        <Add>System.Web.StaticFileHandler</Add>
        <Add>System.Web.Handlers.AssemblyResourceLoader</Add>
        <Add>System.Web.Optimization.BundleHandler</Add>
        <Add>System.Web.Script.Services.ScriptHandlerFactory</Add>
        <Add>System.Web.Handlers.TraceHandler</Add>
        <Add>System.Web.Services.Discovery.DiscoveryRequestHandler</Add>
        <Add>System.Web.HttpDebugHandler</Add>
      </Handlers>
    </Add>
    <Add Type="Microsoft.ApplicationInsights.Web.ExceptionTrackingTelemetryModule, Microsoft.AI.Web"/>
    <Add Type="Microsoft.ApplicationInsights.Web.AspNetDiagnosticTelemetryModule, Microsoft.AI.Web"/>
  </TelemetryModules>
  <ApplicationIdProvider Type="Microsoft.ApplicationInsights.Extensibility.Implementation.ApplicationId.ApplicationInsightsApplicationIdProvider, Microsoft.ApplicationInsights"/>

<!-- 
    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.
  -->
    <TelemetryProcessors>
        <Add Type="Microsoft.ApplicationInsights.SnapshotCollector.SnapshotCollectorTelemetryProcessor, Microsoft.ApplicationInsights.SnapshotCollector">
            <!-- Snapshot Debugging is usually disabled when debugging in Visual Studio, but you can enable it by setting this to true. -->
            <IsEnabled>true</IsEnabled>
            <!-- Snapshot Debugging is usually disabled in developer mode, but you can enable it by setting this to true. -->
            <!-- DeveloperMode is a property on the active TelemetryChannel. -->
            <IsEnabledInDeveloperMode>true</IsEnabledInDeveloperMode>
            <!-- How many times we need to see an exception before we ask for snapshots. -->
            <ThresholdForSnapshotting>1</ThresholdForSnapshotting>
            <!-- Other properties are documented at https://aka.ms/pnv0qt -->
        </Add>
    </TelemetryProcessors>
</ApplicationInsights>

我想念什么?

2 个答案:

答案 0 :(得分:2)

最初在GitHub issue中回答了此问题。

因此,我花了将近一天的时间试图使快照调试器在旧版ASP.NET应用程序中工作,现在终于可以使用了! 虽然不能保证我遇到的问题与您遇到的问题相同,但我相信这很有可能,因为我遇到的症状基本相同。

TL; DR :它是<assemblyBinding>

问题

Application Insights可能更愿意(静静地?)忽略故障来尝试对故障进行恢复。

这就是对SnapshotCollectorTelemetryProcessor所做的事情。如果它无法加载,它只是默默地跳过它,并在没有它的情况下愉快地前进。 您可以通过输入任何垃圾而不是Microsoft.ApplicationInsights.SnapshotCollector.SnapshotCollectorTelemetryProcessor, Microsoft.ApplicationInsights.SnapshotCollector来进行验证 作为Type中的ApplicationInsights.config属性值。

如果您勾选TelemetryConfiguration.Active.DefaultTelemetrySink.TelemetryProcessors,它只会丢失那些未能加载的内容。

一种确定问题是否与程序集加载有关的可靠方法,只需在启动代码中的以下位置添加此行:

var _ = typeof(SnapshotCollectorTelemetryProcessor);

那应该触发错误。

AFAIK与类库项目不同,ASP.NET应用程序中的Web.config无法从<AutoGenerateBindingRedirects>中受益,而VS中的NuGet程序包管理器一旦移至{{1}就不会这样做}(或者像我一样使用“带有glob的新csproj”)。因此,您必须手动进行维护。

“修复”

从今天起,假设您的PackageReference文件中有这些参考版本,

csproj

您可能至少需要在Web.config中进行这些重定向

<PackageReference Include="Microsoft.ApplicationInsights.SnapshotCollector" Version="1.3.7" />
<PackageReference Include="Microsoft.ApplicationInsights.Web" Version="2.14.0" />

添加了这些内容之后,我可以看到在磁盘上创建了<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> <dependentAssembly> <assemblyIdentity name="Microsoft.ApplicationInsights" publicKeyToken="31bf3856ad364e35" culture="neutral" /> <bindingRedirect oldVersion="0.0.0.0-2.14.0.17971" newVersion="2.14.0.17971" /> </dependentAssembly> <dependentAssembly> <assemblyIdentity name="Microsoft.ApplicationInsights.SnapshotCollector" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" /> <bindingRedirect oldVersion="0.0.0.0-1.3.7.0" newVersion="1.3.7.0" /> </dependentAssembly> <dependentAssembly> <assemblyIdentity name="System.Diagnostics.DiagnosticSource" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" /> <bindingRedirect oldVersion="0.0.0.0-4.0.4.0" newVersion="4.0.4.0" /> </dependentAssembly> </assemblyBinding> 目录,并且在模拟异常以及门户中的一些快照之后不久。

其他怪癖

如上所述,默认情况下将配置错误地添加到SnapshotUploader的根目录中,而不是默认接收器中。

此外,由ApplicationInsights.config创建的接收器配置包含Microsoft.ApplicationInsights.Web的重复条目,这可能会导致在某些情况下采样的遥测次数少于预期。

答案 1 :(得分:0)

Application Insights快照调试器是作为App Services运行时的一部分预先安装的,但是您需要打开它以获取App Service应用程序的快照。部署应用程序后,即使您已在源代码中包括Application Insights SDK,也请按照以下步骤启用快照调试器。

  1. 转到Azure门户中的“应用程序服务”窗格。
  2. 导航至“设置”>“应用程序见解”窗格。

    enter image description here

  3. 按照窗格上的说明创建新资源,或选择现有的App Insights资源来监视您的应用程序。另外,请确保快照调试器的两个开关都处于打开状态。

    enter image description here

  4. 快照调试器现在已使用App Services应用程序设置启用。

enter image description here

启用快照调试器后,当您看不到变量和 Open Debug Snapshot选项时,这意味着您需要在应用程序洞察资源中添加适当的角色。

对快照的访问受基于角色的访问控制(RBAC)保护。要检查快照,必须先由订阅所有者将您添加到必要的角色。

订阅所有者应将Application Insights快照调试器角色分配给将检查快照的用户。订阅所有者可以为目标Application Insights资源或其资源组或订阅将该角色分配给单个用户或组。

  1. 导航到Azure门户中的Application Insights资源。

  2. 单击访问控制(IAM)。

  3. 单击+添加角色分配按钮。

  4. 从“角色”下拉列表中选择“ Application Insights快照调试器”。

  5. 搜索并输入用户要添加的名称。

  6. 单击“保存”按钮将用户添加到角色。

供参考,请遵循以下主题

https://docs.microsoft.com/en-us/azure/azure-monitor/app/snapshot-debugger-appservice

希望有帮助。