Skip to content

Commit 6de4f13

Browse files
authored
feat: Set platform specific defaults for EnvironmentUser (#2402)
* Platform specific defaults for 'EnvironmentUser' * Updated CHANGELOG.md
1 parent 1aed342 commit 6de4f13

File tree

5 files changed

+48
-6
lines changed

5 files changed

+48
-6
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
### Features
66

77
- The SDK now also reports the currently allocated memory when reporting an event or transaction. ([#2398](https://github.com/getsentry/sentry-unity/pull/2398))
8+
- The SDK defaults `EnvironmentUser` to sensible values based on the current platform. This is still guarded by the `SendDefaultPII` flag. ([#2402](https://github.com/getsentry/sentry-unity/pull/2402))
89

910
### Fixes
1011

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ internal static void Display(ScriptableSentryUnityOptions options)
1818

1919
options.IsEnvironmentUser = EditorGUILayout.Toggle(
2020
new GUIContent("Auto Set UserName", "Whether to report the 'Environment.UserName' as " +
21-
"the User affected in the event. Should be disabled for " +
22-
"Android and iOS."),
21+
"the User affected in the event. Defaults to enabled on desktop " +
22+
"platforms and disabled on mobile and console platforms."),
2323
options.IsEnvironmentUser);
2424

2525
EditorGUI.indentLevel--;

src/Sentry.Unity/SentryUnityOptions.cs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,24 @@ internal SentryUnityOptions(IApplication? application = null,
374374
// Ben.Demystifer not compatible with IL2CPP. We could allow Enhanced in the future for Mono.
375375
// See https://github.com/getsentry/sentry-unity/issues/675
376376
base.StackTraceMode = StackTraceMode.Original;
377-
IsEnvironmentUser = false;
377+
378+
IsEnvironmentUser = application.Platform switch
379+
{
380+
// Desktop: true (capture logged-in user)
381+
RuntimePlatform.WindowsPlayer or RuntimePlatform.WindowsServer
382+
or RuntimePlatform.OSXPlayer or RuntimePlatform.OSXServer
383+
or RuntimePlatform.LinuxPlayer or RuntimePlatform.LinuxServer => true,
384+
385+
// Mobile: false
386+
RuntimePlatform.Android or RuntimePlatform.IPhonePlayer => false,
387+
388+
// Consoles: false
389+
RuntimePlatform.GameCoreXboxSeries or RuntimePlatform.GameCoreXboxOne
390+
or RuntimePlatform.PS4 or RuntimePlatform.PS5 or RuntimePlatform.Switch => false,
391+
392+
// Unknown platforms
393+
_ => false
394+
};
378395

379396
if (application.ProductName is string productName
380397
&& !string.IsNullOrWhiteSpace(productName)

test/Sentry.Unity.Tests/SentryUnityOptionsTests.cs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,5 +87,29 @@ public void Ctor_Release_IgnoresDotOnlyProductNames()
8787
}
8888

8989
[Test]
90-
public void Ctor_IsEnvironmentUser_IsFalse() => Assert.AreEqual(false, _fixture.GetSut().IsEnvironmentUser);
90+
[TestCase(RuntimePlatform.WindowsPlayer, true)]
91+
[TestCase(RuntimePlatform.WindowsServer, true)]
92+
[TestCase(RuntimePlatform.OSXPlayer, true)]
93+
[TestCase(RuntimePlatform.OSXServer, true)]
94+
[TestCase(RuntimePlatform.LinuxPlayer, true)]
95+
[TestCase(RuntimePlatform.LinuxServer, true)]
96+
[TestCase(RuntimePlatform.Android, false)]
97+
[TestCase(RuntimePlatform.IPhonePlayer, false)]
98+
[TestCase(RuntimePlatform.GameCoreXboxSeries, false)]
99+
[TestCase(RuntimePlatform.GameCoreXboxOne, false)]
100+
[TestCase(RuntimePlatform.PS4, false)]
101+
[TestCase(RuntimePlatform.PS5, false)]
102+
[TestCase(RuntimePlatform.Switch, false)]
103+
[TestCase(RuntimePlatform.WindowsEditor, false)]
104+
[TestCase(RuntimePlatform.OSXEditor, false)]
105+
[TestCase(RuntimePlatform.LinuxEditor, false)]
106+
[TestCase(RuntimePlatform.WebGLPlayer, false)]
107+
public void Ctor_IsEnvironmentUser_DefaultsBasedOnPlatform(RuntimePlatform platform, bool expectedValue)
108+
{
109+
_fixture.Application.Platform = platform;
110+
111+
var sut = _fixture.GetSut();
112+
113+
Assert.AreEqual(expectedValue, sut.IsEnvironmentUser);
114+
}
91115
}

test/Sentry.Unity.Tests/UnityEventScopeTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ public void AppProtocol_Assigned()
284284
public void AppMemory_SetByEventProcessor()
285285
{
286286
// arrange
287-
var unityEventProcessor = new UnityEventProcessor(_sentryOptions);
287+
var unityEventProcessor = new UnityEventProcessor(_sentryOptions, new TestUnityInfo());
288288
var sentryEvent = new SentryEvent();
289289

290290
// act
@@ -298,7 +298,7 @@ public void AppMemory_SetByEventProcessor()
298298
public void AppMemory_SetByEventProcessorForTransactions()
299299
{
300300
// arrange
301-
var unityEventProcessor = new UnityEventProcessor(_sentryOptions);
301+
var unityEventProcessor = new UnityEventProcessor(_sentryOptions, new TestUnityInfo());
302302
var transaction = new SentryTransaction("test-transaction", "test-operation");
303303

304304
// act

0 commit comments

Comments
 (0)