-
-
Notifications
You must be signed in to change notification settings - Fork 445
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
Hubs/Scopes Merge 14 - Add Scopes
to replace Hub
#3311
Conversation
…pes-merge-2-add-scopes
|
Performance metrics 🚀
|
@@ -800,6 +801,7 @@ public static void removeExtra(final @NotNull String key) { | |||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll address pushScope
, popScope
and withScope
in a separate PR.
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 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).
@@ -254,8 +254,9 @@ private static synchronized void init( | |||
Sentry.globalHubMode = globalHubMode; | |||
|
|||
final IScopes hub = getCurrentScopes(); | |||
// TODO new Scopes() | |||
mainScopes = new Hub(options); | |||
final IScope rootScope = new Scope(options); |
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.
This bit in init
will have to be replaced in a follow up PR.
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.
This code region has changed multiple times. #3362 has the most recent state (for now :D)
@@ -661,10 +661,12 @@ public abstract interface class io/sentry/IScope { | |||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 getContexts ()Lio/sentry/protocol/Contexts; | ||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
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.
Changed in #3346
} | ||
} | ||
|
||
// TODO which scopes do we call this on? isolation and current 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.
I would think so, yes
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 need to update this in a follow up PR
} | ||
} | ||
|
||
// TODO this seems unused |
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.
Yes, at first glance this is only called in a single Test. Most likely safe to remove
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To me it makes sense to put this on isolation 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.
For backend this goes to isolation scope by default. For Android it goes to current scope but that should never be forked on Android.
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit
: a few final
keywords are missing, e.g. in the setters.
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.
Will address in a follow up PR.
@@ -661,10 +661,12 @@ public abstract interface class io/sentry/IScope { | |||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
Scopes
class which shall replaceHub
class.Scopes
forwards API to one/multiple of current scope, isolation scope or global scope (will be fleshed out more in follow up PRs).Scopes
is somewhat of a 1:1 copy ofHub
but uses differentIScope
depending on API. Some things previously stored onHub
will have to be moved.💡 Motivation and Context
💚 How did you test it?
📝 Checklist
sendDefaultPII
is enabled.🔮 Next steps