Hubs/Scopes Merge 14 - Add Scopes to replace Hub#3311
Conversation
…pes-merge-2-add-scopes
|
Performance metrics 🚀
|
| public static void pushScope() { | ||
| // pushScope is no-op in global hub mode | ||
| if (!globalHubMode) { | ||
| // TODO this might have to behave differently from Scopes.pushScope |
There was a problem hiding this comment.
I'll address pushScope, popScope and withScope in a separate PR.
There was a problem hiding this comment.
We just forward to current Scopes and let it deal with it. If pushScope is called on a non current Scopes, the Scopes forked by pushScope is made current (i.e. saved in ThreadLocal).
| final IScopes hub = getCurrentScopes(); | ||
| // TODO new Scopes() | ||
| mainScopes = new Hub(options); | ||
| final IScope rootScope = new Scope(options); |
There was a problem hiding this comment.
This bit in init will have to be replaced in a follow up PR.
There was a problem hiding this comment.
This code region has changed multiple times. #3362 has the most recent state (for now :D)
| public abstract fun endSession ()Lio/sentry/Session; | ||
| public abstract fun getAttachments ()Ljava/util/List; | ||
| public abstract fun getBreadcrumbs ()Ljava/util/Queue; | ||
| public abstract fun getClient ()Lio/sentry/ISentryClient; |
There was a problem hiding this comment.
Client now lives on IScope and we'll set the default one on global scope in the future (follow up PR).
There was a problem hiding this comment.
Client is now bound to global scope, as of #3344 but the code region is changed in later PRs a couple times.
There was a problem hiding this comment.
Sounds good! For metrics it would be important to have only one shared SentryClient instance by default, as metrics aggregation/sending is bound to that right now. If that's not the case anymore just let me know, I can take a look.
There was a problem hiding this comment.
Should still be true. The SentryClient is set on global scope on Sentry.init. Before that there's a NoOpSentryClient on global scope. By default there should also only ever be NoOpSentryClient on isolation and current scope. A user can however bind any client on any of the scopes.
| public abstract fun getEventProcessors ()Ljava/util/List; | ||
| public abstract fun getExtras ()Ljava/util/Map; | ||
| public abstract fun getFingerprint ()Ljava/util/List; | ||
| public abstract fun getLastEventId ()Lio/sentry/protocol/SentryId; |
There was a problem hiding this comment.
I was thinking that we could track last event ID per scope. By default it should probably just return the value from global scope in the future.
| } | ||
| } | ||
|
|
||
| // TODO which scopes do we call this on? isolation and current scope? |
There was a problem hiding this comment.
We need to update this in a follow up PR
| } | ||
| } | ||
|
|
||
| // TODO this seems unused |
There was a problem hiding this comment.
Yes, at first glance this is only called in a single Test. Most likely safe to remove
There was a problem hiding this comment.
Already removed in a follow up PR.
| @NotNull | ||
| PropagationContext propagationContext = | ||
| PropagationContext.fromHeaders(getOptions().getLogger(), sentryTrace, baggageHeaders); | ||
| // TODO should this go on isolation scope? |
There was a problem hiding this comment.
To me it makes sense to put this on isolation scope
There was a problem hiding this comment.
For backend this goes to isolation scope by default. For Android it goes to current scope but that should never be forked on Android.
markushi
left a comment
There was a problem hiding this comment.
Looking good, left a few comments. I'm approving this, as I assume the mentioned TODOs are addressed in the follow-up PRs.
There was a problem hiding this comment.
nit: a few final keywords are missing, e.g. in the setters.
There was a problem hiding this comment.
Will address in a follow up PR.
| public abstract fun endSession ()Lio/sentry/Session; | ||
| public abstract fun getAttachments ()Ljava/util/List; | ||
| public abstract fun getBreadcrumbs ()Ljava/util/Queue; | ||
| public abstract fun getClient ()Lio/sentry/ISentryClient; |
There was a problem hiding this comment.
Sounds good! For metrics it would be important to have only one shared SentryClient instance by default, as metrics aggregation/sending is bound to that right now. If that's not the case anymore just let me know, I can take a look.
| this(scope, isolationScope, null, options, creator); | ||
| } | ||
|
|
||
| private Scopes( |
There was a problem hiding this comment.
Seeing IScope and Scopes side by side here could be confusing to our users, since both are public APIs. I'm wondering if we could use some backwards compatible interface ScopeContext : IScope {} to make it clear that Scopes is the forking mechanism / API and ScopeContext simply the data holder.
There was a problem hiding this comment.
Scope is part of https://develop.sentry.dev/sdk/unified-api/ so I don't think we should rename it.
There was a problem hiding this comment.
Scopes is in fact a plural of Scope as it combines multiple scopes together to allow scoping things like tags etc. to the users needs.
| } | ||
|
|
||
| @Override | ||
| public @NotNull SentryId getLastEventId() { |
There was a problem hiding this comment.
It's a bit weird but JS removed this feature altogether:
REMOVED - Use event processors or beforeSend instead
But to be honest I still think we need it though 😅
There was a problem hiding this comment.
If we intend to remove it, we should deprecate it for a while and only remove this in a later major, not in 8.x.
#skip-changelog
📜 Description
Introducing
Scopesclass which shall replaceHubclass.Scopesforwards API to one/multiple of current scope, isolation scope or global scope (will be fleshed out more in follow up PRs).Scopesis somewhat of a 1:1 copy ofHubbut uses differentIScopedepending on API. Some things previously stored onHubwill have to be moved.💡 Motivation and Context
💚 How did you test it?
📝 Checklist
sendDefaultPIIis enabled.🔮 Next steps