Skip to content

Commit 3f30abe

Browse files
committed
Avoid forking rootScopes for Reactor if current thread has NoOpScopes
1 parent 96449e8 commit 3f30abe

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

sentry-reactor/src/main/java/io/sentry/reactor/SentryReactorThreadLocalAccessor.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,11 @@ public Object key() {
1616

1717
@Override
1818
public IScopes getValue() {
19-
return Sentry.getCurrentScopes();
19+
if (Sentry.hasScopes()) {
20+
return Sentry.getCurrentScopes();
21+
} else {
22+
return NoOpScopes.getInstance();
23+
}
2024
}
2125

2226
@Override

sentry/api/sentry.api

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2599,6 +2599,7 @@ public final class io/sentry/Sentry {
25992599
public static fun getLastEventId ()Lio/sentry/protocol/SentryId;
26002600
public static fun getSpan ()Lio/sentry/ISpan;
26012601
public static fun getTraceparent ()Lio/sentry/SentryTraceHeader;
2602+
public static fun hasScopes ()Z
26022603
public static fun init ()V
26032604
public static fun init (Lio/sentry/OptionsContainer;Lio/sentry/Sentry$OptionsConfiguration;)V
26042605
public static fun init (Lio/sentry/OptionsContainer;Lio/sentry/Sentry$OptionsConfiguration;Z)V

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,12 @@ private Sentry() {}
112112
return scopes;
113113
}
114114

115+
@ApiStatus.Internal
116+
public static boolean hasScopes() {
117+
final @Nullable IScopes scopes = getScopesStorage().get();
118+
return scopes != null && !scopes.isNoOp();
119+
}
120+
115121
private static @NotNull IScopesStorage getScopesStorage() {
116122
return scopesStorage;
117123
}

0 commit comments

Comments
 (0)