Skip to content

Commit db9a241

Browse files
authored
Merge branch 'main' into feat/support-span-sentry-item-type
2 parents 39664b5 + d872fbc commit db9a241

File tree

4 files changed

+27
-4
lines changed

4 files changed

+27
-4
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@
66

77
- Support `span` envelope item type ([#4935](https://github.com/getsentry/sentry-java/pull/4935))
88

9+
### Improvements
10+
11+
- Avoid forking `rootScopes` for Reactor if current thread has `NoOpScopes` ([#4793](https://github.com/getsentry/sentry-java/pull/4793))
12+
- This reduces the SDKs overhead by avoiding unnecessary scope forks
13+
914
## 8.27.1
1015

1116
### Fixes

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

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

1717
@Override
1818
public IScopes getValue() {
19-
return Sentry.getCurrentScopes();
19+
return Sentry.getCurrentScopes(false);
2020
}
2121

2222
@Override

sentry/api/sentry.api

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2631,6 +2631,7 @@ 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;

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

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,16 +97,33 @@ 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
}

0 commit comments

Comments
 (0)