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 42d - Close previous scopes before binding a new global client #3404

Merged
merged 52 commits into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
305baf5
replace hub with scopes
adinauer Mar 27, 2024
95f5e1b
Add Scopes
adinauer Apr 2, 2024
27f2398
Introduce `IScopes` interface.
adinauer Apr 2, 2024
ce3c14f
Replace `IHub` with `IScopes` in core
adinauer Apr 2, 2024
ce615f4
Replace `IHub` with `IScopes` in android core
adinauer Apr 2, 2024
22ddc00
Replace `IHub` with `IScopes` in android integrations
adinauer Apr 2, 2024
305c217
Replace `IHub` with `IScopes` in apollo integrations
adinauer Apr 2, 2024
da927bc
Replace `IHub` with `IScopes` in okhttp integration
adinauer Apr 2, 2024
8279276
Replace `IHub` with `IScopes` in graphql integration
adinauer Apr 2, 2024
9bfc086
Replace `IHub` with `IScopes` in logging integrations
adinauer Apr 2, 2024
b998e50
Replace `IHub` with `IScopes` in more integrations
adinauer Apr 2, 2024
739827a
Replace `IHub` with `IScopes` in OTel integration
adinauer Apr 2, 2024
69f2d63
Replace `IHub` with `IScopes` in Spring 5 / Spring Boot 2 integrations
adinauer Apr 2, 2024
792d482
Replace `IHub` with `IScopes` in Spring 6 / Spring Boot 3 integrations
adinauer Apr 2, 2024
9bcbce6
Replace `IHub` with `IScopes` in samples
adinauer Apr 2, 2024
3f25a4b
Merge branch 'feat/hsm-13-replacements-in-samples' into feat/hubs-sco…
adinauer Apr 2, 2024
d6fb40a
gitscopes -> github
adinauer Apr 2, 2024
7752bcc
Replace ThreadLocal with ScopesStorage
adinauer Apr 4, 2024
1e329c5
Move client and throwable to span map to scope
adinauer Apr 4, 2024
b0d89ae
Add global scope
adinauer Apr 4, 2024
cdd414a
use global scope in Scopes
adinauer Apr 4, 2024
98da9ff
Implement pushScope popScope and withScope for Scopes
adinauer Apr 4, 2024
2d26033
Add pushIsolationScope; add fork methods to ISCope
adinauer Apr 12, 2024
bbb6700
Use separate scopes for current, isolation and global scope; rename m…
adinauer Apr 12, 2024
c714b21
Allow controlling which scope configureScope uses
adinauer Apr 12, 2024
a474402
Combine scopes
adinauer Apr 12, 2024
ae93e33
Use new API for CRONS integrations
adinauer Apr 12, 2024
b01298b
Add lifecycle helper
adinauer Apr 12, 2024
b64e688
Change spring integrations to use new API
adinauer Apr 12, 2024
d06fc50
Use new API in servlet integrations
adinauer Apr 12, 2024
f0af5c3
Use new API for kotlin coroutines and wrapers for Supplier/Callable
adinauer Apr 12, 2024
2f02001
Discussion TODOs
adinauer Apr 12, 2024
bf4a7bf
Fix breadcrumb ordering
adinauer Apr 15, 2024
62cb91a
Mark TODOS with [HSM]
adinauer Apr 15, 2024
b1630ea
Add getGlobalScope and forkedRootScopes to IScopes
adinauer Apr 16, 2024
136b9ce
Fix EventProcessor ordering on scopes
adinauer Apr 16, 2024
94d54ef
Reuse code in Scopes
adinauer Apr 16, 2024
017599d
No longer replace global scope
adinauer Apr 16, 2024
f4c2b3c
Replace hub occurrences in comments, var names etc.
adinauer Apr 16, 2024
61c9d4a
Implement ScopesTest
adinauer Apr 18, 2024
04f3892
Implement CombinedScopeViewTest
adinauer Apr 18, 2024
840c194
Fix combined contexts
adinauer Apr 19, 2024
ab1c3a6
Use combined scopes for cross platform
adinauer Apr 19, 2024
23506c5
Changes according to reviews of previous PRs
adinauer Apr 23, 2024
c9b6f8b
more
adinauer Apr 23, 2024
696a809
even more
adinauer Apr 23, 2024
847200d
isEnabled checks client instead of having a property on Scopes
adinauer Apr 24, 2024
8e86d3b
Use SentryOptions.empty
adinauer Apr 25, 2024
06db228
Remove Hub
adinauer Apr 25, 2024
d4a35bb
Close previous scopes before binding a new global client
adinauer May 2, 2024
28de44b
Merge branch '8.x.x' into feat/hsm-42d-close-bind-client-ordering
adinauer May 2, 2024
dee2203
Merge branch '8.x.x' into feat/hsm-42d-close-bind-client-ordering
adinauer May 3, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions sentry/src/main/java/io/sentry/Sentry.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ private Sentry() {}
*/
// TODO [HSM] use SentryOptions.empty and address
// https://github.com/getsentry/sentry-java/issues/2541
private static volatile @NotNull IScope globalScope = new Scope(SentryOptions.empty());
private static final @NotNull IScope globalScope = new Scope(SentryOptions.empty());

/** Default value for globalHubMode is false */
private static final boolean GLOBAL_HUB_DEFAULT_MODE = false;
Expand Down Expand Up @@ -277,12 +277,12 @@ private static synchronized void init(
final IScopes scopes = getCurrentScopes();
final IScope rootScope = new Scope(options);
final IScope rootIsolationScope = new Scope(options);
globalScope.bindClient(new SentryClient(options));
rootScopes = new Scopes(rootScope, rootIsolationScope, globalScope, "Sentry.init");

getScopesStorage().set(rootScopes);

scopes.close(true);
globalScope.bindClient(new SentryClient(options));

// If the executorService passed in the init is the same that was previously closed, we have to
// set a new one
Expand Down
32 changes: 32 additions & 0 deletions sentry/src/test/java/io/sentry/SentryTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,38 @@ class SentryTest {
verify(scopes).close(eq(true))
}

@Test
fun `global client is enabled after restart`() {
val scopes = mock<IScopes>()
whenever(scopes.close()).then { Sentry.getGlobalScope().client.close() }
whenever(scopes.close(anyOrNull())).then { Sentry.getGlobalScope().client.close() }

Sentry.init {
it.dsn = dsn
}
Sentry.setCurrentScopes(scopes)
Sentry.init {
it.dsn = dsn
}
verify(scopes).close(eq(true))
assertTrue(Sentry.getGlobalScope().client.isEnabled)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should we also check that Sentry.getCurrentScopes() has an enabled client?

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 basically already are. It'd be more of a duplicate of tests already present in ScopesTest / CombinedScopeViewTest. I think it's fine as is.

}

@Test
fun `global client is disabled after close`() {
val scopes = mock<IScopes>()
whenever(scopes.close()).then { Sentry.getGlobalScope().client.close() }
whenever(scopes.close(anyOrNull())).then { Sentry.getGlobalScope().client.close() }

Sentry.init {
it.dsn = dsn
}
Sentry.setCurrentScopes(scopes)
Sentry.close()
verify(scopes).close(eq(false))
assertFalse(Sentry.getGlobalScope().client.isEnabled)
}

@Test
fun `close calls scopes close with isRestarting false`() {
val scopes = mock<IScopes>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,16 @@ import org.mockito.kotlin.check
import org.mockito.kotlin.mock
import org.mockito.kotlin.verify
import org.mockito.kotlin.whenever
import kotlin.test.BeforeTest
import kotlin.test.Test

class MetricsIntegrationTest {

@BeforeTest
Copy link
Member Author

Choose a reason for hiding this comment

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

Test started becoming flaky. Not sure why exactly.

fun setup() {
Sentry.close()
}

@Test
fun `metrics are collected`() {
val options = SentryOptions().apply {
Expand Down