Skip to content

Set error.type attribute #42

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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_VALUE = "error.type";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
private const string ERROR_TYPE_VALUE = "error.type";
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_VALUE))
{
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_VALUE))
{
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_VALUE] = errorType;
}
}
}