Skip to content

Commit b0d89ae

Browse files
committed
Add global scope
1 parent 1e329c5 commit b0d89ae

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

sentry/api/sentry.api

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2001,6 +2001,7 @@ public final class io/sentry/Sentry {
20012001
public static fun getBaggage ()Lio/sentry/BaggageHeader;
20022002
public static fun getCurrentHub ()Lio/sentry/IHub;
20032003
public static fun getCurrentScopes ()Lio/sentry/IScopes;
2004+
public static fun getGlobalScope ()Lio/sentry/IScope;
20042005
public static fun getLastEventId ()Lio/sentry/protocol/SentryId;
20052006
public static fun getSpan ()Lio/sentry/ISpan;
20062007
public static fun getTraceparent ()Lio/sentry/SentryTraceHeader;

sentry/src/main/java/io/sentry/Scopes.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -579,7 +579,8 @@ private void updateLastEventId(final @NotNull SentryId lastEventId) {
579579

580580
// TODO add to IScopes interface
581581
public @NotNull IScope getGlobalScope() {
582-
// TODO return singleton global scope here
582+
// TODO should be:
583+
// return Sentry.getGlobalScope();
583584
return scope;
584585
}
585586

sentry/src/main/java/io/sentry/Sentry.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ private Sentry() {}
4747

4848
/** The Main Hub or NoOp if Sentry is disabled. */
4949
private static volatile @NotNull IScopes mainScopes = NoOpScopes.getInstance();
50+
// TODO cannot pass options here
51+
private static volatile @NotNull IScope globalScope = new Scope(new SentryOptions());
5052

5153
/** Default value for globalHubMode is false */
5254
private static final boolean GLOBAL_HUB_DEFAULT_MODE = false;
@@ -122,6 +124,9 @@ public static void setCurrentHub(final @NotNull IHub hub) {
122124
public static @NotNull ISentryLifecycleToken setCurrentScopes(final @NotNull IScopes scopes) {
123125
return getScopesStorage().set(scopes);
124126
}
127+
128+
public static @NotNull IScope getGlobalScope() {
129+
return globalScope;
125130
}
126131

127132
/**
@@ -264,6 +269,8 @@ private static synchronized void init(
264269
// TODO should be:
265270
// getGlobalScope().bindClient(new SentryClient(options));
266271
rootScope.bindClient(new SentryClient(options));
272+
// TODO shouldn't replace global scope
273+
globalScope = rootScope;
267274
mainScopes = new Scopes(rootScope, rootScope, options, "Sentry.init");
268275

269276
getScopesStorage().set(mainScopes);

0 commit comments

Comments
 (0)