From bdc63bd91cea2bbcc5bf4e6c9dc5f6931c3bf00a Mon Sep 17 00:00:00 2001 From: kdysput Date: Wed, 3 Jul 2024 14:41:48 +0200 Subject: [PATCH 1/2] Set error.type attribute --- Backtrace/Base/BacktraceBase.cs | 21 ++++++++++++++------- Backtrace/Model/BacktraceReport.cs | 15 +++++++++++++++ 2 files changed, 29 insertions(+), 7 deletions(-) diff --git a/Backtrace/Base/BacktraceBase.cs b/Backtrace/Base/BacktraceBase.cs index d2eb665..877aa4b 100644 --- a/Backtrace/Base/BacktraceBase.cs +++ b/Backtrace/Base/BacktraceBase.cs @@ -319,8 +319,7 @@ public virtual void HandleApplicationException() /// public virtual void HandleApplicationThreadException(object sender, System.Threading.ThreadExceptionEventArgs e) { - var exception = e.Exception as Exception; - Send(new BacktraceReport(exception)); + ReportUnhandledException(e.Exception); OnUnhandledApplicationException?.Invoke(e.Exception); } @@ -346,18 +345,26 @@ private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionE private void ReportUnhandledException(Exception exception) { + if (UnpackAggregateExcetpion && exception is AggregateException) + { + exception = exception.InnerException; + } // Always prefer to use Database rather than freezing the app because of the http request. // On environment where the database cannot be enabled for any reason, we still want to report // data and in this situation we prefer to take this tradeoff. var report = new BacktraceReport(exception); + report.SetReportErrorType("Unhandled Exception"); if (Database != null) { - Database.Add(report, Attributes, MiniDumpType); - } - else - { - Send(report); + var result = Database.Add(report, Attributes, MiniDumpType); + // try to send anyway if the database refuses to accept a report for any reason. + if (result != null) + { + return; + } } + Send(report); + } #endif } diff --git a/Backtrace/Model/BacktraceReport.cs b/Backtrace/Model/BacktraceReport.cs index 35c00cf..124c4f0 100644 --- a/Backtrace/Model/BacktraceReport.cs +++ b/Backtrace/Model/BacktraceReport.cs @@ -93,6 +93,8 @@ public class BacktraceReport internal readonly bool _reflectionMethodName; + private const string ERROR_TYPE_VALUE = "error.type"; + /// /// Create new instance of Backtrace report to sending a report with custom client message /// @@ -108,6 +110,10 @@ public BacktraceReport( : this(null as Exception, attributes, attachmentPaths, reflectionMethodName) { Message = message; + if (!Attributes.ContainsKey(ERROR_TYPE_VALUE)) + { + SetReportErrorType("Message"); + } } /// @@ -131,6 +137,10 @@ public BacktraceReport( _reflectionMethodName = reflectionMethodName; Message = ExceptionTypeReport ? exception.Message : string.Empty; SetCallingAssemblyInformation(); + if (ExceptionTypeReport && !Attributes.ContainsKey(ERROR_TYPE_VALUE)) + { + SetReportErrorType("Exception"); + } } /// @@ -193,5 +203,10 @@ internal BacktraceReport CreateInnerReport() copy.Classifier = copy.Exception.GetType().Name; return copy; } + + internal void SetReportErrorType(string errorType) + { + Attributes[ERROR_TYPE_VALUE] = errorType; + } } } From 22f5f76971016333bdf28a59d48ce76746acdeb5 Mon Sep 17 00:00:00 2001 From: kdysput Date: Wed, 3 Jul 2024 17:00:53 +0200 Subject: [PATCH 2/2] Rename attribute name --- Backtrace/Model/BacktraceReport.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Backtrace/Model/BacktraceReport.cs b/Backtrace/Model/BacktraceReport.cs index 124c4f0..f40b2c1 100644 --- a/Backtrace/Model/BacktraceReport.cs +++ b/Backtrace/Model/BacktraceReport.cs @@ -93,7 +93,7 @@ public class BacktraceReport internal readonly bool _reflectionMethodName; - private const string ERROR_TYPE_VALUE = "error.type"; + private const string ERROR_TYPE_ATTRIBUTE = "error.type"; /// /// Create new instance of Backtrace report to sending a report with custom client message @@ -110,7 +110,7 @@ public BacktraceReport( : this(null as Exception, attributes, attachmentPaths, reflectionMethodName) { Message = message; - if (!Attributes.ContainsKey(ERROR_TYPE_VALUE)) + if (!Attributes.ContainsKey(ERROR_TYPE_ATTRIBUTE)) { SetReportErrorType("Message"); } @@ -137,7 +137,7 @@ public BacktraceReport( _reflectionMethodName = reflectionMethodName; Message = ExceptionTypeReport ? exception.Message : string.Empty; SetCallingAssemblyInformation(); - if (ExceptionTypeReport && !Attributes.ContainsKey(ERROR_TYPE_VALUE)) + if (ExceptionTypeReport && !Attributes.ContainsKey(ERROR_TYPE_ATTRIBUTE)) { SetReportErrorType("Exception"); } @@ -206,7 +206,7 @@ internal BacktraceReport CreateInnerReport() internal void SetReportErrorType(string errorType) { - Attributes[ERROR_TYPE_VALUE] = errorType; + Attributes[ERROR_TYPE_ATTRIBUTE] = errorType; } } }