Retrace: Ideas Portal

Retrace combines several tools every development team needs, but we are always open to fresh new ideas.  Please submit your feature request/idea for Retrace below.

Add extension point to allow customising exception stack traces

I've been looking at ways we can improve our logging/error reporting and one of the issues we're having now, is that some of our exception stack traces are effectively useless. With async methods, LINQ queries and the like, it's quite common to see a stack trace that tells us next to nothing about where the error occurred. Take the following as an example (this is a real exception from our Retrace logs):

ERROR Object reference not set to an instance of an object.
System.NullReferenceException: Object reference not set to an instance of an object.
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification
at d__1.MoveNext
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw
at d__1.MoveNext
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification
at d__0.MoveNext
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification
at d__0.MoveNext

Retrace will catch this error and give us more context (the web request that was invoked, for example), and if we're lucky, it will have captured a trace which can give us more detail again. But if we can improve that stack trace it would be a big help.

Apparently, in .Net core 2.1 this is improved by default (https://www.ageofascent.com/2018/01/26/stack-trace-for-exceptions-in-dotnet-core-2.1/), but there are also NuGet packages around that can potentially help if we're still on the regular framework. https://github.com/benaadams/Ben.Demystifier seems to be one option, though I've yet to try it.

What I think would be great for Retrace, is if the logging/error handling library could provide an extension point so that we could intercept and potentially modify the exception before it gets sent. This way we could add whatever customisation we wanted (such as the NuGet package I linked to improve the stack trace). This could work both for unhandled exceptions as well as Logger.Error calls.

  • Avatar32.5fb70cce7410889e661286fd7f1897de Guest
  • Jul 25 2018
  • Attach files
  • Avatar40.8f183f721a2c86cd98fddbbe6dc46ec9
    Guest commented
    29 Aug 19:37

    Can you site an example on how do you want it to behave? Like a hook? How do you expect it to be transformed? I wanted to know about on it more as this give us the user the freedom to give a more verbose exception before sending it to retrace? like tagging exceptions.