Skip to content

Commit 9305311

Browse files
authored
Set error.type attribute (#42)
* Set error.type attribute * Rename attribute name
1 parent 34e44af commit 9305311

2 files changed

Lines changed: 29 additions & 7 deletions

File tree

Backtrace/Base/BacktraceBase.cs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -319,8 +319,7 @@ public virtual void HandleApplicationException()
319319
/// </summary>
320320
public virtual void HandleApplicationThreadException(object sender, System.Threading.ThreadExceptionEventArgs e)
321321
{
322-
var exception = e.Exception as Exception;
323-
Send(new BacktraceReport(exception));
322+
ReportUnhandledException(e.Exception);
324323
OnUnhandledApplicationException?.Invoke(e.Exception);
325324
}
326325

@@ -346,18 +345,26 @@ private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionE
346345

347346
private void ReportUnhandledException(Exception exception)
348347
{
348+
if (UnpackAggregateExcetpion && exception is AggregateException)
349+
{
350+
exception = exception.InnerException;
351+
}
349352
// Always prefer to use Database rather than freezing the app because of the http request.
350353
// On environment where the database cannot be enabled for any reason, we still want to report
351354
// data and in this situation we prefer to take this tradeoff.
352355
var report = new BacktraceReport(exception);
356+
report.SetReportErrorType("Unhandled Exception");
353357
if (Database != null)
354358
{
355-
Database.Add(report, Attributes, MiniDumpType);
356-
}
357-
else
358-
{
359-
Send(report);
359+
var result = Database.Add(report, Attributes, MiniDumpType);
360+
// try to send anyway if the database refuses to accept a report for any reason.
361+
if (result != null)
362+
{
363+
return;
364+
}
360365
}
366+
Send(report);
367+
361368
}
362369
#endif
363370
}

Backtrace/Model/BacktraceReport.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ public class BacktraceReport
9393

9494
internal readonly bool _reflectionMethodName;
9595

96+
private const string ERROR_TYPE_ATTRIBUTE = "error.type";
97+
9698
/// <summary>
9799
/// Create new instance of Backtrace report to sending a report with custom client message
98100
/// </summary>
@@ -108,6 +110,10 @@ public BacktraceReport(
108110
: this(null as Exception, attributes, attachmentPaths, reflectionMethodName)
109111
{
110112
Message = message;
113+
if (!Attributes.ContainsKey(ERROR_TYPE_ATTRIBUTE))
114+
{
115+
SetReportErrorType("Message");
116+
}
111117
}
112118

113119
/// <summary>
@@ -131,6 +137,10 @@ public BacktraceReport(
131137
_reflectionMethodName = reflectionMethodName;
132138
Message = ExceptionTypeReport ? exception.Message : string.Empty;
133139
SetCallingAssemblyInformation();
140+
if (ExceptionTypeReport && !Attributes.ContainsKey(ERROR_TYPE_ATTRIBUTE))
141+
{
142+
SetReportErrorType("Exception");
143+
}
134144
}
135145

136146
/// <summary>
@@ -193,5 +203,10 @@ internal BacktraceReport CreateInnerReport()
193203
copy.Classifier = copy.Exception.GetType().Name;
194204
return copy;
195205
}
206+
207+
internal void SetReportErrorType(string errorType)
208+
{
209+
Attributes[ERROR_TYPE_ATTRIBUTE] = errorType;
210+
}
196211
}
197212
}

0 commit comments

Comments
 (0)