-
-
Notifications
You must be signed in to change notification settings - Fork 234
feat: User.Id can now be overriden (set to null) in Global mode #5039
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
28e9845
feat: User.Id can now be overriden (set to null) in Global mode
jamescrosswell 1b15d0f
additional core verify tests
jamescrosswell 7b2e38d
Windows verify files
jamescrosswell 7a7d0f6
Fix verify files
jamescrosswell 9907a6c
Windows verify files
jamescrosswell 2663ae0
Skip tests on mobile
jamescrosswell abca943
Fixed build on NetFX/Standard
jamescrosswell 8c2d66b
Update src/Sentry/Internal/Enricher.cs
jamescrosswell 04435e6
Merge branch 'main' into remove-user-id-4172
jamescrosswell 219f31e
Improve tests
jamescrosswell 8ae30ad
Merge remote-tracking branch 'origin/remove-user-id-4172' into remove…
jamescrosswell 4d523b3
Merge remote-tracking branch 'origin/main' into remove-user-id-4172
jamescrosswell 070e294
test: improve consistency in GlobalRootScopeIntegrationTests
jamescrosswell 3141233
Apply suggestions from code review
jamescrosswell af186b3
test: address review nits in SentryClientTests
jamescrosswell File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| namespace Sentry.Integrations; | ||
|
|
||
| internal class GlobalRootScopeIntegration : ISdkIntegration | ||
| { | ||
| public void Register(IHub hub, SentryOptions options) | ||
| { | ||
| if (!options.IsGlobalModeEnabled) | ||
| { | ||
| return; | ||
| } | ||
|
|
||
| hub.ConfigureScope(scope => scope.User.Id ??= options.InstallationId); | ||
|
Flash0ver marked this conversation as resolved.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could use the non-Closure-allocating overload: -hub.ConfigureScope(scope => scope.User.Id ??= options.InstallationId);
+hub.ConfigureScope(static (scope, options) => scope.User.Id ??= options.InstallationId, options);But let's do this in a follow-up, as this would also need a change to the tests, and it's not really worth going through the entire cycle again. Opened #5219. |
||
| } | ||
|
jamescrosswell marked this conversation as resolved.
|
||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
120 changes: 120 additions & 0 deletions
120
test/Sentry.Tests/Integrations/GlobalRootScopeIntegrationTests.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,120 @@ | ||
| using Sentry.Integrations; | ||
|
|
||
| namespace Sentry.Tests.Integrations; | ||
|
|
||
| public class GlobalRootScopeIntegrationTests | ||
| { | ||
| [Fact] | ||
| public void Register_GlobalModeDisabled_DoesNotConfigureScope() | ||
| { | ||
| // Arrange | ||
| var options = new SentryOptions | ||
| { | ||
| Dsn = ValidDsn, | ||
| IsGlobalModeEnabled = false, | ||
| AutoSessionTracking = false | ||
| }; | ||
| var scope = new Scope(); | ||
|
|
||
| var hub = Substitute.For<IHub>(); | ||
| hub.SubstituteConfigureScope(scope); | ||
| var integration = new GlobalRootScopeIntegration(); | ||
|
|
||
| // Act | ||
| integration.Register(hub, options); | ||
|
|
||
| // Assert | ||
| hub.DidNotReceive().ConfigureScope(Arg.Any<Action<Scope>>()); | ||
|
jamescrosswell marked this conversation as resolved.
|
||
| scope.User.Id.Should().BeNull(); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void Register_GlobalModeEnabled_SetsInstallationIdOnRootScope() | ||
| { | ||
| // Arrange | ||
| var options = new SentryOptions | ||
| { | ||
| Dsn = ValidDsn, | ||
| IsGlobalModeEnabled = true, | ||
| AutoSessionTracking = false | ||
| }; | ||
| var scope = new Scope(); | ||
|
|
||
| var hub = Substitute.For<IHub>(); | ||
| hub.SubstituteConfigureScope(scope); | ||
| var integration = new GlobalRootScopeIntegration(); | ||
|
|
||
| // Act | ||
| integration.Register(hub, options); | ||
|
|
||
| // Assert | ||
| hub.Received(1).ConfigureScope(Arg.Any<Action<Scope>>()); | ||
| scope.User.Id.Should().Be(options.InstallationId); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void Register_GlobalModeEnabled_DoesNotOverwriteExistingUserId() | ||
| { | ||
| // Arrange | ||
| var options = new SentryOptions | ||
| { | ||
| Dsn = ValidDsn, | ||
| IsGlobalModeEnabled = true, | ||
| AutoSessionTracking = false | ||
| }; | ||
| var oldId = "old-id"; | ||
| var scope = new Scope | ||
| { | ||
| User = | ||
| { | ||
| Id = oldId | ||
| } | ||
| }; | ||
|
|
||
| var hub = Substitute.For<IHub>(); | ||
| hub.SubstituteConfigureScope(scope); | ||
| var integration = new GlobalRootScopeIntegration(); | ||
|
|
||
| // Act | ||
| integration.Register(hub, options); | ||
|
|
||
| // Assert | ||
| hub.Received(1).ConfigureScope(Arg.Any<Action<Scope>>()); | ||
| scope.User.Id.Should().Be(oldId); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void Enricher_GlobalModeEnabled_DoesNotSetInstallationId() | ||
| { | ||
| // Verify the enricher no longer sets User.Id when global mode is enabled, | ||
| // ensuring users can clear the User.Id set by GlobalRootScopeIntegration. | ||
| var options = new SentryOptions { IsGlobalModeEnabled = true }; | ||
| var enricher = new Sentry.Internal.Enricher(options); | ||
|
|
||
| var eventLike = Substitute.For<IEventLike>(); | ||
| eventLike.Sdk.Returns(new SdkVersion()); | ||
| eventLike.User = new SentryUser(); | ||
| eventLike.Contexts = new SentryContexts(); | ||
|
|
||
| enricher.Apply(eventLike); | ||
|
|
||
| eventLike.User.Id.Should().BeNull(); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void Enricher_GlobalModeDisabled_SetsInstallationIdAsFallback() | ||
| { | ||
| // Verify the enricher still sets User.Id when global mode is disabled (e.g. ASP.NET Core). | ||
| var options = new SentryOptions { IsGlobalModeEnabled = false }; | ||
| var enricher = new Sentry.Internal.Enricher(options); | ||
|
|
||
| var eventLike = Substitute.For<IEventLike>(); | ||
| eventLike.Sdk.Returns(new SdkVersion()); | ||
| eventLike.User = new SentryUser(); | ||
| eventLike.Contexts = new SentryContexts(); | ||
|
|
||
| enricher.Apply(eventLike); | ||
|
|
||
| eventLike.User.Id.Should().Be(options.InstallationId); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.