Skip to content

Commit 3f8dd6c

Browse files
adinauerclaude
andauthored
ref(core): Remove deprecated Hub APIs (#6223)
* ref(core): Remove deprecated Hub APIs Remove the Hub compatibility layer and migration aliases now that IScopes and Scopes are the supported APIs. Refs GH-3069 Co-Authored-By: Claude <noreply@anthropic.com> * changelog --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent c406939 commit 3f8dd6c

27 files changed

Lines changed: 15 additions & 2080 deletions

File tree

‎.cursor/rules/api.mdc‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,15 +63,13 @@ When adding a new method that users can call (e.g. a new scope operation), these
6363
7. `NoOpScope` — no-op stub for `IScope`
6464
8. `NoOpScopes` — no-op stub for `IScopes`
6565
9. `ScopesAdapter` — delegates to `Sentry` static API
66-
10. `HubAdapter` — deprecated bridge from old `IHub` API
67-
11. `HubScopesWrapper` — wraps `IScopes` as `IHub`
6866

6967
### Serialization (if the data is sent to Sentry)
70-
12. Add serialization/deserialization in the relevant data class or create a new one implementing `JsonSerializable` and `JsonDeserializer`
68+
10. Add serialization/deserialization in the relevant data class or create a new one implementing `JsonSerializable` and `JsonDeserializer`
7169

7270
### Tests
73-
13. Write tests for all implementations, especially `Scope`, `Scopes`, `SentryTest`, and any new data classes
74-
14. No-op classes typically don't need separate tests unless they have non-trivial logic
71+
11. Write tests for all implementations, especially `Scope`, `Scopes`, `SentryTest`, and any new data classes
72+
12. No-op classes typically don't need separate tests unless they have non-trivial logic
7573

7674
## Protocol / Data Model Classes
7775

‎.cursor/rules/scopes.mdc‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ Data itself is stored on `Scope` instances.
1414
## `Hub`
1515

1616
Up until major version 7 of the Java SDK the `IHub` interface was a central part of the SDK.
17-
In major version 8 we replaced the `IHub` interface with `IScopes`. `IHub` has been deprecated.
18-
While there is some bridging code in place to allow for easier migration, we are planning to remove it in an upcoming major.
17+
In major version 8 we replaced the `IHub` interface with `IScopes` and deprecated the Hub compatibility APIs.
18+
Those compatibility APIs were removed in major version 9.
1919

2020
## Scope Types
2121

@@ -79,7 +79,7 @@ There were several implementations of the `IHub` interface:
7979
`HubAdapter` has been replaced by `ScopesAdapter`
8080
`Hub.clone` should be replaced by using `pushScope` or `pushIsolationScope`
8181
`Sentry.getCurrentHub` has been replaced by `Sentry.getCurrentScopes`
82-
`Sentry.popScope` has been deprecated. Instead `close` should be called on the `ISentryLifecycleToken` returned e.g. by `pushScope`. This can also be done in a `try-with-resource` block.
82+
`Sentry.popScope` was deprecated in version 8 and removed in version 9. Instead, `close` should be called on the `ISentryLifecycleToken` returned e.g. by `pushScope`. This can also be done in a `try-with-resources` block.
8383

8484
## `globalHubMode`
8585
The SDK has a `globalHubMode` option which affects forking behaviour of the SDK.
@@ -93,8 +93,8 @@ For JVM Backend applications (servers) we discourage enabling `globalHubMode` si
9393
If `globalHubMode` is enabled, the SDK avoids forking scopes _implicitly_.
9494

9595
This means, retrieving current scopes on a thread where specific scopes do not exist yet for the thread, the root scopes are not forked but returned directly.
96-
`Sentry.pushScope`, `Sentry.pushIsolationScope` and `Sentry.popScope` are no-ops.
97-
They are unbalanced API: the caller may never restore the previous scopes, or restore them on a different thread, which would corrupt the globally shared scopes.
96+
`Sentry.pushScope` and `Sentry.pushIsolationScope` are no-ops and return no-op lifecycle tokens.
97+
Implicit forking is suppressed because callers could otherwise fail to restore the previous scopes, or restore them on a different thread, which would corrupt the globally shared scopes.
9898

9999
`Sentry.withScope` and `Sentry.withIsolationScope` do fork, also when `globalHubMode` is enabled.
100100
They are balanced by construction and always restore the previous scopes before returning, so they cannot corrupt the shared scopes.

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
- `Sentry.showUserFeedbackDialog(...)`: use `Sentry.feedback().show(...)` instead
1111
- Android: `SentryUserFeedbackDialog`: use `SentryUserFeedbackForm` instead
1212
- Android: the `SentryUserFeedbackButton` view and composable: call `Sentry.feedback().show()` from your own button instead
13+
- Remove deprecated Hub compatibility APIs in favor of `IScopes` and `Scopes` ([#6223](https://github.com/getsentry/sentry-java/pull/6223))
1314
- Remove the aggregate Sentry Logs and Metrics enable options from all configuration surfaces:
1415
- Java API: `options.getLogs().setEnabled(...)` and `options.getMetrics().setEnabled(...)`
1516
- Properties files: `logs.enabled` and `metrics.enabled`

‎sentry-android-core/src/test/java/io/sentry/android/core/SentryAndroidTest.kt‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ class SentryAndroidTest {
401401
fun `init starts session replay if app is in foreground`() {
402402
initSentryWithForegroundImportance(true) { _ ->
403403
Shadows.shadowOf(Looper.getMainLooper()).idle()
404-
assertTrue(Sentry.getCurrentHub().options.replayController.isRecording())
404+
assertTrue(Sentry.getCurrentScopes().options.replayController.isRecording())
405405
}
406406
}
407407

@@ -410,7 +410,7 @@ class SentryAndroidTest {
410410
fun `init does not start session replay if the app is in background`() {
411411
initSentryWithForegroundImportance(false) { _ ->
412412
Shadows.shadowOf(Looper.getMainLooper()).idle()
413-
assertFalse(Sentry.getCurrentHub().options.replayController.isRecording())
413+
assertFalse(Sentry.getCurrentScopes().options.replayController.isRecording())
414414
}
415415
}
416416

‎sentry-android-integration-tests/sentry-uitest-android-critical/src/main/java/io/sentry/uitest/android/critical/MainActivity.kt‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ class MainActivity : ComponentActivity() {
3636

3737
super.onCreate(savedInstanceState)
3838
val outboxPath =
39-
Sentry.getCurrentHub().options.outboxPath ?: throw RuntimeException("Outbox path is not set.")
39+
Sentry.getCurrentScopes().options.outboxPath
40+
?: throw RuntimeException("Outbox path is not set.")
4041

4142
requestPermissionLauncher =
4243
registerForActivityResult(ActivityResultContracts.RequestPermission()) { isGranted: Boolean ->

‎sentry-graphql-core/api/sentry-graphql-core.api‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ public final class io/sentry/graphql/ExceptionReporter {
1111
public final class io/sentry/graphql/ExceptionReporter$ExceptionDetails {
1212
public fun <init> (Lio/sentry/IScopes;Lgraphql/execution/instrumentation/parameters/InstrumentationExecutionParameters;Z)V
1313
public fun <init> (Lio/sentry/IScopes;Lgraphql/schema/DataFetchingEnvironment;Z)V
14-
public fun getHub ()Lio/sentry/IScopes;
1514
public fun getQuery ()Ljava/lang/String;
1615
public fun getScopes ()Lio/sentry/IScopes;
1716
public fun getVariables ()Ljava/util/Map;

‎sentry-graphql-core/src/main/java/io/sentry/graphql/ExceptionReporter.java‎

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -163,14 +163,6 @@ public boolean isSubscription() {
163163
return isSubscription;
164164
}
165165

166-
/**
167-
* @deprecated please use {@link ExceptionDetails#getScopes()} instead.
168-
*/
169-
@Deprecated
170-
public @NotNull IScopes getHub() {
171-
return scopes;
172-
}
173-
174166
public @NotNull IScopes getScopes() {
175167
return scopes;
176168
}

‎sentry-spring-7/api/sentry-spring-7.api‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,6 @@ public final class io/sentry/spring7/tracing/TransactionNameWithSource {
381381
}
382382

383383
public abstract class io/sentry/spring7/webflux/AbstractSentryWebFilter : org/springframework/web/server/WebFilter {
384-
public static final field SENTRY_HUB_KEY Ljava/lang/String;
385384
public static final field SENTRY_SCOPES_KEY Ljava/lang/String;
386385
public fun <init> (Lio/sentry/IScopes;)V
387386
protected fun doFinally (Lorg/springframework/web/server/ServerWebExchange;Lio/sentry/IScopes;Lio/sentry/ITransaction;)V

‎sentry-spring-7/src/main/java/io/sentry/spring7/webflux/AbstractSentryWebFilter.java‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,6 @@ public abstract class AbstractSentryWebFilter implements WebFilter {
3737
private final @NotNull SentryRequestResolver sentryRequestResolver;
3838
public static final String SENTRY_SCOPES_KEY = "sentry-scopes";
3939

40-
/**
41-
* @deprecated please use {@link AbstractSentryWebFilter#SENTRY_SCOPES_KEY} instead.
42-
*/
43-
@Deprecated public static final String SENTRY_HUB_KEY = SENTRY_SCOPES_KEY;
44-
4540
private static final String TRANSACTION_OP = "http.server";
4641

4742
public AbstractSentryWebFilter(final @NotNull IScopes scopes) {

‎sentry-spring-jakarta/api/sentry-spring-jakarta.api‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,6 @@ public final class io/sentry/spring/jakarta/tracing/TransactionNameWithSource {
381381
}
382382

383383
public abstract class io/sentry/spring/jakarta/webflux/AbstractSentryWebFilter : org/springframework/web/server/WebFilter {
384-
public static final field SENTRY_HUB_KEY Ljava/lang/String;
385384
public static final field SENTRY_SCOPES_KEY Ljava/lang/String;
386385
public fun <init> (Lio/sentry/IScopes;)V
387386
protected fun doFinally (Lorg/springframework/web/server/ServerWebExchange;Lio/sentry/IScopes;Lio/sentry/ITransaction;)V

0 commit comments

Comments
 (0)