diff --git a/sentry/api/sentry.api b/sentry/api/sentry.api index e17c36b2e96..44f4fe4d89c 100644 --- a/sentry/api/sentry.api +++ b/sentry/api/sentry.api @@ -2004,6 +2004,7 @@ public final class io/sentry/Sentry { public static fun getBaggage ()Lio/sentry/BaggageHeader; public static fun getCurrentHub ()Lio/sentry/IHub; public static fun getCurrentScopes ()Lio/sentry/IScopes; + public static fun getGlobalScope ()Lio/sentry/IScope; public static fun getLastEventId ()Lio/sentry/protocol/SentryId; public static fun getSpan ()Lio/sentry/ISpan; public static fun getTraceparent ()Lio/sentry/SentryTraceHeader; diff --git a/sentry/src/main/java/io/sentry/Scopes.java b/sentry/src/main/java/io/sentry/Scopes.java index b384d39c05d..c440b995ec5 100644 --- a/sentry/src/main/java/io/sentry/Scopes.java +++ b/sentry/src/main/java/io/sentry/Scopes.java @@ -579,8 +579,9 @@ private void updateLastEventId(final @NotNull SentryId lastEventId) { // TODO add to IScopes interface public @NotNull IScope getGlobalScope() { - // TODO return singleton global scope here - return scope; + // TODO should be: + return Sentry.getGlobalScope(); + // return scope; } @Override diff --git a/sentry/src/main/java/io/sentry/Sentry.java b/sentry/src/main/java/io/sentry/Sentry.java index e01ca2f281d..76ada357f2a 100644 --- a/sentry/src/main/java/io/sentry/Sentry.java +++ b/sentry/src/main/java/io/sentry/Sentry.java @@ -47,6 +47,8 @@ private Sentry() {} /** The Main Hub or NoOp if Sentry is disabled. */ private static volatile @NotNull IScopes mainScopes = NoOpScopes.getInstance(); + // TODO cannot pass options here + private static volatile @NotNull IScope globalScope = new Scope(new SentryOptions()); /** Default value for globalHubMode is false */ private static final boolean GLOBAL_HUB_DEFAULT_MODE = false; @@ -122,6 +124,9 @@ public static void setCurrentHub(final @NotNull IHub hub) { public static @NotNull ISentryLifecycleToken setCurrentScopes(final @NotNull IScopes scopes) { return getScopesStorage().set(scopes); } + + public static @NotNull IScope getGlobalScope() { + return globalScope; } /** @@ -264,6 +269,8 @@ private static synchronized void init( // TODO should be: // getGlobalScope().bindClient(new SentryClient(options)); rootScope.bindClient(new SentryClient(options)); + // TODO shouldn't replace global scope + globalScope = rootScope; mainScopes = new Scopes(rootScope, rootScope, options, "Sentry.init"); getScopesStorage().set(mainScopes);