Skip to content

Commit 0e4edd9

Browse files
committed
RUM-10770: Remove KeepAlive event in RUM
1 parent 714d915 commit 0e4edd9

File tree

11 files changed

+106
-357
lines changed

11 files changed

+106
-357
lines changed

features/dd-sdk-android-rum/src/main/kotlin/com/datadog/android/rum/internal/RumFeature.kt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -431,10 +431,7 @@ internal class RumFeature(
431431

432432
TELEMETRY_SESSION_REPLAY_SKIP_FRAME -> addSessionReplaySkippedFrame()
433433
FLUSH_AND_STOP_MONITOR_MESSAGE_TYPE -> {
434-
(GlobalRumMonitor.get(sdkCore) as? DatadogRumMonitor)?.let {
435-
it.stopKeepAliveCallback()
436-
it.drainExecutorService()
437-
}
434+
(GlobalRumMonitor.get(sdkCore) as? DatadogRumMonitor)?.drainExecutorService()
438435
}
439436

440437
else -> {

features/dd-sdk-android-rum/src/main/kotlin/com/datadog/android/rum/internal/domain/scope/RumRawEvent.kt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -170,10 +170,6 @@ internal sealed class RumRawEvent {
170170
override val eventTime: Time = Time()
171171
) : RumRawEvent()
172172

173-
internal data class KeepAlive(
174-
override val eventTime: Time = Time()
175-
) : RumRawEvent()
176-
177173
internal data class ApplicationStarted(
178174
override val eventTime: Time,
179175
val applicationStartupNanos: Long

features/dd-sdk-android-rum/src/main/kotlin/com/datadog/android/rum/internal/domain/scope/RumViewManagerScope.kt

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,8 @@ internal class RumViewManagerScope(
108108
delegateToChildren(event, datadogContext, writeScope, writer)
109109

110110
if (event is RumRawEvent.StartView && !stopped) {
111-
startForegroundView(event, datadogContext, writeScope, writer)
111+
startForegroundView(event)
112+
sendViewUpdateToChildren(event, datadogContext, writeScope, writer)
112113
lastStoppedViewTime?.let {
113114
val gap = event.eventTime.nanoTime - it.nanoTime
114115
if (gap in 1 until THREE_SECONDS_GAP_NS) {
@@ -176,6 +177,15 @@ internal class RumViewManagerScope(
176177
childrenScopes.add(viewScope)
177178
}
178179

180+
private fun sendViewUpdateToChildren(
181+
event: RumRawEvent,
182+
datadogContext: DatadogContext,
183+
writeScope: EventWriteScope,
184+
writer: DataWriter<Any>
185+
) {
186+
childrenScopes.forEach { it.sendViewUpdate(event, datadogContext, writeScope, writer) }
187+
}
188+
179189
@WorkerThread
180190
private fun delegateToChildren(
181191
event: RumRawEvent,
@@ -262,10 +272,7 @@ internal class RumViewManagerScope(
262272

263273
@WorkerThread
264274
private fun startForegroundView(
265-
event: RumRawEvent.StartView,
266-
datadogContext: DatadogContext,
267-
writeScope: EventWriteScope,
268-
writer: DataWriter<Any>
275+
event: RumRawEvent.StartView
269276
) {
270277
val viewScope = RumViewScope.fromEvent(
271278
parentScope = this,
@@ -289,7 +296,6 @@ internal class RumViewManagerScope(
289296
)
290297
applicationDisplayed = true
291298
childrenScopes.add(viewScope)
292-
viewScope.handleEvent(RumRawEvent.KeepAlive(), datadogContext, writeScope, writer)
293299
viewChangedListener?.onViewChanged(
294300
RumViewInfo(
295301
key = event.key,
@@ -428,7 +434,6 @@ internal class RumViewManagerScope(
428434

429435
internal val silentOrphanEventTypes = arrayOf<Class<*>>(
430436
RumRawEvent.ApplicationStarted::class.java,
431-
RumRawEvent.KeepAlive::class.java,
432437
RumRawEvent.ResetSession::class.java,
433438
RumRawEvent.StopView::class.java,
434439
RumRawEvent.ActionDropped::class.java,

features/dd-sdk-android-rum/src/main/kotlin/com/datadog/android/rum/internal/domain/scope/RumViewScope.kt

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,6 @@ internal open class RumViewScope(
226226
)
227227

228228
is RumRawEvent.AddCustomTiming -> onAddCustomTiming(event, datadogContext, writeScope, writer)
229-
is RumRawEvent.KeepAlive -> onKeepAlive(event, datadogContext, writeScope, writer)
230229

231230
is RumRawEvent.StopSession -> onStopSession(event, datadogContext, writeScope, writer)
232231

@@ -898,19 +897,6 @@ internal open class RumViewScope(
898897
stopScope(event, datadogContext, writeScope, writer)
899898
}
900899

901-
@WorkerThread
902-
private fun onKeepAlive(
903-
event: RumRawEvent.KeepAlive,
904-
datadogContext: DatadogContext,
905-
writeScope: EventWriteScope,
906-
writer: DataWriter<Any>
907-
) {
908-
delegateEventToChildren(event, datadogContext, writeScope, writer)
909-
if (stopped) return
910-
911-
sendViewUpdate(event, datadogContext, writeScope, writer)
912-
}
913-
914900
@WorkerThread
915901
private fun delegateEventToChildren(
916902
event: RumRawEvent,
@@ -1111,7 +1097,7 @@ internal open class RumViewScope(
11111097
}
11121098

11131099
@Suppress("LongMethod", "ComplexMethod")
1114-
private fun sendViewUpdate(
1100+
internal fun sendViewUpdate(
11151101
event: RumRawEvent,
11161102
datadogContext: DatadogContext,
11171103
writeScope: EventWriteScope,

features/dd-sdk-android-rum/src/main/kotlin/com/datadog/android/rum/internal/monitor/DatadogRumMonitor.kt

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -122,18 +122,10 @@ internal class DatadogRumMonitor(
122122
rumSessionScopeStartupManagerFactory = rumSessionScopeStartupManagerFactory
123123
)
124124

125-
internal val keepAliveRunnable = Runnable {
126-
handleEvent(RumRawEvent.KeepAlive())
127-
}
128-
129125
internal var debugListener: RumDebugListener? = null
130126

131127
private val internalProxy = _RumInternalProxy(this)
132128

133-
init {
134-
handler.postDelayed(keepAliveRunnable, KEEP_ALIVE_MS)
135-
}
136-
137129
private val globalAttributes: MutableMap<String, Any?> = ConcurrentHashMap()
138130

139131
private val isDebugEnabled = AtomicBoolean(false)
@@ -804,7 +796,6 @@ internal class DatadogRumMonitor(
804796
} else if (event is RumRawEvent.TelemetryEventWrapper) {
805797
telemetryEventHandler.handleEvent(event, writer)
806798
} else {
807-
handler.removeCallbacks(keepAliveRunnable)
808799
sdkCore.getFeature(Feature.RUM_FEATURE_NAME)
809800
?.withWriteContext(
810801
withFeatureContexts = setOf(Feature.SESSION_REPLAY_FEATURE_NAME)
@@ -822,7 +813,6 @@ internal class DatadogRumMonitor(
822813
handleEventWithMethodCallPerf(event, datadogContext, writeScope)
823814
notifyDebugListenerWithState()
824815
}
825-
handler.postDelayed(keepAliveRunnable, KEEP_ALIVE_MS)
826816
currentRumContext()
827817
}
828818
)
@@ -885,10 +875,6 @@ internal class DatadogRumMonitor(
885875
return context
886876
}
887877

888-
internal fun stopKeepAliveCallback() {
889-
handler.removeCallbacks(keepAliveRunnable)
890-
}
891-
892878
internal fun notifyDebugListenerWithState() {
893879
debugListener?.let {
894880
val sessionScope = rootScope.activeSession
@@ -928,7 +914,6 @@ internal class DatadogRumMonitor(
928914
// endregion
929915

930916
companion object {
931-
internal val KEEP_ALIVE_MS = TimeUnit.MINUTES.toMillis(5)
932917

933918
// should be aligned with CoreFeature#DRAIN_WAIT_SECONDS, but not a requirement
934919
internal const val DRAIN_WAIT_SECONDS = 10L

features/dd-sdk-android-rum/src/test/kotlin/com/datadog/android/rum/internal/domain/scope/RumRawEventExt.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,6 @@ internal fun Forge.silentOrphanEvent(): RumRawEvent {
263263
listOf(
264264
RumRawEvent.ApplicationStarted(Time(), aLong()),
265265
RumRawEvent.ResetSession(),
266-
RumRawEvent.KeepAlive(),
267266
RumRawEvent.StopView(getForgery(), emptyMap()),
268267
RumRawEvent.ActionSent(
269268
fakeId,

features/dd-sdk-android-rum/src/test/kotlin/com/datadog/android/rum/internal/domain/scope/RumViewScopeAttributePropagationTest.kt

Lines changed: 18 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import com.datadog.android.core.internal.net.FirstPartyHostHeaderTypeResolver
2121
import com.datadog.android.rum.RumAttributes
2222
import com.datadog.android.rum.RumErrorSource
2323
import com.datadog.android.rum.RumSessionType
24-
import com.datadog.android.rum.assertj.ActionEventAssert.Companion.assertThat
2524
import com.datadog.android.rum.assertj.ErrorEventAssert.Companion.assertThat
2625
import com.datadog.android.rum.assertj.LongTaskEventAssert.Companion.assertThat
2726
import com.datadog.android.rum.assertj.ViewEventAssert.Companion.assertThat
@@ -263,68 +262,6 @@ internal class RumViewScopeAttributePropagationTest {
263262

264263
// region Propagate parent attributes in View Event
265264

266-
@Test
267-
fun `M send event with parent attributes W handleEvent(KeepAlive) on active view`() {
268-
// Given
269-
val expectedAttributes = mutableMapOf<String, Any?>()
270-
expectedAttributes.putAll(fakeParentAttributes)
271-
testedScope = newRumViewScope(initialAttributes = emptyMap())
272-
273-
// When
274-
val result =
275-
testedScope.handleEvent(RumRawEvent.KeepAlive(), fakeDatadogContext, mockEventWriteScope, mockWriter)
276-
277-
// Then
278-
argumentCaptor<ViewEvent> {
279-
verify(mockWriter).write(eq(mockEventBatchWriter), capture(), eq(EventType.DEFAULT))
280-
assertThat(lastValue)
281-
.containsExactlyContextAttributes(expectedAttributes)
282-
}
283-
assertThat(result).isNotNull()
284-
}
285-
286-
@Test
287-
fun `M send event with both parent and view attributes W handleEvent(KeepAlive) on active view`() {
288-
// Given
289-
val expectedAttributes = mutableMapOf<String, Any?>()
290-
expectedAttributes.putAll(fakeParentAttributes)
291-
expectedAttributes.putAll(fakeViewAttributes)
292-
testedScope = newRumViewScope(initialAttributes = fakeViewAttributes)
293-
294-
// When
295-
val result =
296-
testedScope.handleEvent(RumRawEvent.KeepAlive(), fakeDatadogContext, mockEventWriteScope, mockWriter)
297-
298-
// Then
299-
argumentCaptor<ViewEvent> {
300-
verify(mockWriter).write(eq(mockEventBatchWriter), capture(), eq(EventType.DEFAULT))
301-
assertThat(lastValue)
302-
.containsExactlyContextAttributes(expectedAttributes)
303-
}
304-
assertThat(result).isNotNull()
305-
}
306-
307-
@Test
308-
fun `M send event with overridden parent attributes W handleEvent(KeepAlive) on active view`(
309-
forge: Forge
310-
) {
311-
// Given
312-
val overriddenAttributes = fakeParentAttributes.map { it.key to forge.aString() }.toMap()
313-
testedScope = newRumViewScope(initialAttributes = overriddenAttributes)
314-
315-
// When
316-
val result =
317-
testedScope.handleEvent(RumRawEvent.KeepAlive(), fakeDatadogContext, mockEventWriteScope, mockWriter)
318-
319-
// Then
320-
argumentCaptor<ViewEvent> {
321-
verify(mockWriter).write(eq(mockEventBatchWriter), capture(), eq(EventType.DEFAULT))
322-
assertThat(lastValue)
323-
.containsExactlyContextAttributes(overriddenAttributes)
324-
}
325-
assertThat(result).isNotNull()
326-
}
327-
328265
@Test
329266
fun `M send event with original parent attributes W handleEvent(StopView+ErrorSent) on active view`(
330267
@StringForgery fakeAttrKey: String,
@@ -360,22 +297,27 @@ internal class RumViewScopeAttributePropagationTest {
360297
}
361298

362299
@Test
363-
fun `M send event with added view attributes W handleEvent(AddViewAttributes+KeepAlive) on active view`() {
300+
fun `M send event with added view attributes W handleEvent(AddViewAttributes+StopView) on active view`() {
364301
// Given
365302
val expectedAttributes = mutableMapOf<String, Any?>()
366303
expectedAttributes.putAll(fakeParentAttributes)
367304
expectedAttributes.putAll(fakeViewAttributes)
368305
testedScope = newRumViewScope(initialAttributes = emptyMap())
369306

370307
// When
371-
testedScope.handleEvent(
308+
val result = testedScope.handleEvent(
372309
RumRawEvent.AddViewAttributes(fakeViewAttributes),
373310
fakeDatadogContext,
374311
mockEventWriteScope,
375312
mockWriter
376313
)
377-
val result =
378-
testedScope.handleEvent(RumRawEvent.KeepAlive(), fakeDatadogContext, mockEventWriteScope, mockWriter)
314+
315+
testedScope.handleEvent(
316+
RumRawEvent.StopView(testedScope.key, emptyMap()),
317+
fakeDatadogContext,
318+
mockEventWriteScope,
319+
mockWriter
320+
)
379321

380322
// Then
381323
argumentCaptor<ViewEvent> {
@@ -387,7 +329,7 @@ internal class RumViewScopeAttributePropagationTest {
387329
}
388330

389331
@Test
390-
fun `M send event without removed view attributes W handleEvent(AddViewAttributes+KeepAlive) on active view`(
332+
fun `M send event without removed view attributes W handleEvent(AddViewAttributes+StopView) on active view`(
391333
@MapForgery(
392334
key = AdvancedForgery(string = [StringForgery(StringForgeryType.ALPHABETICAL)]),
393335
value = AdvancedForgery(string = [StringForgery()])
@@ -399,14 +341,19 @@ internal class RumViewScopeAttributePropagationTest {
399341
testedScope = newRumViewScope(initialAttributes = fakeViewAttributes)
400342

401343
// When
402-
testedScope.handleEvent(
344+
val result = testedScope.handleEvent(
403345
RumRawEvent.RemoveViewAttributes(fakeViewAttributes.keys),
404346
fakeDatadogContext,
405347
mockEventWriteScope,
406348
mockWriter
407349
)
408-
val result =
409-
testedScope.handleEvent(RumRawEvent.KeepAlive(), fakeDatadogContext, mockEventWriteScope, mockWriter)
350+
351+
testedScope.handleEvent(
352+
RumRawEvent.StopView(testedScope.key, emptyMap()),
353+
fakeDatadogContext,
354+
mockEventWriteScope,
355+
mockWriter
356+
)
410357

411358
// Then
412359
argumentCaptor<ViewEvent> {

0 commit comments

Comments
 (0)