Skip to content
Draft
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
1 change: 1 addition & 0 deletions .github/workflows/test-run-android.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ jobs:
HOMEBREW_NO_INSTALL_CLEANUP: 1
SENTRY_DSN: ${{ secrets.SENTRY_TEST_DSN }}
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
SENTRY_TEST_UNITY_VERSION: ${{ inputs.unity-version }}

steps:
- name: Checkout
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## Unreleased

### Behavioral Changes

- The device name (`device.name`), which often contains the user's name, is now only sent when `SendDefaultPii` is enabled. This also applies to native crashes on desktop and consoles. ([#2932](https://github.com/getsentry/sentry-unity/pull/2932))

## 4.12.0

### Behavioral Changes
Expand Down
5 changes: 4 additions & 1 deletion src/Sentry.Unity/Integrations/UnityScopeIntegration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,10 @@ private void PopulateDevice(Device device)
device.CpuDescription = MainThreadData.CpuDescription;
device.Timezone = TimeZoneInfo.Local;
device.SupportsVibration = MainThreadData.SupportsVibration;
device.Name = MainThreadData.DeviceName;
// The device name is often set by the user and can contain their name, e.g. "Jane's iPhone".
device.Name = _options.SendDefaultPii
? MainThreadData.DeviceName
: null;

// The app can be run in an iOS or Android emulator. We can't safely set a value for simulator.
device.Simulator = _application.IsEditor ? true : null;
Expand Down
4 changes: 4 additions & 0 deletions test/IntegrationTest/Integration.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,10 @@ Describe "Unity $($env:SENTRY_TEST_PLATFORM) Integration Tests" {
Set-ItResult -Skipped -Because "line numbers come from the IL2CPP mappings, which a Mono player does not produce"
return
}
if ($script:Platform -eq "Android" -and $script:TestSetup.UnityVersion -like "2021.3*") {
Set-ItResult -Skipped -Because "on the Android 2021.3 x86_64 emulator, IL2CPP intermittently reports no stack frames for the thrown exception, so the event carries only the throwing frame without a native address"
return
}

$frame = $runEvent.exception.values[0].stacktrace.frames |
Where-Object { $_.module -eq "IntegrationTester" -and $_.function -eq "ThrowException" } |
Expand Down
29 changes: 29 additions & 0 deletions test/Sentry.Unity.Tests/ContextWriterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,35 @@ public void Arguments()
Assert.AreEqual(sysInfo.CopyTextureSupport?.Value, context.UnityCopyTextureSupport);
Assert.AreEqual(sysInfo.RenderingThreadingMode?.Value, context.UnityRenderingThreadingMode);
}

[Test]
public void DeviceName_WithoutSendDefaultPii_NotWritten()
{
// arrange
var context = new MockContextWriter();
var options = new SentryUnityOptions(application: _testApplication, behaviour: _sentryMonoBehaviour)
{
Dsn = "http://publickey@localhost/12345",
Enabled = true,
SendDefaultPii = false,
Debug = true,
DiagnosticLogger = new TestLogger(),
NativeContextWriter = context,
CreateHttpMessageHandler = () => new TestHttpClientHandler(),
AutoSessionTracking = false,
CacheDirectoryPath = null,
};

// act
MainThreadData.SentrySystemInfo = new TestSentrySystemInfo { DeviceName = "Jane's PC" };
MainThreadData.CollectData();

SentrySdk.Init(options);
Assert.IsTrue(context.SyncFinished.WaitOne(TimeSpan.FromSeconds(10)));

// assert
Assert.IsNull(context.DeviceName);
}
}

internal sealed class MockContextWriter : ContextWriter
Expand Down
28 changes: 28 additions & 0 deletions test/Sentry.Unity.Tests/UnityEventScopeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -267,10 +267,37 @@ public void DeviceUniqueIdentifierWithSendDefaultPii_IsNotNull()
Assert.IsNotNull(scope.Contexts.Device.DeviceUniqueIdentifier);
}

[Test]
[TestCase(true)]
[TestCase(false)]
public void DeviceName_SetOnlyWithSendDefaultPii(bool sendDefaultPii)
{
// arrange
MainThreadData.SentrySystemInfo = new TestSentrySystemInfo { DeviceName = "Jane's iPhone" };
MainThreadData.CollectData();

var sentryOptions = new SentryUnityOptions(application: _testApplication) { SendDefaultPii = sendDefaultPii };
var sut = new UnityScopeUpdater(sentryOptions, _testApplication);
var scope = new Scope(sentryOptions);

// act
sut.ConfigureScope(scope);

// assert
Assert.AreEqual(sendDefaultPii ? "Jane's iPhone" : null, scope.Contexts.Device.Name);
}

[Test]
public void AppProtocol_Assigned()
{
// arrange
MainThreadData.SentrySystemInfo = new TestSentrySystemInfo
{
StartTime = new Lazy<DateTimeOffset>(() => DateTimeOffset.UtcNow),
IsDebugBuild = new Lazy<bool>(() => true)
};
MainThreadData.CollectData();

_testApplication = new TestApplication(productName: "TestGame");
var sut = new UnityScopeUpdater(_sentryOptions, _testApplication);
var scope = new Scope(_sentryOptions);
Expand Down Expand Up @@ -550,6 +577,7 @@ public void DeviceProtocol_Assigned()
MainThreadData.SentrySystemInfo = systemInfo;
MainThreadData.CollectData();

_sentryOptions.SendDefaultPii = true; // for Device.Name
var sut = new UnityScopeUpdater(_sentryOptions, _testApplication);
var scope = new Scope(_sentryOptions);

Expand Down
Loading