RaygunClient.Send() call not showing up for an unhandled exception

fschwiet

Posted on
Sep 19 2018

Our code has a call to RaygunClient.Send() which is not getting through when called from a AppDomain.CurrentDomain.UnhandledException handler. The exception does end up in Raygun with the "UnhandledException" tag, but not with that tags and user custom data we are sending. It looks like Raygun is sending the "UnhandledException" tagged result on its own while not sending the information we send with RaygunClient.Send(). If I make the same call to RaygunClient.Send() outside of the AppDomain.CurrentDomain.UnhandledException handler then it works, the exception goes through with the tag and user custom data.

I would like for our call to RaygunClient.Send() during the AppDomain.CurrentDomain.UnhandledException handler to go through. At the same time the "UnhandledException" tagged one would be redundant, so I'd like it not to show up. Any ideas how we can achieve this?

We are calling Raygun with the .NET library Mindscape.Raygun4Net version 5.5.4. I've seen the issue on Mac, iOS, Android and Windows. I focused on Android when debugging through and experimenting. I swear tags were getting through as expected before, but maybe I had just tested it by calling RaygunClient.Send directly rather than within the unhandled exception handler.


Mitchell

Raygun

Posted on
Sep 19 2018

Hi fschwiet,

Thank you for getting in touch with us. It definitely sounds like there is a bug with the way we are attaching tags and custom data to reports during certain times. I will make a ticket for the engineering team to investigate into this problem. Can you please provide any example code snippets that you are using to test this scenario.

Thank you, Mitchell.


fschwiet

Posted on
Sep 21 2018

No I can't send the working code and don't really have time to create an issue.

I think I understand the issue a bit more. The exceptions are being sent from our unhandled exception handler, but the Raygun client has its own unhandled exception handler sending the same exception. I think the Raygun client or server are detecting that both have the same exception and only keeping one report. The report from the raygun client with the "UnhandledException" tag is kept, our report and the tags/custom data is dropped.

I haven't had time to verify that reports are de-duplicated like that. If thats the case I would say its not really a Raygun bug but a our error due to not understanding how Raygun works enough. There's probably room for improvement in the documentation (in what cases does the raygun client automatically send a report? are reports de-duplicated?).


Jason Fauchelle

Raygun

Posted on
Oct 09 2018

Hi fschwiet,

I can help you with this. Everything you mentioned in your follow up comment is correct. The RaygunClient adds a flag to the Data collection of any Exception instance that it sends to Raygun. If the RaygunClient sees flagged Exception instances again, it avoids double sending them.

The RaygunClient automatically sends unhandled exceptions if you call the Attach or AttachCrashReporting methods. Raygun4Net will still works fine if you don't call either of those methods, and just want to have full control of sending exceptions reports, including unhandled exceptions. So the easiest way to get the behaviour you described in your first comment would be to not call Attach or AttachCrashReporting, and instead create the RaygunClient with just the static Initialize method, or constructor that takes an api key.

A couple of things to note about not using Attach or AttachCrashReporting:

  • The reports will no longer have the "UnhandledException" tag for exceptions sent via an unhandled exception callback. This tag is used by the Raygun service for statistics related to exceptions that cause an app crash vs exceptions that don't crash the app. (generally, an exception that hits an unhandled exception handler will crash the application). You could easily add this tag in to your own unhandled exception callback though.
  • For some platforms, there are multiple unhandled exception callbacks managed by the Attach/AttachCrashReporting method. So if you don't call either of those, you may want to attach the additional callbacks manually too. You can check the Raygun4Net source code to find out what to attach to. Here is the Android code for example: https://github.com/MindscapeHQ/raygun4net/blob/master/Mindscape.Raygun4Net.Xamarin.Android/RaygunClient.cs#L386

If you'd prefer to leave Raygun4Net to report unhandled exceptions for you, then you'd want to avoid calling the Send method inside your own unhandled exceptions callback. Instead, you could use the RaygunClient SendingMessage or CustomGroupingKey events. These events get called when Raygun4Net is about to serialize and send the exception report to Raygun. The callback of these events includes the RaygunMessage object, to which you can append tags and custom data to. The CustomGroupingKey also includes the Exception object, so use that one if you need the Exception to work out what tags/custom data you want to add.

Indeed our documentation could be improved for this use case.

Please let us know if you have further questions about any of this and we'll help you out.

-Jason Fauchelle


fschwiet

Posted on
Oct 11 2018

Its sorted out now, thank you for the help.


Reply