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 33 - No longer replace global scope #3362

Merged
merged 39 commits into from
May 2, 2024

Conversation

adinauer
Copy link
Member

#skip-changelog

📜 Description

We're now instantiating globalScope with default SentryOptions. These are replaced in a static {} block for SentryAndroid (temporarily) and then replaced on Sentry.init to actually use options customized by the user.

Also remove options from Scopes and instead use globla scope options (via CombinedScopeView).

💡 Motivation and Context

Before we were replacing global scope on Sentry.init.

💚 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

adinauer and others added 30 commits March 27, 2024 16:30
Copy link
Contributor

github-actions bot commented Apr 16, 2024

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

Generated by 🚫 dangerJS against 0b5a5a0

@@ -44,6 +44,7 @@ public final class InternalSentrySdk {
@Nullable
public static IScope getCurrentScope() {
final @NotNull AtomicReference<IScope> scopeRef = new AtomicReference<>();
// TODO [HSM] should this retrieve combined 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.

This way, if a user adds, e.g. tags to global scope, cross platform SDKs will also receive the tag.

@ApiStatus.Internal
@Override
public void replaceOptions(final @NotNull SentryOptions options) {
// TODO [HSM] check if already enabled and noop in that case?
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 shouldn't be used after Sentry.init since only some options are actually updated.

this.tracesSampler = new TracesSampler(options);
this.transactionPerformanceCollector = options.getTransactionPerformanceCollector();

// TODO [HSM] Checking isEnabled may not be what we want with global scope anymore
Copy link
Member Author

Choose a reason for hiding this comment

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

Allowing users to use global scope before Sentry.init may imply that we can't noop if not yet enabled.

Copy link
Collaborator

Choose a reason for hiding this comment

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

What do we do then, if a capture method is called before Sentry.init?

Right now, this would call capture on NoOpScope with no information for the user, right?

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'd say if the SDK hasn't been enabled yet we shouldn't send anything. We shouldn't store things to send once enabled as the SDK might never be enabled.

RFC also suggests to not do anything in that case: https://github.com/getsentry/rfcs/pull/122/files#diff-c9abcee1a2612ddd7dd66e226e832f520e6b4cbc67bdcbb5371514af7d25ae38R94

Copy link
Contributor

github-actions bot commented Apr 16, 2024

Performance metrics 🚀

  Plain With Sentry Diff
Startup time 386.67 ms 465.00 ms 78.33 ms
Size 1.70 MiB 2.28 MiB 596.26 KiB

Previous results on branch: feat/hsm-33-no-longer-replace-global-scope

Startup times

Revision Plain With Sentry Diff
098d86b 366.02 ms 442.43 ms 76.41 ms

App size

Revision Plain With Sentry Diff
098d86b 1.70 MiB 2.28 MiB 596.26 KiB

@@ -24,6 +24,10 @@
/** Sentry initialization class */
public final class SentryAndroid {

static {
Sentry.getGlobalScope().replaceOptions(new SentryAndroidOptions());
Copy link
Member

Choose a reason for hiding this comment

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

Maybe @romtsn can recall exactly, but I think creating options can be expensive. There's also SentryOptions.empty(), maybe that's better?

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah, might be a good idea.

Copy link
Member

Choose a reason for hiding this comment

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

even the empty() one will instantiate some of the options fields (like EnvelopeReader or JsonSerializer), so ideally we don't do that, but I guess there's no way around it. We should just probably fix the root cause here eventually and lazily initialize those fields #2541

Copy link
Member

Choose a reason for hiding this comment

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

IIRC we discussed that this is not required, as any integrations / processors will access the SentryAndroidOptions only after Sentry.init() which replaces the options already.

@@ -24,6 +24,10 @@
/** Sentry initialization class */
public final class SentryAndroid {

static {
Sentry.getGlobalScope().replaceOptions(new SentryAndroidOptions());
Copy link
Member

Choose a reason for hiding this comment

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

IIRC we discussed that this is not required, as any integrations / processors will access the SentryAndroidOptions only after Sentry.init() which replaces the options already.

Base automatically changed from feat/hsm-32-reuse-code-in-scopes to 8.x.x May 2, 2024 12:05
@adinauer adinauer merged commit 2e11284 into 8.x.x May 2, 2024
11 of 20 checks passed
@adinauer adinauer deleted the feat/hsm-33-no-longer-replace-global-scope branch May 2, 2024 12:15
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.

4 participants