Skip to content

Commit 66baca1

Browse files
authored
chore: Changelog and tests for Debug.LogError flag (#2010)
1 parent f45f5ea commit 66baca1

File tree

3 files changed

+27
-11
lines changed

3 files changed

+27
-11
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
### Features
66

7+
- Added option to enable/disable automatic capture of `Debug.LogError` as event. ([#2009](https://github.com/getsentry/sentry-unity/pull/2009))
78
- The `Ignore CLI Errors` checkbox in the Debug Symbols tab now applies to all supported platforms. ([#2008](https://github.com/getsentry/sentry-unity/pull/2008))
89
- The SDK now provides stacktraces when capturing events created via `Debug.LogError`. Note, that the SDK is currently not able to provide line numbers for these events. ([#1965](https://github.com/getsentry/sentry-unity/pull/1965))
910

src/Sentry.Unity.Editor/ConfigurationWindow/EnrichmentTab.cs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,26 +63,31 @@ internal static void Display(ScriptableSentryUnityOptions options)
6363
EditorGUI.DrawRect(EditorGUILayout.GetControlRect(false, 1), Color.gray);
6464
EditorGUILayout.Space();
6565

66+
GUILayout.Label("Automatically capture and send events for:", EditorStyles.boldLabel);
67+
EditorGUILayout.Space();
68+
6669
options.CaptureLogErrorEvents = EditorGUILayout.Toggle(
67-
new GUIContent("Capture LogError as Event", "Whether the SDK automatically captures events for 'Debug.LogError'."),
70+
new GUIContent("Debug.LogError", "Whether the SDK automatically captures events for 'Debug.LogError'."),
6871
options.CaptureLogErrorEvents);
6972

70-
GUILayout.Label("Breadcrumbs automatically added for LogType:", EditorStyles.boldLabel);
73+
EditorGUILayout.Space();
74+
GUILayout.Label("Automatically create breadcrumbs for:", EditorStyles.boldLabel);
75+
EditorGUILayout.Space();
7176

7277
options.BreadcrumbsForLogs = EditorGUILayout.Toggle(
73-
new GUIContent("Log", "Whether the SDK automatically adds breadcrumbs 'Debug.Log'."),
78+
new GUIContent("Debug.Log", "Whether the SDK automatically adds breadcrumbs 'Debug.Log'."),
7479
options.BreadcrumbsForLogs);
7580
options.BreadcrumbsForWarnings = EditorGUILayout.Toggle(
76-
new GUIContent("Warning", "Whether the SDK automatically adds breadcrumbs for 'Debug.LogWarning'."),
81+
new GUIContent("Debug.Warning", "Whether the SDK automatically adds breadcrumbs for 'Debug.LogWarning'."),
7782
options.BreadcrumbsForWarnings);
7883
options.BreadcrumbsForAsserts = EditorGUILayout.Toggle(
79-
new GUIContent("Assert", "Whether the SDK automatically adds breadcrumbs for 'Debug.Assert'."),
84+
new GUIContent("Debug.Assert", "Whether the SDK automatically adds breadcrumbs for 'Debug.Assert'."),
8085
options.BreadcrumbsForAsserts);
8186
options.BreadcrumbsForErrors = EditorGUILayout.Toggle(
82-
new GUIContent("Error", "Whether the SDK automatically adds breadcrumbs for 'Debug.LogError'."),
87+
new GUIContent("Debug.Error", "Whether the SDK automatically adds breadcrumbs for 'Debug.LogError'."),
8388
options.BreadcrumbsForErrors);
8489
options.BreadcrumbsForExceptions = EditorGUILayout.Toggle(
85-
new GUIContent("Exception", "Whether the SDK automatically adds breadcrumbs for exceptions and 'Debug.LogException'."),
90+
new GUIContent("Debug.Exception", "Whether the SDK automatically adds breadcrumbs for exceptions and 'Debug.LogException'."),
8691
options.BreadcrumbsForExceptions);
8792

8893
EditorGUILayout.Space();

test/Sentry.Unity.Tests/UnityApplicationLoggingIntegrationTests.cs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,26 @@ public void OnLogMessageReceived_LogContainsSentryTag_NotCaptured()
4646
}
4747

4848
[Test]
49-
public void OnLogMessageReceived_LogTypeError_CaptureEvent()
49+
[TestCase(true)]
50+
[TestCase(false)]
51+
public void OnLogMessageReceived_LogTypeError_CaptureEvent(bool captureLogErrorEvents)
5052
{
53+
_fixture.SentryOptions.CaptureLogErrorEvents = captureLogErrorEvents;
5154
var sut = _fixture.GetSut();
5255
var message = TestContext.CurrentContext.Test.Name;
5356

5457
sut.OnLogMessageReceived(message, string.Empty, LogType.Error);
5558

56-
Assert.AreEqual(1, _fixture.Hub.CapturedEvents.Count);
57-
Assert.NotNull(_fixture.Hub.CapturedEvents[0].Message);
58-
Assert.AreEqual(message, _fixture.Hub.CapturedEvents[0].Message!.Message);
59+
if (captureLogErrorEvents)
60+
{
61+
Assert.AreEqual(1, _fixture.Hub.CapturedEvents.Count);
62+
Assert.NotNull(_fixture.Hub.CapturedEvents[0].Message);
63+
Assert.AreEqual(message, _fixture.Hub.CapturedEvents[0].Message!.Message);
64+
}
65+
else
66+
{
67+
Assert.AreEqual(0, _fixture.Hub.CapturedEvents.Count);
68+
}
5969
}
6070

6171
[Test]

0 commit comments

Comments
 (0)