Skip to content

Commit

Permalink
Set error.type attribute (#42)
Browse files Browse the repository at this point in the history
* Set error.type attribute

* Rename attribute name
  • Loading branch information
konraddysput authored Jul 3, 2024
1 parent 34e44af commit 9305311
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 7 deletions.
21 changes: 14 additions & 7 deletions Backtrace/Base/BacktraceBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -319,8 +319,7 @@ public virtual void HandleApplicationException()
/// </summary>
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);
}

Expand All @@ -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
}
Expand Down
15 changes: 15 additions & 0 deletions Backtrace/Model/BacktraceReport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ public class BacktraceReport

internal readonly bool _reflectionMethodName;

private const string ERROR_TYPE_ATTRIBUTE = "error.type";

/// <summary>
/// Create new instance of Backtrace report to sending a report with custom client message
/// </summary>
Expand All @@ -108,6 +110,10 @@ public BacktraceReport(
: this(null as Exception, attributes, attachmentPaths, reflectionMethodName)
{
Message = message;
if (!Attributes.ContainsKey(ERROR_TYPE_ATTRIBUTE))
{
SetReportErrorType("Message");
}
}

/// <summary>
Expand All @@ -131,6 +137,10 @@ public BacktraceReport(
_reflectionMethodName = reflectionMethodName;
Message = ExceptionTypeReport ? exception.Message : string.Empty;
SetCallingAssemblyInformation();
if (ExceptionTypeReport && !Attributes.ContainsKey(ERROR_TYPE_ATTRIBUTE))
{
SetReportErrorType("Exception");
}
}

/// <summary>
Expand Down Expand Up @@ -193,5 +203,10 @@ internal BacktraceReport CreateInnerReport()
copy.Classifier = copy.Exception.GetType().Name;
return copy;
}

internal void SetReportErrorType(string errorType)
{
Attributes[ERROR_TYPE_ATTRIBUTE] = errorType;
}
}
}

0 comments on commit 9305311

Please sign in to comment.