-
-
Notifications
You must be signed in to change notification settings - Fork 30
fix(sentry-java): Contexts belong on the Scope #504
fix(sentry-java): Contexts belong on the Scope #504
Conversation
sentry-samples/sentry-samples-console/src/main/java/io/sentry/samples/console/Main.java
Show resolved
Hide resolved
sentry-core/src/main/java/io/sentry/core/util/CollectionUtils.java
Outdated
Show resolved
Hide resolved
marandaneto
left a comment
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.
@maciejwalkowiak thanks for doing this, I left a few comments and it's looking good.
my main point here is, Contexts is cloned but not used, wondering if we could do the merging of contexts on this PR or to raise a new one, but I'd say that both PRs should land together.
if you look at DefaultAndroidEventProcessor, it accesses the event.getContexts() and we'd need to check if the scope has that value and also which one has precedence over it, event or scope?
eg: event.contexts.device is not null, so do we keep as it is or use scope.contexts.device?
or even event.contexts.device.bla exists but also scope.contexts.device.bla, which one wins? etc.
|
Another thing I have in mind if we should implement |
|
@marandaneto regarding actually using but I might have missed something from the bigger picture. |
that sounds a good idea, as I said, the |
yep, this would be moved either to SentryClient or MainEventProcessor, but a note here is, in order to read some device context, we need to have the Android Context and that's why we have this |
|
Please be aware: if (event.getContexts().isEmpty()) {
event.setContexts(scope.getContexts());
}The values copied must be cloned. Otherwise while the event is queued for submission, the scope by be changed, affecting that event. The only references they'd share is any user-defined one, which we were not able to clone with our own deep cloning strategy (i.e Reference types in Extra and Contexts) |
|
There's a PR to this PR: maciejwalkowiak#1 |
* Fix thread-safety when copying maps * Make sure `Users#other` is thread-safe. * Do not enforce thread-safe maps on `unknown` properties for classes that are not part of the `Scope`.
What if we add this to for (Map.Entry<String, Object> entry : scope.getContexts().clone().entrySet()) {
if (!event.getContexts().containsKey(entry.getKey())) {
event.getContexts().put(entry.getKey(), entry.getValue());
}
}
|
Makes sense to me. |
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.
Approving but let's see what @marandaneto has to say
its LGTM for me too, well done @maciejwalkowiak |
📢 Type of change
📜 Description
Adds
Contextsto scope together with deep cloning for knownCloneableobjects.💡 Motivation and Context
Continuation of #240.
💚 How did you test it?
📝 Checklist
🔮 Next steps