none
What am i missing for AI crash reports to show on dashboard RRS feed

  • Question

  • HI all,

    I recently started using Application insights in the latest update to my app.  I am really liking the information it provides and intend to expand this with other events and metrics in the near future. However, one measurement that isn't coming through at all is crash reports This is true both from the field and in dev sessions where I have tried to explicitly force crash telemetry with explicit calls to TelemetryClient.TrackException and some forced exceptions.

    When I look in the dashboard I see:

    So the text here suggests I need to configure crashes in the dashboard. Clicking either of these takes me to an unhelpful screen with links to general info about setting up application insights, and I feel like I have followed the steps in there. Wat it amounts to in the end is

    "Monitor crash frequency:
    If you haven't done this already, add Application Insights to your app project, and republish it.
    Crashes show up on your application's overview blade in the Application Insights portal."

    (from

    https://azure.microsoft.com/en-us/documentation/articles/app-insights-windows-crashes/)

    So what am I missing. Near the top of App.xaml.cs is the following code

                //Initialize Application Insights
                WindowsAppInitializer.InitializeAsync();
                ApplicationInsightsUITelemetry = new TelemetryClient();
                ApplicationInsightsUITelemetry.InstrumentationKey = TelemetryConfiguration.Active.InstrumentationKey;
                var assemblyName = new AssemblyName(Assembly.GetExecutingAssembly().FullName);
                ApplicationInsightsUITelemetry.TrackEvent(assemblyName.Version.ToString());

    The last 2 lines are just in there to grab the version as an event. However, they are not in the released build right now so I can see that events from my local version, where i'm forcing exceptions and tracking them, is showing up in application insights. It's just the crash data that isn't there.

    One caveat in this is that I'm also using BugSense / Splunk Mint.  Is there any chance of that blocking AI from grabbing crashes?

    Ultimately, I have some crashes in the field that show up in Slunk and I'm not able to repro locally.  The extra info AI provides will help with understanding what's going on and ultimately I want to ditch splunk. However, I'd like to make sure AI is going to work for me first and that means seeing crashes and being able to compare the crash reporting from AI with that in splunk.

    Anyway, there must be something I am missing in either how i'm setting this up, or how i'm using the dashboard that will enable me to see application crashes. Any ideas?

    Thanks for your help in this. 



    • Edited by bluechrism Monday, September 21, 2015 6:05 PM
    Monday, September 21, 2015 6:03 PM

Answers

  • Hi Starkey, 

    There are several points to address:

    1. Calling TrackException with exception is tracking the exception as a UserCode exception. To track the exception as unhanded one you will need to wrap the code with ExceptionTelemetry and set ExceptionTelemetry.HandledAt to ExceptionHandledAt.Unhandled.

    Handled exceptions are not shown in the Crashes metric, only in Diagnostics --> Search. 

    2. The Application Insights SDK for Silverlight currently has a bug that prevents unhanded exception

    from being reported.

    The workaround is to do the exception tracking manually. 

    a. Replace 

    WindowsAppInitializer.InitializeAsync();

    with

    WindowsAppInitializer.InitializeAsync(WindowsCollectors.Metadata | WindowsCollectors.PageView | WindowsCollectors.Session);
    
     

    (This will prevent the default exception handling)

    b. Make sure the following line exists in App constructor, if not add it:

    UnhandledException += Application_UnhandledException;

    c. Add these usings:

    using Microsoft.ApplicationInsights;
    using Microsoft.ApplicationInsights.DataContracts;
    using Microsoft.ApplicationInsights.Extensibility;
    using Microsoft.ApplicationInsights.Channel; 
    

    d. Add the following code to Application_UnhandledException:

    if (TelemetryConfiguration.Active.TelemetryChannel isPersistenceChannel)
    {
      TelemetryClient client = newTelemetryClient();
      ExceptionTelemetry ex = newExceptionTelemetry(e.ExceptionObject);
      ex.HandledAt = ExceptionHandledAt.Unhandled;
      client.TrackException(ex);
      client.Flush();
    }

    Notes: with this workaround the crashes will be flushed to disk and will only get sent once the app is re-openned. In addition, crashes that will thrown on App startup (~2 seconds from app startup) will not be tracked. 

    3. InitializeAsync returns a task, if you intend to send events at app startup, you should either await on it or use ContinueWith.  

    • Marked as answer by bluechrism Wednesday, December 2, 2015 2:27 PM
    Wednesday, December 2, 2015 6:33 AM
    Moderator
  • My conclusion in the end is that for Windows Phone 8 Silverlight applications, this feature of Application Insights is unsupported.  Even in an empty app with an empty app insights I couldn't get exception tracking to work.

    My work around for this is that in the places where I think exceptions could happen, I am using the catch statement to create an application insights event and load that event up with the message, stack trace and some custom variables relevant to the application. Doing these seems to serve me well enough for right now - I do get these events.

    If someone can prove me wrong regarding this working on a WP8.0 Silverlight app then  by all means, mark a different post as the answer, and let me know what I was doing wrong.

    • Marked as answer by bluechrism Tuesday, December 1, 2015 4:56 PM
    Tuesday, December 1, 2015 4:56 PM

All replies

  • I believe there's a very high chance that Bugsense/Slunk are interfering. There's also a chance that you've never had a crash.

    I'd remove the Bugsense/Slunk code, then put some code in to deliberately crash the app (throw an unhandled exception) and run the app.


    http://bc3te.ch/brandonh

    Friday, September 25, 2015 1:49 AM
  • Hdy Brandon, thanks for the reply.

    "There's also a chance that you've never had a crash."

    I only wish this were true. Bugsense tells me I had 40 key not found exceptions over the last 3 days, plus a handful of other bugs. Problem is that I can't repro the scenario to figure out why these exceptions occur (stack traces on their own are only so helpful).  The extra data in AI should help with that - e.g being able to see stats for that session including the user's route through the app..

    "I'd remove the Bugsense/Slunk code, then put some code in to deliberately crash the app (throw an unhandled exception) and run the app."

    I've tried this in a dev build and have seen other events from that dev build show up, but not the crashes that I was forcing.  I tried adding explicit calls to the TelemetryClient.TrackException(Exception someException) method and have confirmed that under debugging, they are getting hit, but they also don't show up.


    • Edited by bluechrism Friday, September 25, 2015 4:20 AM
    Friday, September 25, 2015 4:19 AM
  • I would watch out for the other bug trackers possibly causing interference. When you call the InitializeAsync function the AI SDK will go out and register an unhanded exception handler. If the other products are also doing that, it may be difficult to determine the exception handling sequencing. Bugsense/Splunk may be eating up the exception before the AI sees it. I would suggest disabling them temporarily to see if that is the problem.

    Somewhat unrelated. You don't need the InstrumentationKey line. The default TelemetryClient constructor already sets the iKey to the Configuration.Active.InstrumentationKey.

    Friday, September 25, 2015 6:22 PM
  • ...
    You don't need the InstrumentationKey line. The default TelemetryClient constructor already sets the iKey to the Configuration.Active.InstrumentationKey.

    This is true iff you have ApplicationInsights.config in your project and it's populated w/ the right key. 

    Is this a WP8 Silverlight or WinRT application?


    http://bc3te.ch/brandonh


    • Edited by Brandon H_ Friday, September 25, 2015 6:35 PM
    Friday, September 25, 2015 6:34 PM
  • OK, so this did prompt a few ideas that I can't fully test right now - AI is reporting data errors on their website.

    However, differences in applicationINsights.config and the whole bugsense thing do seem to have an impact, at least in seeing crash reporting in the output window. Somehow I had 2 keys in the dev build I was using, which explains why instrumentation key had to be forced in. That might have been impacting my findings.  Having corrected that...

    One branch - Has bugsense & telerik (using RadDiagnostics) - don't get errors in output window, but do get all other telemtry
    other branch, no bugsense or RadDiagnostics, I get the AI telemetry in my output window including the error report 

    I still need to confirm these show up in AI. If so, i'll mark the thread answered

    The app is still Silverlight.

    Friday, September 25, 2015 7:13 PM
  • Ok, so no change in the end result.  I still don't get to explore my crash data.

    Here's something odd though - it is there - looking through the "No crash data" messages there are bars in the summary graph, and if I do Metrics Explorer, I see line graphs for crashes, and exceptions, all with a "No data for crashes and one other metrics" message watermarked over the top.

    Saturday, September 26, 2015 3:43 AM
  • Ok, so no change in the end result.  I still don't get to explore my crash data.

    Here's something odd though - it is there - looking through the "No crash data" messages there are bars in the summary graph, and if I do Metrics Explorer, I see line graphs for crashes, and exceptions, all with a "No data for crashes and one other metrics" message watermarked over the top.


    top-of-the-page metrics & charts are aggregated. if you want a near-instant report, you have to go in to the diagnostic events.

    http://bc3te.ch/brandonh

    Monday, September 28, 2015 12:30 AM
  • My conclusion in the end is that for Windows Phone 8 Silverlight applications, this feature of Application Insights is unsupported.  Even in an empty app with an empty app insights I couldn't get exception tracking to work.

    My work around for this is that in the places where I think exceptions could happen, I am using the catch statement to create an application insights event and load that event up with the message, stack trace and some custom variables relevant to the application. Doing these seems to serve me well enough for right now - I do get these events.

    If someone can prove me wrong regarding this working on a WP8.0 Silverlight app then  by all means, mark a different post as the answer, and let me know what I was doing wrong.

    • Marked as answer by bluechrism Tuesday, December 1, 2015 4:56 PM
    Tuesday, December 1, 2015 4:56 PM
  • Hi Starkey, 

    There are several points to address:

    1. Calling TrackException with exception is tracking the exception as a UserCode exception. To track the exception as unhanded one you will need to wrap the code with ExceptionTelemetry and set ExceptionTelemetry.HandledAt to ExceptionHandledAt.Unhandled.

    Handled exceptions are not shown in the Crashes metric, only in Diagnostics --> Search. 

    2. The Application Insights SDK for Silverlight currently has a bug that prevents unhanded exception

    from being reported.

    The workaround is to do the exception tracking manually. 

    a. Replace 

    WindowsAppInitializer.InitializeAsync();

    with

    WindowsAppInitializer.InitializeAsync(WindowsCollectors.Metadata | WindowsCollectors.PageView | WindowsCollectors.Session);
    
     

    (This will prevent the default exception handling)

    b. Make sure the following line exists in App constructor, if not add it:

    UnhandledException += Application_UnhandledException;

    c. Add these usings:

    using Microsoft.ApplicationInsights;
    using Microsoft.ApplicationInsights.DataContracts;
    using Microsoft.ApplicationInsights.Extensibility;
    using Microsoft.ApplicationInsights.Channel; 
    

    d. Add the following code to Application_UnhandledException:

    if (TelemetryConfiguration.Active.TelemetryChannel isPersistenceChannel)
    {
      TelemetryClient client = newTelemetryClient();
      ExceptionTelemetry ex = newExceptionTelemetry(e.ExceptionObject);
      ex.HandledAt = ExceptionHandledAt.Unhandled;
      client.TrackException(ex);
      client.Flush();
    }

    Notes: with this workaround the crashes will be flushed to disk and will only get sent once the app is re-openned. In addition, crashes that will thrown on App startup (~2 seconds from app startup) will not be tracked. 

    3. InitializeAsync returns a task, if you intend to send events at app startup, you should either await on it or use ContinueWith.  

    • Marked as answer by bluechrism Wednesday, December 2, 2015 2:27 PM
    Wednesday, December 2, 2015 6:33 AM
    Moderator
  • Thanks for that detailed reply
    Wednesday, December 2, 2015 2:27 PM
  • Update: Latest version (v1.1.1) of Microsoft.ApplicationInsights.WindowsApps  

    fixes the bug with unhanded exception described in point #2 in my previous reply, so the workaround is no longer required. 

    Sunday, February 7, 2016 6:39 AM
    Moderator