-
-
Notifications
You must be signed in to change notification settings - Fork 460
Hubs/Scopes Merge 22 - Combine global, isolation and current scope #3346
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
Conversation
…pes-merge-2-add-scopes
…ainScopes to rootScopes
|
|
|
||
| @Override | ||
| public @NotNull Contexts getContexts() { | ||
| return new CombinedContextsView( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CombinedContextsView isn't totally necessary to have but it avoids constantly creating copies of Contexts.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should use CombinedContextsView as ScopeType.COMBINED for cross platform SDKs should get all values and calls setDevice and setOperatingSystem so handing back a copy that isn't mutable (or rather loses updates) isn't ideal. See #3375
|
|
||
| @Override | ||
| public @NotNull IScope clone() { | ||
| // TODO just return a new CombinedScopeView with forked scope? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not quite sure here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We're now returning a new CombinedScopeView with forked isolation and current scope. See #3375
Performance metrics 🚀
|
| } | ||
|
|
||
| @Override | ||
| public @Nullable Device getDevice() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we need some propagation or copy-on-write mechanism for all Scope related fields.
E.g.
val user = Sentry.getUser() // returns global scope user, as it's unset
Sentry.setUser(user) // now default scope is set to the user
user.email = "[email protected]" // both global and default scope is written toThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm this should only happen if someone calls .setUser on global scope so an actual User instance is returned from CombinedScopeView and then pass that into .setUser that goes to current or isolation scope.
Can we ignore this edge case for now and address it, when it actually happens for a customer?
One solution would be to have something like CombinedContextsView for user and other fields.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here's an example that should avoid the problem:
sentry-java/sentry-android-core/src/main/java/io/sentry/android/core/InternalSentrySdk.java
Lines 87 to 98 in ab1c3a6
| @Nullable User user = scope.getUser(); | |
| if (user == null) { | |
| user = new User(); | |
| scope.setUser(user); | |
| } | |
| if (user.getId() == null) { | |
| try { | |
| user.setId(Installation.id(context)); | |
| } catch (RuntimeException e) { | |
| logger.log(SentryLevel.ERROR, "Could not retrieve installation ID", e); | |
| } | |
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The two comments within Scopes.getGlobalScope() could be removed:
sentry-java/sentry/src/main/java/io/sentry/Scopes.java
Lines 584 to 588 in a474402
| public @NotNull IScope getGlobalScope() { | |
| // TODO should be: | |
| return Sentry.getGlobalScope(); | |
| // return scope; | |
| } |
LGTM otherwise
#skip-changelog
📜 Description
When creating envelopes/events/transactions/... we now have to use all three scopes (global, isolation and current).
TODO: Breadcrumbs currently do not maintain insertion order across scopes. This will be adressed in a future PR.
💡 Motivation and Context
💚 How did you test it?
📝 Checklist
sendDefaultPIIis enabled.🔮 Next steps