Skip to content

Commit 0792d93

Browse files
committed
fix changelog; replace hasScopes with bool param on getCurrentScopes
1 parent a29d0f2 commit 0792d93

File tree

4 files changed

+25
-16
lines changed

4 files changed

+25
-16
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Changelog
22

3-
## 8.23.1-alpha.1
3+
## Unreleased
44

55
### Features
66

@@ -29,6 +29,8 @@
2929
- Fix profilerId propagation ([#4833](https://github.com/getsentry/sentry-java/pull/4833))
3030
- Fix profiling init for Spring and Spring Boot w Agent auto-init ([#4815](https://github.com/getsentry/sentry-java/pull/4815))
3131
- Copy active span on scope clone ([#4878](https://github.com/getsentry/sentry-java/pull/4878))
32+
- Avoid forking `rootScopes` for Reactor if current thread has NoOpScopes ([#4793](https://github.com/getsentry/sentry-java/pull/4793))
33+
- This reduces the SDKs overhead by avoiding unnecessary scope forks
3234

3335
### Improvements
3436

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

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

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

2622
@Override

sentry/api/sentry.api

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2631,11 +2631,11 @@ public final class io/sentry/Sentry {
26312631
public static fun getBaggage ()Lio/sentry/BaggageHeader;
26322632
public static fun getCurrentHub ()Lio/sentry/IHub;
26332633
public static fun getCurrentScopes ()Lio/sentry/IScopes;
2634+
public static fun getCurrentScopes (Z)Lio/sentry/IScopes;
26342635
public static fun getGlobalScope ()Lio/sentry/IScope;
26352636
public static fun getLastEventId ()Lio/sentry/protocol/SentryId;
26362637
public static fun getSpan ()Lio/sentry/ISpan;
26372638
public static fun getTraceparent ()Lio/sentry/SentryTraceHeader;
2638-
public static fun hasScopes ()Z
26392639
public static fun init ()V
26402640
public static fun init (Lio/sentry/OptionsContainer;Lio/sentry/Sentry$OptionsConfiguration;)V
26412641
public static fun init (Lio/sentry/OptionsContainer;Lio/sentry/Sentry$OptionsConfiguration;Z)V

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

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)