ASP.NET MVC / Prevent error grouping

Gérard Lambert

Posted on
Feb 09 2018

Hello,

In one of my controller, I have the following line :

throw new Exception(message);

The message can be different depending on the cases. For example, an exception with the message "Error 1" could be raised and then, another one could be raised with the message "Error 2". On the crash reporting interfce, these errors are grouped in one like you can see below : enter image description here

I would like to have two lines instead of one : enter image description here

How can I achieve this ? Should I add something to my Exception object ?

Thanks for your answer.


John-Daniel Trask

Raygun

Posted on
Feb 09 2018

Hi Gérard,

The reason for this will be because all those errors will have the same stack trace + same error class type ('Exception'). In this case, what I'd recommend is setting a custom grouping key for errors from this part (likely just a hash of the message in this case) as you won't want to change your entire account to use messages as it'll make the exceptions from other parts of your app make more groups than you'd like.

https://github.com/MindscapeHQ/raygun4net#custom-grouping-keys

I'd recommend wiring up to this event, but perhaps only using a custom grouping key when you see that the error is coming from this location (or perhaps has a class name of 'Exception') so that it doesn't impact the other rules Raygun would use to group your errors.

I hope that helps!

Kind regards,

John-Daniel Trask


Gérard Lambert

Posted on
Feb 09 2018

Hi John-Daniel,

Thank you for your detailed answer.

I was able to do exactly what I want with custom grouping keys, see my code below :

// On the RaygunClient instance, attach an event handler to the CustomGroupingKey event.
RaygunClient.CustomGroupingKey += RaygunClient_CustomGroupingKey;

Then

private void RaygunClient_CustomGroupingKey(object sender, RaygunCustomGroupingKeyEventArgs e)
{
    if (e.Exception is KickAssException)
    {
        var kickAssException = (KickAssException)e.Exception;
        e.CustomGroupingKey = kickAssException.GetRaygunCustomGroupingKey();
    }
}

It works perfectly, thank you again !

Best regards,

Gérard


Reply