Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
- Fix profilerId propagation ([#4833](https://github.com/getsentry/sentry-java/pull/4833))
- Fix profiling init for Spring and Spring Boot w Agent auto-init ([#4815](https://github.com/getsentry/sentry-java/pull/4815))
- Copy active span on scope clone ([#4878](https://github.com/getsentry/sentry-java/pull/4878))
- Avoid forking `rootScopes` for Reactor if current thread has NoOpScopes ([#4793](https://github.com/getsentry/sentry-java/pull/4793))
- This reduces the SDKs overhead by avoiding unnecessary scope forks

### Improvements

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public Object key() {

@Override
public IScopes getValue() {
return Sentry.getCurrentScopes();
return Sentry.getCurrentScopes(false);
}

@Override
Expand Down
1 change: 1 addition & 0 deletions sentry/api/sentry.api
Original file line number Diff line number Diff line change
Expand Up @@ -2631,6 +2631,7 @@ public final class io/sentry/Sentry {
public static fun getBaggage ()Lio/sentry/BaggageHeader;
public static fun getCurrentHub ()Lio/sentry/IHub;
public static fun getCurrentScopes ()Lio/sentry/IScopes;
public static fun getCurrentScopes (Z)Lio/sentry/IScopes;
public static fun getGlobalScope ()Lio/sentry/IScope;
public static fun getLastEventId ()Lio/sentry/protocol/SentryId;
public static fun getSpan ()Lio/sentry/ISpan;
Expand Down
23 changes: 20 additions & 3 deletions sentry/src/main/java/io/sentry/Sentry.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,16 +97,33 @@ private Sentry() {}
return new HubScopesWrapper(getCurrentScopes());
}

@ApiStatus.Internal // exposed for the coroutines integration in SentryContext
@ApiStatus.Internal
@SuppressWarnings("deprecation")
public static @NotNull IScopes getCurrentScopes() {
return getCurrentScopes(true);
}

/**
* Returns the current contexts scopes.
*
* @param ensureForked if true, forks root scopes in case there are no scopes for this context if
* false, returns NoOpScopes if there are no scopes for this context
* @return current scopes, a root scopes fork or NoopScopes
*/
@ApiStatus.Internal
@SuppressWarnings("deprecation")
public static @NotNull IScopes getCurrentScopes(final boolean ensureForked) {
if (globalHubMode) {
return rootScopes;
}
@Nullable IScopes scopes = getScopesStorage().get();
if (scopes == null || scopes.isNoOp()) {
scopes = rootScopes.forkedScopes("getCurrentScopes");
getScopesStorage().set(scopes);
if (!ensureForked) {
return NoOpScopes.getInstance();
} else {
scopes = rootScopes.forkedScopes("getCurrentScopes");
getScopesStorage().set(scopes);
}
}
return scopes;
}
Expand Down
Loading