Skip to content

Commit 32f1546

Browse files
committed
move from hub to scopes
1 parent 938923d commit 32f1546

File tree

31 files changed

+219
-269
lines changed

31 files changed

+219
-269
lines changed

sentry-android-core/src/test/java/io/sentry/android/core/ActivityLifecycleIntegrationTest.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -766,7 +766,7 @@ class ActivityLifecycleIntegrationTest {
766766
fun `When firstActivityCreated is true and no app start time is set, default to onActivityCreated time`() {
767767
val sut = fixture.getSut()
768768
fixture.options.tracesSampleRate = 1.0
769-
sut.register(fixture.hub, fixture.options)
769+
sut.register(fixture.scopes, fixture.options)
770770

771771
// usually set by SentryPerformanceProvider
772772
val date = SentryNanotimeDate(Date(1), 0)
@@ -777,7 +777,7 @@ class ActivityLifecycleIntegrationTest {
777777
fixture.options.dateProvider = SentryDateProvider { date2 }
778778
sut.onActivityCreated(activity, fixture.bundle)
779779

780-
verify(fixture.hub).startTransaction(
780+
verify(fixture.scopes).startTransaction(
781781
any(),
782782
check<TransactionOptions> {
783783
assertEquals(date2.nanoTimestamp(), it.startTimestamp!!.nanoTimestamp())
@@ -974,7 +974,7 @@ class ActivityLifecycleIntegrationTest {
974974
fun `When firstActivityCreated is true and app started more than 1 minute ago, app start spans are dropped`() {
975975
val sut = fixture.getSut()
976976
fixture.options.tracesSampleRate = 1.0
977-
sut.register(fixture.hub, fixture.options)
977+
sut.register(fixture.scopes, fixture.options)
978978

979979
val date = SentryNanotimeDate(Date(1), 0)
980980
val duration = TimeUnit.MINUTES.toMillis(1) + 2
@@ -996,7 +996,7 @@ class ActivityLifecycleIntegrationTest {
996996
val sut = fixture.getSut()
997997
AppStartMetrics.getInstance().isAppLaunchedInForeground = false
998998
fixture.options.tracesSampleRate = 1.0
999-
sut.register(fixture.hub, fixture.options)
999+
sut.register(fixture.scopes, fixture.options)
10001000

10011001
val date = SentryNanotimeDate(Date(1), 0)
10021002
setAppStartTime(date)

sentry-android-core/src/test/java/io/sentry/android/core/PerformanceAndroidEventProcessorTest.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ class PerformanceAndroidEventProcessorTest {
322322
// when an activity transaction is created
323323
val sut = fixture.getSut(enablePerformanceV2 = true)
324324
val context = TransactionContext("Activity", UI_LOAD_OP)
325-
val tracer = SentryTracer(context, fixture.hub)
325+
val tracer = SentryTracer(context, fixture.scopes)
326326
var tr = SentryTransaction(tracer)
327327

328328
// and it contains an app.start.cold span
@@ -376,7 +376,7 @@ class PerformanceAndroidEventProcessorTest {
376376
// when an activity transaction is created
377377
val sut = fixture.getSut(enablePerformanceV2 = true)
378378
val context = TransactionContext("Activity", UI_LOAD_OP)
379-
val tracer = SentryTracer(context, fixture.hub)
379+
val tracer = SentryTracer(context, fixture.scopes)
380380
var tr = SentryTransaction(tracer)
381381

382382
// and it contains an app.start.cold span

sentry-android-core/src/test/java/io/sentry/android/core/SystemEventsBreadcrumbsIntegrationTest.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ class SystemEventsBreadcrumbsIntegrationTest {
120120
fun `handles battery changes`() {
121121
val sut = fixture.getSut()
122122

123-
sut.register(fixture.hub, fixture.options)
123+
sut.register(fixture.scopes, fixture.options)
124124
val intent = Intent().apply {
125125
action = Intent.ACTION_BATTERY_CHANGED
126126
putExtra(BatteryManager.EXTRA_LEVEL, 75)
@@ -129,7 +129,7 @@ class SystemEventsBreadcrumbsIntegrationTest {
129129
}
130130
sut.receiver!!.onReceive(fixture.context, intent)
131131

132-
verify(fixture.hub).addBreadcrumb(
132+
verify(fixture.scopes).addBreadcrumb(
133133
check<Breadcrumb> {
134134
assertEquals("device.event", it.category)
135135
assertEquals("system", it.type)
@@ -145,7 +145,7 @@ class SystemEventsBreadcrumbsIntegrationTest {
145145
fun `battery changes are debounced`() {
146146
val sut = fixture.getSut()
147147

148-
sut.register(fixture.hub, fixture.options)
148+
sut.register(fixture.scopes, fixture.options)
149149
val intent1 = Intent().apply {
150150
action = Intent.ACTION_BATTERY_CHANGED
151151
putExtra(BatteryManager.EXTRA_LEVEL, 80)
@@ -161,14 +161,14 @@ class SystemEventsBreadcrumbsIntegrationTest {
161161
sut.receiver!!.onReceive(fixture.context, intent2)
162162

163163
// should only add the first crumb
164-
verify(fixture.hub).addBreadcrumb(
164+
verify(fixture.scopes).addBreadcrumb(
165165
check<Breadcrumb> {
166166
assertEquals(it.data["level"], 80f)
167167
assertEquals(it.data["charging"], false)
168168
},
169169
anyOrNull()
170170
)
171-
verifyNoMoreInteractions(fixture.hub)
171+
verifyNoMoreInteractions(fixture.scopes)
172172
}
173173

174174
@Test

sentry-android-fragment/src/main/java/io/sentry/android/fragment/SentryFragmentLifecycleCallbacks.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ class SentryFragmentLifecycleCallbacks(
8181
// we only start the tracing for the fragment if the fragment has been added to its activity
8282
// and not only to the backstack
8383
if (fragment.isAdded) {
84-
if (hub.options.isEnableScreenTracking) {
85-
hub.configureScope { it.screen = getFragmentName(fragment) }
84+
if (scopes.options.isEnableScreenTracking) {
85+
scopes.configureScope { it.screen = getFragmentName(fragment) }
8686
}
8787
startTracing(fragment)
8888
}

sentry-android-navigation/src/main/java/io/sentry/android/navigation/SentryNavigationListener.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ class SentryNavigationListener @JvmOverloads constructor(
182182
val name = route ?: try {
183183
context.resources.getResourceEntryName(id)
184184
} catch (e: NotFoundException) {
185-
hub.options.logger.log(
185+
scopes.options.logger.log(
186186
DEBUG,
187187
"Destination id cannot be retrieved from Resources, no transaction captured."
188188
)

sentry-android-replay/api/sentry-android-replay.api

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public final class io/sentry/android/replay/ReplayIntegration : android/content/
6565
public fun onScreenshotRecorded (Ljava/io/File;J)V
6666
public fun onTouchEvent (Landroid/view/MotionEvent;)V
6767
public fun pause ()V
68-
public fun register (Lio/sentry/IHub;Lio/sentry/SentryOptions;)V
68+
public fun register (Lio/sentry/IScopes;Lio/sentry/SentryOptions;)V
6969
public fun resume ()V
7070
public fun setBreadcrumbConverter (Lio/sentry/ReplayBreadcrumbConverter;)V
7171
public fun start ()V

sentry-android-replay/src/main/java/io/sentry/android/replay/ReplayIntegration.kt

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import android.graphics.Bitmap
77
import android.os.Build
88
import android.view.MotionEvent
99
import io.sentry.Breadcrumb
10-
import io.sentry.IHub
10+
import io.sentry.IScopes
1111
import io.sentry.Integration
1212
import io.sentry.NoOpReplayBreadcrumbConverter
1313
import io.sentry.ReplayBreadcrumbConverter
@@ -74,7 +74,7 @@ public class ReplayIntegration(
7474
}
7575

7676
private lateinit var options: SentryOptions
77-
private var hub: IHub? = null
77+
private var scopes: IScopes? = null
7878
private var recorder: Recorder? = null
7979
private var gestureRecorder: GestureRecorder? = null
8080
private val random by lazy { SecureRandom() }
@@ -92,7 +92,7 @@ public class ReplayIntegration(
9292

9393
private lateinit var recorderConfig: ScreenshotRecorderConfig
9494

95-
override fun register(hub: IHub, options: SentryOptions) {
95+
override fun register(scopes: IScopes, options: SentryOptions) {
9696
this.options = options
9797

9898
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
@@ -107,7 +107,7 @@ public class ReplayIntegration(
107107
return
108108
}
109109

110-
this.hub = hub
110+
this.scopes = scopes
111111
recorder = recorderProvider?.invoke() ?: WindowRecorder(options, this, mainLooperHandler)
112112
gestureRecorder = gestureRecorderProvider?.invoke() ?: GestureRecorder(options, this)
113113
isEnabled.set(true)
@@ -149,9 +149,9 @@ public class ReplayIntegration(
149149

150150
recorderConfig = recorderConfigProvider?.invoke(false) ?: ScreenshotRecorderConfig.from(context, options.experimental.sessionReplay)
151151
captureStrategy = replayCaptureStrategyProvider?.invoke(isFullSession) ?: if (isFullSession) {
152-
SessionCaptureStrategy(options, hub, dateProvider, replayCacheProvider = replayCacheProvider)
152+
SessionCaptureStrategy(options, scopes, dateProvider, replayCacheProvider = replayCacheProvider)
153153
} else {
154-
BufferCaptureStrategy(options, hub, dateProvider, random, replayCacheProvider = replayCacheProvider)
154+
BufferCaptureStrategy(options, scopes, dateProvider, random, replayCacheProvider = replayCacheProvider)
155155
}
156156

157157
captureStrategy?.start(recorderConfig)
@@ -218,7 +218,7 @@ public class ReplayIntegration(
218218

219219
override fun onScreenshotRecorded(bitmap: Bitmap) {
220220
var screen: String? = null
221-
hub?.configureScope { screen = it.screen?.substringAfterLast('.') }
221+
scopes?.configureScope { screen = it.screen?.substringAfterLast('.') }
222222
captureStrategy?.onScreenshotRecorded(bitmap) { frameTimeStamp ->
223223
addFrame(bitmap, frameTimeStamp, screen)
224224
}
@@ -313,7 +313,7 @@ public class ReplayIntegration(
313313
}
314314
val breadcrumbs = PersistingScopeObserver.read(options, BREADCRUMBS_FILENAME, List::class.java, Breadcrumb.Deserializer()) as? List<Breadcrumb>
315315
val segment = CaptureStrategy.createSegment(
316-
hub = hub,
316+
scopes = scopes,
317317
options = options,
318318
duration = lastSegment.duration,
319319
currentSegmentTimestamp = lastSegment.timestamp,
@@ -331,7 +331,7 @@ public class ReplayIntegration(
331331

332332
if (segment is ReplaySegment.Created) {
333333
val hint = HintUtils.createWithTypeCheckHint(PreviousReplayHint())
334-
segment.capture(hub, hint)
334+
segment.capture(scopes, hint)
335335
}
336336
cleanupReplays(unfinishedReplayId = previousReplayIdString) // will be cleaned up after the envelope is assembled
337337
}

sentry-android-replay/src/main/java/io/sentry/android/replay/capture/BaseCaptureStrategy.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package io.sentry.android.replay.capture
33
import android.view.MotionEvent
44
import io.sentry.Breadcrumb
55
import io.sentry.DateUtils
6-
import io.sentry.IHub
6+
import io.sentry.IScopes
77
import io.sentry.SentryOptions
88
import io.sentry.SentryReplayEvent.ReplayType
99
import io.sentry.SentryReplayEvent.ReplayType.BUFFER
@@ -44,7 +44,7 @@ import kotlin.reflect.KProperty
4444

4545
internal abstract class BaseCaptureStrategy(
4646
private val options: SentryOptions,
47-
private val hub: IHub?,
47+
private val scopes: IScopes?,
4848
private val dateProvider: ICurrentDateProvider,
4949
executor: ScheduledExecutorService? = null,
5050
private val replayCacheProvider: ((replayId: SentryId, recorderConfig: ScreenshotRecorderConfig) -> ReplayCache)? = null
@@ -138,7 +138,7 @@ internal abstract class BaseCaptureStrategy(
138138
events: LinkedList<RRWebEvent> = this.currentEvents
139139
): ReplaySegment =
140140
createSegment(
141-
hub,
141+
scopes,
142142
options,
143143
duration,
144144
currentSegmentTimestamp,

sentry-android-replay/src/main/java/io/sentry/android/replay/capture/BufferCaptureStrategy.kt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package io.sentry.android.replay.capture
33
import android.graphics.Bitmap
44
import android.view.MotionEvent
55
import io.sentry.DateUtils
6-
import io.sentry.IHub
6+
import io.sentry.IScopes
77
import io.sentry.SentryLevel.DEBUG
88
import io.sentry.SentryLevel.ERROR
99
import io.sentry.SentryLevel.INFO
@@ -25,12 +25,12 @@ import java.util.concurrent.ScheduledExecutorService
2525

2626
internal class BufferCaptureStrategy(
2727
private val options: SentryOptions,
28-
private val hub: IHub?,
28+
private val scopes: IScopes?,
2929
private val dateProvider: ICurrentDateProvider,
3030
private val random: SecureRandom,
3131
executor: ScheduledExecutorService? = null,
3232
replayCacheProvider: ((replayId: SentryId, recorderConfig: ScreenshotRecorderConfig) -> ReplayCache)? = null
33-
) : BaseCaptureStrategy(options, hub, dateProvider, executor = executor, replayCacheProvider = replayCacheProvider) {
33+
) : BaseCaptureStrategy(options, scopes, dateProvider, executor = executor, replayCacheProvider = replayCacheProvider) {
3434

3535
// TODO: capture envelopes for buffered segments instead, but don't send them until buffer is triggered
3636
private val bufferedSegments = mutableListOf<ReplaySegment.Created>()
@@ -72,7 +72,7 @@ internal class BufferCaptureStrategy(
7272

7373
// write replayId to scope right away, so it gets picked up by the event that caused buffer
7474
// to flush
75-
hub?.configureScope {
75+
scopes?.configureScope {
7676
it.replayId = currentReplayId
7777
}
7878

@@ -87,7 +87,7 @@ internal class BufferCaptureStrategy(
8787
bufferedSegments.capture()
8888

8989
if (segment is ReplaySegment.Created) {
90-
segment.capture(hub)
90+
segment.capture(scopes)
9191

9292
// we only want to increment segment_id in the case of success, but currentSegment
9393
// might be irrelevant since we changed strategies, so in the callback we increment
@@ -128,7 +128,7 @@ internal class BufferCaptureStrategy(
128128
return this
129129
}
130130
// we hand over replayExecutor to the new strategy to preserve order of execution
131-
val captureStrategy = SessionCaptureStrategy(options, hub, dateProvider, replayExecutor)
131+
val captureStrategy = SessionCaptureStrategy(options, scopes, dateProvider, replayExecutor)
132132
captureStrategy.start(recorderConfig, segmentId = currentSegment, replayId = currentReplayId, replayType = BUFFER)
133133
return captureStrategy
134134
}
@@ -155,7 +155,7 @@ internal class BufferCaptureStrategy(
155155
private fun MutableList<ReplaySegment.Created>.capture() {
156156
var bufferedSegment = removeFirstOrNull()
157157
while (bufferedSegment != null) {
158-
bufferedSegment.capture(hub)
158+
bufferedSegment.capture(scopes)
159159
bufferedSegment = removeFirstOrNull()
160160
// a short delay between processing envelopes to avoid bursting our server and hitting
161161
// another rate limit https://develop.sentry.dev/sdk/features/#additional-capabilities

sentry-android-replay/src/main/java/io/sentry/android/replay/capture/CaptureStrategy.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import android.view.MotionEvent
55
import io.sentry.Breadcrumb
66
import io.sentry.DateUtils
77
import io.sentry.Hint
8-
import io.sentry.IHub
8+
import io.sentry.IScopes
99
import io.sentry.ReplayRecording
1010
import io.sentry.SentryOptions
1111
import io.sentry.SentryReplayEvent
@@ -59,7 +59,7 @@ internal interface CaptureStrategy {
5959
internal val currentEventsLock = Any()
6060

6161
fun createSegment(
62-
hub: IHub?,
62+
scopes: IScopes?,
6363
options: SentryOptions,
6464
duration: Long,
6565
currentSegmentTimestamp: Date,
@@ -86,7 +86,7 @@ internal interface CaptureStrategy {
8686

8787
val replayBreadcrumbs: List<Breadcrumb> = if (breadcrumbs == null) {
8888
var crumbs = emptyList<Breadcrumb>()
89-
hub?.configureScope { scope ->
89+
scopes?.configureScope { scope ->
9090
crumbs = ArrayList(scope.breadcrumbs)
9191
}
9292
crumbs
@@ -224,8 +224,8 @@ internal interface CaptureStrategy {
224224
val replay: SentryReplayEvent,
225225
val recording: ReplayRecording
226226
) : ReplaySegment() {
227-
fun capture(hub: IHub?, hint: Hint = Hint()) {
228-
hub?.captureReplay(replay, hint.apply { replayRecording = recording })
227+
fun capture(scopes: IScopes?, hint: Hint = Hint()) {
228+
scopes?.captureReplay(replay, hint.apply { replayRecording = recording })
229229
}
230230

231231
fun setSegmentId(segmentId: Int) {

0 commit comments

Comments
 (0)