0
votes

I want to collect exception's stack in application insights to debug it on local PC later.

I have a ASP.NET MVC 5.2 application with .NET 4.7.2 framework.

I added NuGet package Microsoft.ApplicationInsights.SnapshotCollector to my project, my app insights keys:

<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>false</IsEnabledInDeveloperMode>
  <!-- How many times we need to see an exception before we ask for snapshots. -->
  <ThresholdForSnapshotting>1</ThresholdForSnapshotting>
  <!-- The maximum number of snapshots we collect for a single problem. -->
  <MaximumSnapshotsRequired>3</MaximumSnapshotsRequired>
  <!-- The maximum number of problems that we can be tracking at any time. -->
  <MaximumCollectionPlanSize>50</MaximumCollectionPlanSize>
  <!-- How often to reset problem counters. -->
  <ProblemCounterResetInterval>24:00:00</ProblemCounterResetInterval>
  <!-- The maximum number of snapshots allowed per day. -->
  <SnapshotsPerDayLimit>30</SnapshotsPerDayLimit>
  <!--Whether or not to collect snapshot in low IO priority thread.-->
  <SnapshotInLowPriorityThread>true</SnapshotInLowPriorityThread>
</Add>

(I follow the documentation: https://docs.microsoft.com/en-us/azure/application-insights/app-insights-snapshot-debugger )

I added this controller method to test:

    public ActionResult TestCatchException()
    {
        try
        {
            throw new WebException("Test web ex");
        }
        catch(WebException web_ex)
        {
            try
            {
                throw new Exception("Web Catch First Level", web_ex);
            }
            catch(Exception ex)
            {
                var telemetry = new TelemetryClient();
                telemetry.TrackException(ex);
            }
        }

        return RedirectToAction("Error", new { Text = "err" });
    }

then I look it on azure portal:

enter image description here

but no way to download exception snapshot. What is wrong?

1
You could refer to this article to download exception snapshot.Joey Cai

1 Answers

0
votes

Thank you for the very detailed question. From the information you provided, there are three possible reasons that snapshots are not being uploaded.

First, if you are debugging the application in Visual Studio, then DeveloperMode will be true. Please set the IsEnabledInDeveloperMode property to true in your Applicationinsights.config file.

Second, the exception has be to triggered twice before we’ll capture a snapshot. The first time we see the exception, we check if it is being tracked by App Insights and if it is, we collect the snapshot the second time we see the exception. If you are running the app from your local machine, you’ll need to trigger the exception twice in one execution of your web app. If you are running the app in Azure, you'll also need to trigger the exception twice making sure the app doesn't restart in between.

Third, if you are running this on your local machine, you may be closing the web app before the uploader can finish uploading the snapshot. Let your application run for a few minutes after generating the exceptions to give the uploader time to finish uploading the snapshot. This troubleshooting page explains how to view telemetry from the uploader to get more details about what is happening: https://docs.microsoft.com/en-us/azure/application-insights/app-insights-troubleshoot-snapshot-debugger.