Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
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
22 changes: 22 additions & 0 deletions Runtime/Model/JsonData/BacktraceAttributes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,28 @@ internal void SetExceptionAttributes(BacktraceReport report)
Attributes["error.message"] = report.ExceptionTypeReport
? report.Exception.Message
: report.Message;

// detect exception type
var errorType = "error.type";
if (!report.ExceptionTypeReport)
{
Attributes[errorType] = "Message";
return;
}
if (report.Exception is BacktraceUnhandledException)
{
if ((report.Exception as BacktraceUnhandledException).Classifier == "ANRException")
{
Attributes[errorType] = "Hang";
}
else
{
Attributes[errorType] = "Unhandled exception";
}
} else
{
Attributes[errorType] = "Exception";
}
}

internal void SetSceneInformation(bool onlyBuiltInAttributes = false)
Expand Down
36 changes: 36 additions & 0 deletions Tests/Runtime/BacktraceAttributeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,5 +121,41 @@ public void TestCorrectDictionaryGeneration_CreateCorrectAttributesDictionary_Wi
Assert.IsTrue(testObject.Attributes[clientAttributeKey] == clientAttributeValue);
Assert.IsTrue(testObject.Attributes[reportAttributeKey] == reportAttributeValue);
}

[Test]
public void TestExceptionTypeAttribute_ShouldSetExceptionTypeMessage_ExceptionTypeAttributeIsCorrect()
{
var report = new BacktraceReport("foo");
var testAttributes = new BacktraceAttributes(report, null);

Assert.AreEqual("Message", testAttributes.Attributes["error.type"]);
}

[Test]
public void TestExceptionTypeAttribute_ShouldSetExceptionTypeException_ExceptionTypeAttributeIsCorrect()
{
var report = new BacktraceReport(new Exception("foo"));
var testAttributes = new BacktraceAttributes(report, null);

Assert.AreEqual("Exception", testAttributes.Attributes["error.type"]);
}

[Test]
public void TestExceptionTypeAttribute_ShouldSetExceptionTypeUnhandledException_ExceptionTypeAttributeIsCorrect()
{
var report = new BacktraceReport(new BacktraceUnhandledException("foo", string.Empty));
var testAttributes = new BacktraceAttributes(report, null);

Assert.AreEqual("Unhandled exception", testAttributes.Attributes["error.type"]);
}

[Test]
public void TestExceptionTypeAttribute_ShouldSetExceptionTypeHang_ExceptionTypeAttributeIsCorrect()
{
var report = new BacktraceReport(new BacktraceUnhandledException("ANRException: Blocked thread detected", string.Empty));
var testAttributes = new BacktraceAttributes(report, null);

Assert.AreEqual("Hang", testAttributes.Attributes["error.type"]);
}
}
}