Skip to content

Commit 6c284c5

Browse files
authored
Merge branch 'main' into markushi/fix/undefined-behavior
2 parents b69da2d + d872fbc commit 6c284c5

File tree

6 files changed

+34
-7
lines changed

6 files changed

+34
-7
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22

33
## Unreleased
44

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

714
- Do not log if `sentry.properties` in rundir has not been found ([#4929](https://github.com/getsentry/sentry-java/pull/4929))

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ org.jetbrains.dokka.experimental.gradle.pluginMode=V2Enabled
1111
android.useAndroidX=true
1212

1313
# Release information
14-
versionName=8.27.0
14+
versionName=8.27.1
1515

1616
# Override the SDK name on native crashes on Android
1717
sentryAndroidSdkName=sentry.native.android

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
}

sentry/src/main/java/io/sentry/util/InitUtil.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,12 +108,14 @@ public static IProfileConverter initializeProfileConverter(@NotNull SentryOption
108108
}
109109

110110
private static boolean shouldInitializeProfiler(@NotNull SentryOptions options) {
111-
return options.isContinuousProfilingEnabled()
111+
return Platform.isJvm()
112+
&& options.isContinuousProfilingEnabled()
112113
&& options.getContinuousProfiler() instanceof NoOpContinuousProfiler;
113114
}
114115

115116
private static boolean shouldInitializeProfileConverter(@NotNull SentryOptions options) {
116-
return options.isContinuousProfilingEnabled()
117+
return Platform.isJvm()
118+
&& options.isContinuousProfilingEnabled()
117119
&& options.getProfilerConverter() instanceof NoOpProfileConverter;
118120
}
119121

0 commit comments

Comments
 (0)