Skip to content
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

Merged
merged 18 commits into from
Apr 19, 2024

Conversation

adinauer
Copy link
Member

@adinauer adinauer commented Apr 2, 2024

#skip-changelog

📜 Description

Introducing Scopes class which shall replace Hub 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 of Hub but uses different IScope depending on API. Some things previously stored on Hub will have to be moved.

💡 Motivation and Context

💚 How did you test it?

📝 Checklist

  • I reviewed the submitted code.
  • I added tests to verify the changes.
  • No new PII added or SDK only sends newly added PII if sendDefaultPII is enabled.
  • I updated the docs if needed.
  • Review from the native team if needed.
  • No breaking change or entry added to the changelog.
  • No breaking change for hybrid SDKs or communicated to hybrid SDKs.

🔮 Next steps

Copy link
Contributor

github-actions bot commented Apr 2, 2024

Messages
📖 Do not forget to update Sentry-docs with your feature once the pull request gets approved.

Generated by 🚫 dangerJS against d260706

Copy link
Contributor

github-actions bot commented Apr 2, 2024

Performance metrics 🚀

  Plain With Sentry Diff
Startup time 397.27 ms 441.39 ms 44.12 ms
Size 1.70 MiB 2.24 MiB 555.31 KiB

@@ -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
Copy link
Member Author

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.

Copy link
Member Author

@adinauer adinauer Apr 16, 2024

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);
Copy link
Member Author

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.

Copy link
Member Author

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;
Copy link
Member Author

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).

Copy link
Member Author

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.

Copy link
Member

@markushi markushi Apr 17, 2024

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.

Copy link
Member Author

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;
Copy link
Member Author

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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed in #3346

@adinauer adinauer marked this pull request as ready for review April 4, 2024 11:38
}
}

// TODO which scopes do we call this on? isolation and current scope?
Copy link
Collaborator

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

Copy link
Member Author

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
Copy link
Collaborator

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

Copy link
Member Author

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?
Copy link
Collaborator

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

Copy link
Member Author

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.

Base automatically changed from feat/hsm-13-replacements-in-samples to 8.x.x April 16, 2024 14:47
Copy link
Member

@markushi markushi left a 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.

Copy link
Member

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.

Copy link
Member Author

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;
Copy link
Member

@markushi markushi Apr 17, 2024

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(
Copy link
Member

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.

Copy link
Member Author

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.

Copy link
Member Author

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() {
Copy link
Member

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 😅

Copy link
Member Author

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.

@adinauer adinauer merged commit 7a0cd9f into 8.x.x Apr 19, 2024
6 of 20 checks passed
@adinauer adinauer deleted the feat/hubs-scopes-merge-2-add-scopes branch April 19, 2024 11:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants