@@ -97,26 +97,37 @@ private Sentry() {}
9797 return new HubScopesWrapper (getCurrentScopes ());
9898 }
9999
100- @ ApiStatus .Internal // exposed for the coroutines integration in SentryContext
100+ @ ApiStatus .Internal
101101 @ SuppressWarnings ("deprecation" )
102102 public static @ NotNull IScopes getCurrentScopes () {
103+ return getCurrentScopes (true );
104+ }
105+
106+ /**
107+ * Returns the current contexts scopes.
108+ *
109+ * @param ensureForked if true, forks root scopes in case there are no scopes for this context if
110+ * false, returns NoOpScopes if there are no scopes for this context
111+ * @return current scopes, a root scopes fork or NoopScopes
112+ */
113+ @ ApiStatus .Internal
114+ @ SuppressWarnings ("deprecation" )
115+ public static @ NotNull IScopes getCurrentScopes (final boolean ensureForked ) {
103116 if (globalHubMode ) {
104117 return rootScopes ;
105118 }
106119 @ Nullable IScopes scopes = getScopesStorage ().get ();
107120 if (scopes == null || scopes .isNoOp ()) {
108- scopes = rootScopes .forkedScopes ("getCurrentScopes" );
109- getScopesStorage ().set (scopes );
121+ if (!ensureForked ) {
122+ return NoOpScopes .getInstance ();
123+ } else {
124+ scopes = rootScopes .forkedScopes ("getCurrentScopes" );
125+ getScopesStorage ().set (scopes );
126+ }
110127 }
111128 return scopes ;
112129 }
113130
114- @ ApiStatus .Internal
115- public static boolean hasScopes () {
116- final @ Nullable IScopes scopes = getScopesStorage ().get ();
117- return scopes != null && !scopes .isNoOp ();
118- }
119-
120131 private static @ NotNull IScopesStorage getScopesStorage () {
121132 return scopesStorage ;
122133 }
0 commit comments