Skip to content

Commit 2529856

Browse files
committed
Added error.type to Unity runtime
1 parent 0fc1aa6 commit 2529856

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed

Runtime/Model/JsonData/BacktraceAttributes.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,28 @@ internal void SetExceptionAttributes(BacktraceReport report)
186186
Attributes["error.message"] = report.ExceptionTypeReport
187187
? report.Exception.Message
188188
: report.Message;
189+
190+
// detect exception type
191+
var errorType = "error.type";
192+
if (!report.ExceptionTypeReport)
193+
{
194+
Attributes[errorType] = "Message";
195+
return;
196+
}
197+
if (report.Exception is BacktraceUnhandledException)
198+
{
199+
if ((report.Exception as BacktraceUnhandledException).Classifier == "ANRException")
200+
{
201+
Attributes[errorType] = "Hang";
202+
}
203+
else
204+
{
205+
Attributes[errorType] = "Unhandled exception";
206+
}
207+
} else
208+
{
209+
Attributes[errorType] = "Exception";
210+
}
189211
}
190212

191213
internal void SetSceneInformation(bool onlyBuiltInAttributes = false)

Tests/Runtime/BacktraceAttributeTests.cs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,5 +121,41 @@ public void TestCorrectDictionaryGeneration_CreateCorrectAttributesDictionary_Wi
121121
Assert.IsTrue(testObject.Attributes[clientAttributeKey] == clientAttributeValue);
122122
Assert.IsTrue(testObject.Attributes[reportAttributeKey] == reportAttributeValue);
123123
}
124+
125+
[Test]
126+
public void TestExceptionTypeAttribute_ShouldSetExceptionTypeMessage_ExceptionTypeAttributeIsCorrect()
127+
{
128+
var report = new BacktraceReport("foo");
129+
var testAttributes = new BacktraceAttributes(report, null);
130+
131+
Assert.AreEqual("Message", testAttributes.Attributes["error.type"]);
132+
}
133+
134+
[Test]
135+
public void TestExceptionTypeAttribute_ShouldSetExceptionTypeException_ExceptionTypeAttributeIsCorrect()
136+
{
137+
var report = new BacktraceReport(new Exception("foo"));
138+
var testAttributes = new BacktraceAttributes(report, null);
139+
140+
Assert.AreEqual("Exception", testAttributes.Attributes["error.type"]);
141+
}
142+
143+
[Test]
144+
public void TestExceptionTypeAttribute_ShouldSetExceptionTypeUnhandledException_ExceptionTypeAttributeIsCorrect()
145+
{
146+
var report = new BacktraceReport(new BacktraceUnhandledException("foo", string.Empty));
147+
var testAttributes = new BacktraceAttributes(report, null);
148+
149+
Assert.AreEqual("Unhandled exception", testAttributes.Attributes["error.type"]);
150+
}
151+
152+
[Test]
153+
public void TestExceptionTypeAttribute_ShouldSetExceptionTypeHang_ExceptionTypeAttributeIsCorrect()
154+
{
155+
var report = new BacktraceReport(new BacktraceUnhandledException("ANRException: Blocked thread detected", string.Empty));
156+
var testAttributes = new BacktraceAttributes(report, null);
157+
158+
Assert.AreEqual("Hang", testAttributes.Attributes["error.type"]);
159+
}
124160
}
125161
}

0 commit comments

Comments
 (0)