Skip to content

Commit 30990f6

Browse files
authored
Hubs/Scopes Merge 3 - Replace IHub with IScopes in Android core (#3299)
* Introduce `IScopes` interface. * Replace `IHub` with `IScopes` in core * Replace `IHub` with `IScopes` in android core
1 parent ca5593e commit 30990f6

40 files changed

+511
-504
lines changed

sentry-android-core/api/sentry-android-core.api

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ public final class io/sentry/android/core/ActivityBreadcrumbsIntegration : andro
88
public fun onActivitySaveInstanceState (Landroid/app/Activity;Landroid/os/Bundle;)V
99
public fun onActivityStarted (Landroid/app/Activity;)V
1010
public fun onActivityStopped (Landroid/app/Activity;)V
11-
public fun register (Lio/sentry/IHub;Lio/sentry/SentryOptions;)V
11+
public fun register (Lio/sentry/IScopes;Lio/sentry/SentryOptions;)V
1212
}
1313

1414
public final class io/sentry/android/core/ActivityFramesTracker {
@@ -33,7 +33,7 @@ public final class io/sentry/android/core/ActivityLifecycleIntegration : android
3333
public fun onActivitySaveInstanceState (Landroid/app/Activity;Landroid/os/Bundle;)V
3434
public fun onActivityStarted (Landroid/app/Activity;)V
3535
public fun onActivityStopped (Landroid/app/Activity;)V
36-
public fun register (Lio/sentry/IHub;Lio/sentry/SentryOptions;)V
36+
public fun register (Lio/sentry/IScopes;Lio/sentry/SentryOptions;)V
3737
}
3838

3939
public final class io/sentry/android/core/AndroidCpuCollector : io/sentry/IPerformanceSnapshotCollector {
@@ -87,7 +87,7 @@ public class io/sentry/android/core/AndroidProfiler$ProfileStartData {
8787
public final class io/sentry/android/core/AnrIntegration : io/sentry/Integration, java/io/Closeable {
8888
public fun <init> (Landroid/content/Context;)V
8989
public fun close ()V
90-
public final fun register (Lio/sentry/IHub;Lio/sentry/SentryOptions;)V
90+
public final fun register (Lio/sentry/IScopes;Lio/sentry/SentryOptions;)V
9191
}
9292

9393
public final class io/sentry/android/core/AnrIntegrationFactory {
@@ -104,7 +104,7 @@ public final class io/sentry/android/core/AnrV2EventProcessor : io/sentry/Backfi
104104
public class io/sentry/android/core/AnrV2Integration : io/sentry/Integration, java/io/Closeable {
105105
public fun <init> (Landroid/content/Context;)V
106106
public fun close ()V
107-
public fun register (Lio/sentry/IHub;Lio/sentry/SentryOptions;)V
107+
public fun register (Lio/sentry/IScopes;Lio/sentry/SentryOptions;)V
108108
}
109109

110110
public final class io/sentry/android/core/AnrV2Integration$AnrV2Hint : io/sentry/hints/BlockingFlushHint, io/sentry/hints/AbnormalExit, io/sentry/hints/Backfillable {
@@ -123,13 +123,13 @@ public final class io/sentry/android/core/AppComponentsBreadcrumbsIntegration :
123123
public fun onConfigurationChanged (Landroid/content/res/Configuration;)V
124124
public fun onLowMemory ()V
125125
public fun onTrimMemory (I)V
126-
public fun register (Lio/sentry/IHub;Lio/sentry/SentryOptions;)V
126+
public fun register (Lio/sentry/IScopes;Lio/sentry/SentryOptions;)V
127127
}
128128

129129
public final class io/sentry/android/core/AppLifecycleIntegration : io/sentry/Integration, java/io/Closeable {
130130
public fun <init> ()V
131131
public fun close ()V
132-
public fun register (Lio/sentry/IHub;Lio/sentry/SentryOptions;)V
132+
public fun register (Lio/sentry/IScopes;Lio/sentry/SentryOptions;)V
133133
}
134134

135135
public final class io/sentry/android/core/AppState {
@@ -177,7 +177,7 @@ public final class io/sentry/android/core/CurrentActivityIntegration : android/a
177177
public fun onActivitySaveInstanceState (Landroid/app/Activity;Landroid/os/Bundle;)V
178178
public fun onActivityStarted (Landroid/app/Activity;)V
179179
public fun onActivityStopped (Landroid/app/Activity;)V
180-
public fun register (Lio/sentry/IHub;Lio/sentry/SentryOptions;)V
180+
public fun register (Lio/sentry/IScopes;Lio/sentry/SentryOptions;)V
181181
}
182182

183183
public final class io/sentry/android/core/DeviceInfoUtil {
@@ -193,7 +193,7 @@ public abstract class io/sentry/android/core/EnvelopeFileObserverIntegration : i
193193
public fun <init> ()V
194194
public fun close ()V
195195
public static fun getOutboxFileObserver ()Lio/sentry/android/core/EnvelopeFileObserverIntegration;
196-
public final fun register (Lio/sentry/IHub;Lio/sentry/SentryOptions;)V
196+
public final fun register (Lio/sentry/IScopes;Lio/sentry/SentryOptions;)V
197197
}
198198

199199
public abstract interface class io/sentry/android/core/IDebugImagesLoader {
@@ -219,19 +219,19 @@ public final class io/sentry/android/core/NdkIntegration : io/sentry/Integration
219219
public static final field SENTRY_NDK_CLASS_NAME Ljava/lang/String;
220220
public fun <init> (Ljava/lang/Class;)V
221221
public fun close ()V
222-
public final fun register (Lio/sentry/IHub;Lio/sentry/SentryOptions;)V
222+
public final fun register (Lio/sentry/IScopes;Lio/sentry/SentryOptions;)V
223223
}
224224

225225
public final class io/sentry/android/core/NetworkBreadcrumbsIntegration : io/sentry/Integration, java/io/Closeable {
226226
public fun <init> (Landroid/content/Context;Lio/sentry/android/core/BuildInfoProvider;Lio/sentry/ILogger;)V
227227
public fun close ()V
228-
public fun register (Lio/sentry/IHub;Lio/sentry/SentryOptions;)V
228+
public fun register (Lio/sentry/IScopes;Lio/sentry/SentryOptions;)V
229229
}
230230

231231
public final class io/sentry/android/core/PhoneStateBreadcrumbsIntegration : io/sentry/Integration, java/io/Closeable {
232232
public fun <init> (Landroid/content/Context;)V
233233
public fun close ()V
234-
public fun register (Lio/sentry/IHub;Lio/sentry/SentryOptions;)V
234+
public fun register (Lio/sentry/IScopes;Lio/sentry/SentryOptions;)V
235235
}
236236

237237
public final class io/sentry/android/core/ScreenshotEventProcessor : io/sentry/EventProcessor {
@@ -360,15 +360,15 @@ public final class io/sentry/android/core/SystemEventsBreadcrumbsIntegration : i
360360
public fun <init> (Landroid/content/Context;)V
361361
public fun <init> (Landroid/content/Context;Ljava/util/List;)V
362362
public fun close ()V
363-
public fun register (Lio/sentry/IHub;Lio/sentry/SentryOptions;)V
363+
public fun register (Lio/sentry/IScopes;Lio/sentry/SentryOptions;)V
364364
}
365365

366366
public final class io/sentry/android/core/TempSensorBreadcrumbsIntegration : android/hardware/SensorEventListener, io/sentry/Integration, java/io/Closeable {
367367
public fun <init> (Landroid/content/Context;)V
368368
public fun close ()V
369369
public fun onAccuracyChanged (Landroid/hardware/Sensor;I)V
370370
public fun onSensorChanged (Landroid/hardware/SensorEvent;)V
371-
public fun register (Lio/sentry/IHub;Lio/sentry/SentryOptions;)V
371+
public fun register (Lio/sentry/IScopes;Lio/sentry/SentryOptions;)V
372372
}
373373

374374
public final class io/sentry/android/core/UserInteractionIntegration : android/app/Application$ActivityLifecycleCallbacks, io/sentry/Integration, java/io/Closeable {
@@ -381,7 +381,7 @@ public final class io/sentry/android/core/UserInteractionIntegration : android/a
381381
public fun onActivitySaveInstanceState (Landroid/app/Activity;Landroid/os/Bundle;)V
382382
public fun onActivityStarted (Landroid/app/Activity;)V
383383
public fun onActivityStopped (Landroid/app/Activity;)V
384-
public fun register (Lio/sentry/IHub;Lio/sentry/SentryOptions;)V
384+
public fun register (Lio/sentry/IScopes;Lio/sentry/SentryOptions;)V
385385
}
386386

387387
public final class io/sentry/android/core/ViewHierarchyEventProcessor : io/sentry/EventProcessor {

sentry-android-core/src/main/java/io/sentry/android/core/ActivityBreadcrumbsIntegration.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import android.os.Bundle;
99
import io.sentry.Breadcrumb;
1010
import io.sentry.Hint;
11-
import io.sentry.IHub;
11+
import io.sentry.IScopes;
1212
import io.sentry.Integration;
1313
import io.sentry.SentryLevel;
1414
import io.sentry.SentryOptions;
@@ -23,21 +23,21 @@ public final class ActivityBreadcrumbsIntegration
2323
implements Integration, Closeable, Application.ActivityLifecycleCallbacks {
2424

2525
private final @NotNull Application application;
26-
private @Nullable IHub hub;
26+
private @Nullable IScopes scopes;
2727
private boolean enabled;
2828

2929
public ActivityBreadcrumbsIntegration(final @NotNull Application application) {
3030
this.application = Objects.requireNonNull(application, "Application is required");
3131
}
3232

3333
@Override
34-
public void register(final @NotNull IHub hub, final @NotNull SentryOptions options) {
34+
public void register(final @NotNull IScopes scopes, final @NotNull SentryOptions options) {
3535
final SentryAndroidOptions androidOptions =
3636
Objects.requireNonNull(
3737
(options instanceof SentryAndroidOptions) ? (SentryAndroidOptions) options : null,
3838
"SentryAndroidOptions is required");
3939

40-
this.hub = Objects.requireNonNull(hub, "Hub is required");
40+
this.scopes = Objects.requireNonNull(scopes, "Scopes are required");
4141
this.enabled = androidOptions.isEnableActivityLifecycleBreadcrumbs();
4242
options
4343
.getLogger()
@@ -54,8 +54,9 @@ public void register(final @NotNull IHub hub, final @NotNull SentryOptions optio
5454
public void close() throws IOException {
5555
if (enabled) {
5656
application.unregisterActivityLifecycleCallbacks(this);
57-
if (hub != null) {
58-
hub.getOptions()
57+
if (scopes != null) {
58+
scopes
59+
.getOptions()
5960
.getLogger()
6061
.log(SentryLevel.DEBUG, "ActivityBreadcrumbsIntegration removed.");
6162
}
@@ -100,7 +101,7 @@ public synchronized void onActivityDestroyed(final @NotNull Activity activity) {
100101
}
101102

102103
private void addBreadcrumb(final @NotNull Activity activity, final @NotNull String state) {
103-
if (hub == null) {
104+
if (scopes == null) {
104105
return;
105106
}
106107

@@ -114,7 +115,7 @@ private void addBreadcrumb(final @NotNull Activity activity, final @NotNull Stri
114115
final Hint hint = new Hint();
115116
hint.set(ANDROID_ACTIVITY, activity);
116117

117-
hub.addBreadcrumb(breadcrumb, hint);
118+
scopes.addBreadcrumb(breadcrumb, hint);
118119
}
119120

120121
private @NotNull String getActivityName(final @NotNull Activity activity) {

sentry-android-core/src/main/java/io/sentry/android/core/ActivityLifecycleIntegration.java

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
import android.view.View;
1313
import androidx.annotation.NonNull;
1414
import io.sentry.FullyDisplayedReporter;
15-
import io.sentry.IHub;
1615
import io.sentry.IScope;
16+
import io.sentry.IScopes;
1717
import io.sentry.ISpan;
1818
import io.sentry.ITransaction;
1919
import io.sentry.Instrumenter;
@@ -60,7 +60,7 @@ public final class ActivityLifecycleIntegration
6060

6161
private final @NotNull Application application;
6262
private final @NotNull BuildInfoProvider buildInfoProvider;
63-
private @Nullable IHub hub;
63+
private @Nullable IScopes scopes;
6464
private @Nullable SentryAndroidOptions options;
6565

6666
private boolean performanceEnabled = false;
@@ -102,13 +102,13 @@ public ActivityLifecycleIntegration(
102102
}
103103

104104
@Override
105-
public void register(final @NotNull IHub hub, final @NotNull SentryOptions options) {
105+
public void register(final @NotNull IScopes scopes, final @NotNull SentryOptions options) {
106106
this.options =
107107
Objects.requireNonNull(
108108
(options instanceof SentryAndroidOptions) ? (SentryAndroidOptions) options : null,
109109
"SentryAndroidOptions is required");
110110

111-
this.hub = Objects.requireNonNull(hub, "Hub is required");
111+
this.scopes = Objects.requireNonNull(scopes, "Scopes are required");
112112

113113
performanceEnabled = isPerformanceEnabled(this.options);
114114
fullyDisplayedReporter = this.options.getFullyDisplayedReporter();
@@ -150,10 +150,10 @@ private void stopPreviousTransactions() {
150150

151151
private void startTracing(final @NotNull Activity activity) {
152152
WeakReference<Activity> weakActivity = new WeakReference<>(activity);
153-
if (hub != null && !isRunningTransactionOrTrace(activity)) {
153+
if (scopes != null && !isRunningTransactionOrTrace(activity)) {
154154
if (!performanceEnabled) {
155155
activitiesWithOngoingTransactions.put(activity, NoOpTransaction.getInstance());
156-
TracingUtils.startNewTrace(hub);
156+
TracingUtils.startNewTrace(scopes);
157157
} else {
158158
// as we allow a single transaction running on the bound Scope, we finish the previous ones
159159
stopPreviousTransactions();
@@ -225,7 +225,7 @@ private void startTracing(final @NotNull Activity activity) {
225225

226226
// we can only bind to the scope if there's no running transaction
227227
ITransaction transaction =
228-
hub.startTransaction(
228+
scopes.startTransaction(
229229
new TransactionContext(
230230
activityName,
231231
TransactionNameSource.COMPONENT,
@@ -278,7 +278,7 @@ private void startTracing(final @NotNull Activity activity) {
278278
}
279279

280280
// lets bind to the scope so other integrations can pick it up
281-
hub.configureScope(
281+
scopes.configureScope(
282282
scope -> {
283283
applyScope(scope, transaction);
284284
});
@@ -356,10 +356,10 @@ private void finishTransaction(
356356
status = SpanStatus.OK;
357357
}
358358
transaction.finish(status);
359-
if (hub != null) {
359+
if (scopes != null) {
360360
// make sure to remove the transaction from scope, as it may contain running children,
361361
// therefore `finish` method will not remove it from scope
362-
hub.configureScope(
362+
scopes.configureScope(
363363
scope -> {
364364
clearScope(scope, transaction);
365365
});
@@ -371,9 +371,9 @@ private void finishTransaction(
371371
public synchronized void onActivityCreated(
372372
final @NotNull Activity activity, final @Nullable Bundle savedInstanceState) {
373373
setColdStart(savedInstanceState);
374-
if (hub != null) {
374+
if (scopes != null) {
375375
final @Nullable String activityClassName = ClassUtil.getClassName(activity);
376-
hub.configureScope(scope -> scope.setScreen(activityClassName));
376+
scopes.configureScope(scope -> scope.setScreen(activityClassName));
377377
}
378378
startTracing(activity);
379379
final @Nullable ISpan ttfdSpan = ttfdSpanMap.get(activity);
@@ -429,10 +429,10 @@ public void onActivityPrePaused(@NonNull Activity activity) {
429429
// well
430430
// this ensures any newly launched activity will not use the app start timestamp as txn start
431431
firstActivityCreated = true;
432-
if (hub == null) {
432+
if (scopes == null) {
433433
lastPausedTime = AndroidDateUtils.getCurrentSentryDateTime();
434434
} else {
435-
lastPausedTime = hub.getOptions().getDateProvider().now();
435+
lastPausedTime = scopes.getOptions().getDateProvider().now();
436436
}
437437
}
438438
}
@@ -445,10 +445,10 @@ public synchronized void onActivityPaused(final @NotNull Activity activity) {
445445
// well
446446
// this ensures any newly launched activity will not use the app start timestamp as txn start
447447
firstActivityCreated = true;
448-
if (hub == null) {
448+
if (scopes == null) {
449449
lastPausedTime = AndroidDateUtils.getCurrentSentryDateTime();
450450
} else {
451-
lastPausedTime = hub.getOptions().getDateProvider().now();
451+
lastPausedTime = scopes.getOptions().getDateProvider().now();
452452
}
453453
}
454454
}

sentry-android-core/src/main/java/io/sentry/android/core/AndroidTransactionProfiler.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@
99
import android.os.Build;
1010
import android.os.Process;
1111
import android.os.SystemClock;
12-
import io.sentry.HubAdapter;
13-
import io.sentry.IHub;
1412
import io.sentry.ILogger;
13+
import io.sentry.IScopes;
1514
import io.sentry.ISentryExecutorService;
1615
import io.sentry.ITransaction;
1716
import io.sentry.ITransactionProfiler;
1817
import io.sentry.PerformanceCollectionData;
1918
import io.sentry.ProfilingTraceData;
2019
import io.sentry.ProfilingTransactionData;
20+
import io.sentry.ScopesAdapter;
2121
import io.sentry.SentryLevel;
2222
import io.sentry.SentryOptions;
2323
import io.sentry.android.core.internal.util.CpuInfoUtils;
@@ -46,16 +46,16 @@ final class AndroidTransactionProfiler implements ITransactionProfiler {
4646
private long profileStartCpuMillis;
4747

4848
/**
49-
* @deprecated please use a constructor that doesn't takes a {@link IHub} instead, as it would be
50-
* ignored anyway.
49+
* @deprecated please use a constructor that doesn't takes a {@link IScopes} instead, as it would
50+
* be ignored anyway.
5151
*/
5252
@Deprecated
5353
public AndroidTransactionProfiler(
5454
final @NotNull Context context,
5555
final @NotNull SentryAndroidOptions sentryAndroidOptions,
5656
final @NotNull BuildInfoProvider buildInfoProvider,
5757
final @NotNull SentryFrameMetricsCollector frameMetricsCollector,
58-
final @NotNull IHub hub) {
58+
final @NotNull IScopes scopes) {
5959
this(context, sentryAndroidOptions, buildInfoProvider, frameMetricsCollector);
6060
}
6161

@@ -311,7 +311,7 @@ public void close() {
311311
currentProfilingTransactionData.getTraceId(),
312312
true,
313313
null,
314-
HubAdapter.getInstance().getOptions());
314+
ScopesAdapter.getInstance().getOptions());
315315
} else if (transactionsCounter != 0) {
316316
// in case the app start profiling is running, and it's not bound to a transaction, we still
317317
// stop profiling, but we also have to manually update the counter.

0 commit comments

Comments
 (0)