Skip to content
Merged
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
- Bump Native SDK from v0.14.0 to v0.14.2 ([#2685](https://github.com/getsentry/sentry-unity/pull/2685))
- [changelog](https://github.com/getsentry/sentry-native/blob/master/CHANGELOG.md#0142)
- [diff](https://github.com/getsentry/sentry-native/compare/0.14.0...0.14.2)
- Bump .NET SDK from v6.6.0-1-g4a85500a to v6.6.0 ([#2698](https://github.com/getsentry/sentry-unity/pull/2698))
- [changelog](https://github.com/getsentry/sentry-dotnet/blob/main/CHANGELOG.md#660)
- [diff](https://github.com/getsentry/sentry-dotnet/compare/6.6.0-1-g4a85500a...6.6.0)

## 4.3.1

Expand Down
16 changes: 9 additions & 7 deletions src/Sentry.Unity/Integrations/UnityScopeIntegration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -159,17 +159,19 @@ private void PopulateUnity(Protocol.Unity unity)

private void PopulateUser(Scope scope)
{
if (scope.User.Id is not null)
// The .NET SDK pre-sets User.Id from its own InstallationId on the root scope in global
// mode. On mobile we want the native SDK's installation id so managed events and native
// crashes share a user identity — overwrite unconditionally when DefaultUserId is set.
if (_options.DefaultUserId is not null)
{
return;
scope.User.Id = _options.DefaultUserId;
}

// Only set the native installation ID here. The .NET SDK's Enricher handles
// the fallback to InstallationId after the HasUser() check, which allows
// IsEnvironmentUser/SendDefaultPii to set the Username first.
if (_options.DefaultUserId is not null)
// Enricher only applies Environment.UserName when the scope user has no data yet — and
// the pre-set User.Id above trips that gate. Apply it here so IsEnvironmentUser is honored.
if (scope.User.Username is null && _options.SendDefaultPii && _options.IsEnvironmentUser)
{
scope.User.Id = _options.DefaultUserId;
scope.User.Username = Environment.UserName;
}
}
}
2 changes: 1 addition & 1 deletion src/sentry-dotnet
Submodule sentry-dotnet updated 69 files
+1 −1 .craft.yml
+4 −4 .github/actions/environment/action.yml
+1 −1 .github/actions/freediskspace/action.yml
+3 −1 .github/dependabot.yml
+4 −4 .github/workflows/build.yml
+1 −1 .github/workflows/changelog-preview.yml
+2 −2 .github/workflows/codeql-analysis.yml
+1 −1 .github/workflows/danger.yml
+2 −2 .github/workflows/device-tests-ios.yml
+1 −1 .github/workflows/release.yml
+7 −2 .github/workflows/update-deps.yml
+2 −2 .github/workflows/validate-pr.yml
+29 −0 CHANGELOG.md
+1 −1 Directory.Build.props
+1 −1 modules/sentry-cocoa
+1 −1 modules/sentry-native
+1 −1 src/Sentry.Bindings.Android/Sentry.Bindings.Android.csproj
+7 −1 src/Sentry.Bindings.Android/Transforms/Metadata.xml
+4 −0 src/Sentry.Bindings.Cocoa/ApiDefinitions.cs
+3 −3 src/Sentry.Extensions.Logging/SentryStructuredLogger.cs
+30 −4 src/Sentry.OpenTelemetry.Exporter/ActivityExtensions.cs
+5 −0 src/Sentry.OpenTelemetry.Exporter/SentryTracerProviderBuilderExtensions.cs
+4 −0 src/Sentry/BindableSentryOptions.cs
+24 −2 src/Sentry/Dsn.cs
+15 −5 src/Sentry/DynamicSamplingContext.cs
+14 −0 src/Sentry/Integrations/GlobalRootScopeIntegration.cs
+9 −5 src/Sentry/Internal/Enricher.cs
+40 −0 src/Sentry/Internal/Hub.cs
+52 −0 src/Sentry/Internal/Polyfills.cs
+8 −1 src/Sentry/Platforms/Android/AndroidScopeObserver.cs
+3 −2 src/Sentry/Platforms/Android/SentrySdk.cs
+8 −1 src/Sentry/Platforms/Cocoa/CocoaScopeObserver.cs
+3 −2 src/Sentry/Platforms/Cocoa/SentrySdk.cs
+170 −0 src/Sentry/Protocol/SentryAttributes.cs
+7 −7 src/Sentry/Sentry.csproj
+30 −0 src/Sentry/SentryId.cs
+10 −70 src/Sentry/SentryLog.cs
+3 −3 src/Sentry/SentryMetric.Factory.cs
+6 −102 src/Sentry/SentryMetric.cs
+47 −0 src/Sentry/SentryOptions.cs
+12 −0 src/Sentry/SentrySdk.cs
+45 −15 src/Sentry/SpanId.cs
+43 −0 test/Sentry.OpenTelemetry.Exporter.Tests/ActivityExtensionsTests.cs
+14 −1 test/Sentry.OpenTelemetry.Exporter.Tests/SentryTracerProviderBuilderExtensionsTests.cs
+5 −0 test/Sentry.Testing/DsnSamples.cs
+1 −1 test/Sentry.Testing/FakeFailingTransport.cs
+16 −0 test/Sentry.Testing/SentryAttributesExtensions.cs
+2 −0 test/Sentry.Tests/ApiApprovalTests.Run.DotNet10_0.verified.txt
+2 −0 test/Sentry.Tests/ApiApprovalTests.Run.DotNet8_0.verified.txt
+2 −0 test/Sentry.Tests/ApiApprovalTests.Run.DotNet9_0.verified.txt
+2 −0 test/Sentry.Tests/ApiApprovalTests.Run.Net4_8.verified.txt
+150 −0 test/Sentry.Tests/DynamicSamplingContextTests.cs
+120 −0 test/Sentry.Tests/HubTests.cs
+120 −0 test/Sentry.Tests/Integrations/GlobalRootScopeIntegrationTests.cs
+35 −0 test/Sentry.Tests/Protocol/DsnTests.cs
+16 −3 test/Sentry.Tests/SentryClientTests.cs
+8 −14 test/Sentry.Tests/SentryLogTests.cs
+10 −16 test/Sentry.Tests/SentryMetricTests.cs
+6 −9 ...y.Tests/SentryOptionsTests.Integrations_default_ones_are_properly_registered.DotNet10_0.DotNet.verified.txt
+6 −9 ...SentryOptionsTests.Integrations_default_ones_are_properly_registered.DotNet10_0.Windows.DotNet.verified.txt
+6 −9 ...ry.Tests/SentryOptionsTests.Integrations_default_ones_are_properly_registered.DotNet8_0.DotNet.verified.txt
+6 −9 .../SentryOptionsTests.Integrations_default_ones_are_properly_registered.DotNet8_0.Windows.DotNet.verified.txt
+6 −9 ...ry.Tests/SentryOptionsTests.Integrations_default_ones_are_properly_registered.DotNet9_0.DotNet.verified.txt
+6 −9 .../SentryOptionsTests.Integrations_default_ones_are_properly_registered.DotNet9_0.Windows.DotNet.verified.txt
+6 −9 ....Tests/SentryOptionsTests.Integrations_default_ones_are_properly_registered.Net4_8.Windows.Net.verified.txt
+1 −1 test/Sentry.Tests/SentryOptionsTests.verify.cs
+1 −0 test/Sentry.Tests/SentryPropagationContextTests.cs
+47 −0 test/Sentry.Tests/SentrySdkTests.cs
+1 −2 test/Sentry.Tests/SentryStructuredLoggerTests.cs
27 changes: 16 additions & 11 deletions test/Sentry.Unity.Tests/UnityEventScopeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -343,19 +343,21 @@ public void UserId_SetIfEmpty()
}

[Test]
public void UserId_UnchangedIfNonEmpty()
public void UserId_DefaultUserIdOverwritesPreExisting()
{
// arrange
var options = new SentryUnityOptions(application: _testApplication) { DefaultUserId = "foo" };
// arrange - simulates the .NET SDK's GlobalRootScopeIntegration pre-setting User.Id
// before UnityScopeIntegration runs. Unity's native installation id (DefaultUserId)
// must win so managed events and native crashes share the same User.Id.
var options = new SentryUnityOptions(application: _testApplication) { DefaultUserId = "native-id" };
var sut = new UnityScopeUpdater(options, _testApplication);
var scope = new Scope(options);
scope.User.Id = "bar";
scope.User.Id = "dotnet-installation-id";

// act
sut.ConfigureScope(scope);

// assert
Assert.AreEqual(scope.User.Id, "bar");
Assert.AreEqual("native-id", scope.User.Id);
}

[Test]
Expand Down Expand Up @@ -395,26 +397,29 @@ public void UserId_ScopeSync_TriggeredWhenUserIdSet()
}

[Test]
public void UserId_ScopeSync_NotTriggeredWhenUserAlreadySet()
public void UserId_ScopeSync_TriggeredEvenWhenUserAlreadySet()
{
// arrange - User.Id already set, PopulateUser should early-return
var options = new SentryUnityOptions(application: _testApplication) { DefaultUserId = "should-not-sync" };
// arrange - simulates the .NET SDK pre-setting User.Id before UnityScopeIntegration runs.
// PopulateUser must still overwrite with DefaultUserId so the native SDK receives the
// native installation id via the scope observer.
var options = new SentryUnityOptions(application: _testApplication) { DefaultUserId = "native-id" };
var observer = new TestScopeObserver(options);
options.ScopeObserver = observer;
options.EnableScopeSync = true;

var sut = new UnityScopeUpdater(options, _testApplication);
var scope = new Scope(options);
scope.User.Id = "already-set";
scope.User.Id = "dotnet-installation-id";

// Reset observer after the initial scope.User.Id set above triggered it
observer.LastUser = null;

// act
sut.ConfigureScope(scope);

// assert - PopulateUser should not have set a new user
Assert.IsNull(observer.LastUser, "ScopeObserver.SetUser should not be called when User.Id is already set");
// assert - PopulateUser overwrote and synced the native id
Assert.IsNotNull(observer.LastUser, "ScopeObserver.SetUser should be called when DefaultUserId is set");
Assert.AreEqual("native-id", observer.LastUser!.Id);
}

[Test]
Expand Down
Loading