Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 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
ce17684
Merge branch '8.x.x' into feat/hsm-20-use-separate-scopes
adinauer Apr 19, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 18 additions & 23 deletions sentry/src/main/java/io/sentry/Sentry.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ private Sentry() {}

private static volatile @NotNull IScopesStorage scopesStorage = new DefaultScopesStorage();

/** The Main Hub or NoOp if Sentry is disabled. */
private static volatile @NotNull IScopes mainScopes = NoOpScopes.getInstance();
/** The root Scopes or NoOp if Sentry is disabled. */
private static volatile @NotNull IScopes rootScopes = NoOpScopes.getInstance();
// TODO cannot pass options here
private static volatile @NotNull IScope globalScope = new Scope(new SentryOptions());

Expand All @@ -67,7 +67,7 @@ private Sentry() {}
private static final long classCreationTimestamp = System.currentTimeMillis();

/**
* Returns the current (threads) hub, if none, clones the mainScopes and returns it.
* Returns the current (threads) hub, if none, clones the rootScopes and returns it.
*
* @return the hub
*/
Expand All @@ -82,12 +82,11 @@ private Sentry() {}
@SuppressWarnings("deprecation")
public static @NotNull IScopes getCurrentScopes() {
if (globalHubMode) {
return mainScopes;
return rootScopes;
}
IScopes scopes = getScopesStorage().get();
if (scopes == null || scopes.isNoOp()) {
// TODO fork instead
scopes = mainScopes.clone();
scopes = rootScopes.forkedScopes("getCurrentScopes");
getScopesStorage().set(scopes);
}
return scopes;
Expand All @@ -98,19 +97,18 @@ private Sentry() {}
}

/**
* Returns a new hub which is cloned from the mainScopes.
* Returns a new Scopes which is cloned from the rootScopes.
*
* @return the hub
*/
@ApiStatus.Internal
@ApiStatus.Experimental
@SuppressWarnings("deprecation")
public static @NotNull IScopes cloneMainHub() {
public static @NotNull IScopes forkedRootScopes(final @NotNull String creator) {
if (globalHubMode) {
return mainScopes;
return rootScopes;
}
// TODO fork instead
return mainScopes.clone();
return rootScopes.forkedScopes(creator);
}

public static @NotNull IScopes forkedScopes(final @NotNull String creator) {
Expand All @@ -123,9 +121,9 @@ private Sentry() {}

@ApiStatus.Internal // exposed for the coroutines integration in SentryContext
@Deprecated
@SuppressWarnings({"deprecation", "InlineMeSuggester"})
public static void setCurrentHub(final @NotNull IHub hub) {
setCurrentScopes(hub);
@SuppressWarnings({"deprecation"})
public static @NotNull ISentryLifecycleToken setCurrentHub(final @NotNull IHub hub) {
return setCurrentScopes(hub);
}

@ApiStatus.Internal // exposed for the coroutines integration in SentryContext
Expand Down Expand Up @@ -272,16 +270,13 @@ private static synchronized void init(

final IScopes scopes = getCurrentScopes();
final IScope rootScope = new Scope(options);
// TODO should use separate isolation scope:
// final IScope rootIsolationScope = new Scope(options);
// TODO should be:
// getGlobalScope().bindClient(new SentryClient(options));
rootScope.bindClient(new SentryClient(options));
final IScope rootIsolationScope = new Scope(options);
// TODO shouldn't replace global scope
globalScope = rootScope;
mainScopes = new Scopes(rootScope, rootScope, options, "Sentry.init");
globalScope = new Scope(options);
globalScope.bindClient(new SentryClient(options));
rootScopes = new Scopes(rootScope, rootIsolationScope, options, "Sentry.init");

getScopesStorage().set(mainScopes);
getScopesStorage().set(rootScopes);

scopes.close(true);

Expand Down Expand Up @@ -529,7 +524,7 @@ private static boolean initConfigurations(final @NotNull SentryOptions options)
/** Close the SDK */
public static synchronized void close() {
final IScopes scopes = getCurrentScopes();
mainScopes = NoOpScopes.getInstance();
rootScopes = NoOpScopes.getInstance();
// remove thread local to avoid memory leak
getScopesStorage().close();
scopes.close(false);
Expand Down
10 changes: 5 additions & 5 deletions sentry/src/test/java/io/sentry/SentryTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ class SentryTest {
assertNotNull(scopes)
assertFalse(Sentry.getCurrentScopes().isNoOp)

val newMainHubClone = Sentry.cloneMainHub()
val newMainHubClone = Sentry.forkedRootScopes("test")
newMainHubClone.addBreadcrumb("breadcrumbMainClone")

scopes.captureMessage("messageCurrent")
Expand Down Expand Up @@ -473,7 +473,7 @@ class SentryTest {
assertNotNull(scopes)
assertFalse(scopes.isNoOp)

val newMainHubClone = Sentry.cloneMainHub()
val newMainHubClone = Sentry.forkedRootScopes("test")
newMainHubClone.addBreadcrumb("breadcrumbMainClone")

scopes.captureMessage("messageCurrent")
Expand Down Expand Up @@ -921,7 +921,7 @@ class SentryTest {
}

@Test
fun `getSpan calls returns root span if globalscopes mode is enabled on Android`() {
fun `getSpan calls returns root span if globalHubMode is enabled on Android`() {
PlatformTestManipulator.pretendIsAndroid(true)
Sentry.init({
it.dsn = dsn
Expand All @@ -938,7 +938,7 @@ class SentryTest {
}

@Test
fun `getSpan calls returns child span if globalscopes mode is enabled, but the platform is not Android`() {
fun `getSpan calls returns child span if globalHubMode is enabled, but the platform is not Android`() {
PlatformTestManipulator.pretendIsAndroid(false)
Sentry.init({
it.dsn = dsn
Expand All @@ -954,7 +954,7 @@ class SentryTest {
}

@Test
fun `getSpan calls returns child span if globalscopes mode is disabled`() {
fun `getSpan calls returns child span if globalHubMode is disabled`() {
Sentry.init({
it.dsn = dsn
it.enableTracing = true
Expand Down