Skip to content

Commit 294bfe6

Browse files
committed
RUM-15139: PR Feedback
1 parent f9fa86c commit 294bfe6

6 files changed

Lines changed: 73 additions & 30 deletions

File tree

dd-sdk-android-internal/src/main/java/com/datadog/android/internal/sampling/DeterministicSampling.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,17 @@ object DeterministicSampling {
1515

1616
/**
1717
* Returns the effective sampling rate when a child feature's [featureSampleRate] is applied
18-
* on top of a parent session's [sessionSampleRate].
18+
* on top of a parent session's [rumSessionSampleRate].
1919
*
2020
* The combined rate represents the probability that both the session AND the child feature
2121
* are sampled in, preserving the deterministic guarantee: any session that passes the combined
2222
* threshold is guaranteed to have also passed the session-level threshold.
2323
*
24-
* @param sessionSampleRate The RUM session sampling rate (0–100).
24+
* @param rumSessionSampleRate The RUM session sampling rate (0–100).
2525
* @param featureSampleRate The child feature sampling rate (0–100).
2626
* @return The effective combined rate, clamped to [0, 100].
2727
*/
28-
fun combinedSampleRate(sessionSampleRate: Float, featureSampleRate: Float): Float =
29-
(sessionSampleRate * featureSampleRate / SAMPLE_ALL_RATE)
28+
fun combinedSampleRate(rumSessionSampleRate: Float, featureSampleRate: Float): Float =
29+
(rumSessionSampleRate * featureSampleRate / SAMPLE_ALL_RATE)
3030
.coerceIn(0f, SAMPLE_ALL_RATE)
3131
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ internal data class RumContext(
5050

5151
companion object {
5252
val NULL_UUID = UUID(0, 0).toString()
53-
const val FULL_SESSION_SAMPLE_RATE: Float = 100f
53+
const val SAMPLE_ALL_RATE: Float = 100f
5454

5555
// be careful when changing values below, they may be indirectly referenced (as string
5656
// literal) from other modules

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ internal class RumSessionScope(
6565

6666
internal var sessionId = RumContext.NULL_UUID
6767
internal var sessionState: State = State.NOT_TRACKED
68-
internal val sessionSampleRate: Float = sessionSampler.getSampleRate() ?: RumContext.FULL_SESSION_SAMPLE_RATE
68+
internal val sessionSampleRate: Float = sessionSampler.getSampleRate() ?: RumContext.SAMPLE_ALL_RATE
6969
private var startReason: StartReason = StartReason.USER_APP_LAUNCH
7070
internal var isActive: Boolean = true
7171
private val sessionStartNs = AtomicLong(sdkCore.timeProvider.getDeviceElapsedTimeNanos())
@@ -304,7 +304,11 @@ internal class RumSessionScope(
304304
mapOf(
305305
SESSION_REPLAY_BUS_MESSAGE_TYPE_KEY to RUM_SESSION_RENEWED_BUS_MESSAGE,
306306
RUM_SESSION_ID_BUS_MESSAGE_KEY to sessionId,
307-
RUM_SESSION_SAMPLE_RATE_BUS_MESSAGE_KEY to sessionSampleRate
307+
RUM_SESSION_SAMPLE_RATE_BUS_MESSAGE_KEY to sessionSampleRate,
308+
// Kept for backward compatibility with older Session Replay modules that
309+
// don't yet consume sessionSampleRate.
310+
// RUM-15962: Remove with SDK v4 release (RUM-13454).
311+
RUM_KEEP_SESSION_BUS_MESSAGE_KEY to (sessionState == State.TRACKED)
308312
)
309313
)
310314
}
@@ -316,6 +320,9 @@ internal class RumSessionScope(
316320
internal const val SESSION_REPLAY_BUS_MESSAGE_TYPE_KEY = "type"
317321
internal const val RUM_SESSION_RENEWED_BUS_MESSAGE = "rum_session_renewed"
318322
internal const val RUM_SESSION_ID_BUS_MESSAGE_KEY = "sessionId"
323+
324+
// RUM-15962: Remove with SDK v4 release (RUM-13454).
325+
internal const val RUM_KEEP_SESSION_BUS_MESSAGE_KEY = "keepSession"
319326
internal const val RUM_SESSION_SAMPLE_RATE_BUS_MESSAGE_KEY = "sessionSampleRate"
320327
internal val DEFAULT_SESSION_INACTIVITY_NS = TimeUnit.MINUTES.toNanos(15)
321328
internal val DEFAULT_SESSION_MAX_DURATION_NS = TimeUnit.HOURS.toNanos(4)

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

Lines changed: 54 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1243,7 +1243,9 @@ internal class RumSessionScopeTest {
12431243
RumSessionScope.RUM_SESSION_RENEWED_BUS_MESSAGE,
12441244
RumSessionScope.RUM_SESSION_ID_BUS_MESSAGE_KEY to
12451245
testedScope.getRumContext().sessionId,
1246-
RumSessionScope.RUM_SESSION_SAMPLE_RATE_BUS_MESSAGE_KEY to testedScope.sessionSampleRate
1246+
RumSessionScope.RUM_SESSION_SAMPLE_RATE_BUS_MESSAGE_KEY to testedScope.sessionSampleRate,
1247+
RumSessionScope.RUM_KEEP_SESSION_BUS_MESSAGE_KEY to
1248+
(testedScope.sessionState == RumSessionScope.State.TRACKED)
12471249
)
12481250
)
12491251
assertThat(argumentCaptor.secondValue).isEqualTo(
@@ -1252,7 +1254,9 @@ internal class RumSessionScopeTest {
12521254
RumSessionScope.RUM_SESSION_RENEWED_BUS_MESSAGE,
12531255
RumSessionScope.RUM_SESSION_ID_BUS_MESSAGE_KEY to
12541256
testedScope.getRumContext().sessionId,
1255-
RumSessionScope.RUM_SESSION_SAMPLE_RATE_BUS_MESSAGE_KEY to testedScope.sessionSampleRate
1257+
RumSessionScope.RUM_SESSION_SAMPLE_RATE_BUS_MESSAGE_KEY to testedScope.sessionSampleRate,
1258+
RumSessionScope.RUM_KEEP_SESSION_BUS_MESSAGE_KEY to
1259+
(testedScope.sessionState == RumSessionScope.State.TRACKED)
12561260
)
12571261
)
12581262
}
@@ -1288,7 +1292,9 @@ internal class RumSessionScopeTest {
12881292
RumSessionScope.RUM_SESSION_RENEWED_BUS_MESSAGE,
12891293
RumSessionScope.RUM_SESSION_ID_BUS_MESSAGE_KEY to
12901294
testedScope.getRumContext().sessionId,
1291-
RumSessionScope.RUM_SESSION_SAMPLE_RATE_BUS_MESSAGE_KEY to testedScope.sessionSampleRate
1295+
RumSessionScope.RUM_SESSION_SAMPLE_RATE_BUS_MESSAGE_KEY to testedScope.sessionSampleRate,
1296+
RumSessionScope.RUM_KEEP_SESSION_BUS_MESSAGE_KEY to
1297+
(testedScope.sessionState == RumSessionScope.State.TRACKED)
12921298
)
12931299
)
12941300
assertThat(argumentCaptor.secondValue).isEqualTo(
@@ -1297,7 +1303,9 @@ internal class RumSessionScopeTest {
12971303
RumSessionScope.RUM_SESSION_RENEWED_BUS_MESSAGE,
12981304
RumSessionScope.RUM_SESSION_ID_BUS_MESSAGE_KEY to
12991305
testedScope.getRumContext().sessionId,
1300-
RumSessionScope.RUM_SESSION_SAMPLE_RATE_BUS_MESSAGE_KEY to testedScope.sessionSampleRate
1306+
RumSessionScope.RUM_SESSION_SAMPLE_RATE_BUS_MESSAGE_KEY to testedScope.sessionSampleRate,
1307+
RumSessionScope.RUM_KEEP_SESSION_BUS_MESSAGE_KEY to
1308+
(testedScope.sessionState == RumSessionScope.State.TRACKED)
13011309
)
13021310
)
13031311
}
@@ -1326,15 +1334,19 @@ internal class RumSessionScopeTest {
13261334
RumSessionScope.SESSION_REPLAY_BUS_MESSAGE_TYPE_KEY to
13271335
RumSessionScope.RUM_SESSION_RENEWED_BUS_MESSAGE,
13281336
RumSessionScope.RUM_SESSION_ID_BUS_MESSAGE_KEY to firstSessionId,
1329-
RumSessionScope.RUM_SESSION_SAMPLE_RATE_BUS_MESSAGE_KEY to testedScope.sessionSampleRate
1337+
RumSessionScope.RUM_SESSION_SAMPLE_RATE_BUS_MESSAGE_KEY to testedScope.sessionSampleRate,
1338+
RumSessionScope.RUM_KEEP_SESSION_BUS_MESSAGE_KEY to
1339+
(testedScope.sessionState == RumSessionScope.State.TRACKED)
13301340
)
13311341
)
13321342
assertThat(argumentCaptor.secondValue).isEqualTo(
13331343
mapOf(
13341344
RumSessionScope.SESSION_REPLAY_BUS_MESSAGE_TYPE_KEY to
13351345
RumSessionScope.RUM_SESSION_RENEWED_BUS_MESSAGE,
13361346
RumSessionScope.RUM_SESSION_ID_BUS_MESSAGE_KEY to secondSessionId,
1337-
RumSessionScope.RUM_SESSION_SAMPLE_RATE_BUS_MESSAGE_KEY to testedScope.sessionSampleRate
1347+
RumSessionScope.RUM_SESSION_SAMPLE_RATE_BUS_MESSAGE_KEY to testedScope.sessionSampleRate,
1348+
RumSessionScope.RUM_KEEP_SESSION_BUS_MESSAGE_KEY to
1349+
(testedScope.sessionState == RumSessionScope.State.TRACKED)
13381350
)
13391351
)
13401352
}
@@ -1364,7 +1376,9 @@ internal class RumSessionScopeTest {
13641376
RumSessionScope.RUM_SESSION_RENEWED_BUS_MESSAGE,
13651377
RumSessionScope.RUM_SESSION_ID_BUS_MESSAGE_KEY to
13661378
firstSessionId,
1367-
RumSessionScope.RUM_SESSION_SAMPLE_RATE_BUS_MESSAGE_KEY to testedScope.sessionSampleRate
1379+
RumSessionScope.RUM_SESSION_SAMPLE_RATE_BUS_MESSAGE_KEY to testedScope.sessionSampleRate,
1380+
RumSessionScope.RUM_KEEP_SESSION_BUS_MESSAGE_KEY to
1381+
(testedScope.sessionState == RumSessionScope.State.TRACKED)
13681382
)
13691383
)
13701384
assertThat(argumentCaptor.secondValue).isEqualTo(
@@ -1373,7 +1387,9 @@ internal class RumSessionScopeTest {
13731387
RumSessionScope.RUM_SESSION_RENEWED_BUS_MESSAGE,
13741388
RumSessionScope.RUM_SESSION_ID_BUS_MESSAGE_KEY to
13751389
secondSessionId,
1376-
RumSessionScope.RUM_SESSION_SAMPLE_RATE_BUS_MESSAGE_KEY to testedScope.sessionSampleRate
1390+
RumSessionScope.RUM_SESSION_SAMPLE_RATE_BUS_MESSAGE_KEY to testedScope.sessionSampleRate,
1391+
RumSessionScope.RUM_KEEP_SESSION_BUS_MESSAGE_KEY to
1392+
(testedScope.sessionState == RumSessionScope.State.TRACKED)
13771393
)
13781394
)
13791395
}
@@ -1404,7 +1420,9 @@ internal class RumSessionScopeTest {
14041420
RumSessionScope.RUM_SESSION_RENEWED_BUS_MESSAGE,
14051421
RumSessionScope.RUM_SESSION_ID_BUS_MESSAGE_KEY to
14061422
firstSessionId,
1407-
RumSessionScope.RUM_SESSION_SAMPLE_RATE_BUS_MESSAGE_KEY to testedScope.sessionSampleRate
1423+
RumSessionScope.RUM_SESSION_SAMPLE_RATE_BUS_MESSAGE_KEY to testedScope.sessionSampleRate,
1424+
RumSessionScope.RUM_KEEP_SESSION_BUS_MESSAGE_KEY to
1425+
(testedScope.sessionState == RumSessionScope.State.TRACKED)
14081426
)
14091427
)
14101428
assertThat(argumentCaptor.secondValue).isEqualTo(
@@ -1413,7 +1431,9 @@ internal class RumSessionScopeTest {
14131431
RumSessionScope.RUM_SESSION_RENEWED_BUS_MESSAGE,
14141432
RumSessionScope.RUM_SESSION_ID_BUS_MESSAGE_KEY to
14151433
secondSessionId,
1416-
RumSessionScope.RUM_SESSION_SAMPLE_RATE_BUS_MESSAGE_KEY to testedScope.sessionSampleRate
1434+
RumSessionScope.RUM_SESSION_SAMPLE_RATE_BUS_MESSAGE_KEY to testedScope.sessionSampleRate,
1435+
RumSessionScope.RUM_KEEP_SESSION_BUS_MESSAGE_KEY to
1436+
(testedScope.sessionState == RumSessionScope.State.TRACKED)
14171437
)
14181438
)
14191439
assertThat(argumentCaptor.thirdValue).isEqualTo(
@@ -1422,7 +1442,9 @@ internal class RumSessionScopeTest {
14221442
RumSessionScope.RUM_SESSION_RENEWED_BUS_MESSAGE,
14231443
RumSessionScope.RUM_SESSION_ID_BUS_MESSAGE_KEY to
14241444
secondSessionId,
1425-
RumSessionScope.RUM_SESSION_SAMPLE_RATE_BUS_MESSAGE_KEY to testedScope.sessionSampleRate
1445+
RumSessionScope.RUM_SESSION_SAMPLE_RATE_BUS_MESSAGE_KEY to testedScope.sessionSampleRate,
1446+
RumSessionScope.RUM_KEEP_SESSION_BUS_MESSAGE_KEY to
1447+
(testedScope.sessionState == RumSessionScope.State.TRACKED)
14261448
)
14271449
)
14281450
}
@@ -1453,15 +1475,19 @@ internal class RumSessionScopeTest {
14531475
RumSessionScope.SESSION_REPLAY_BUS_MESSAGE_TYPE_KEY to
14541476
RumSessionScope.RUM_SESSION_RENEWED_BUS_MESSAGE,
14551477
RumSessionScope.RUM_SESSION_ID_BUS_MESSAGE_KEY to firstSessionId,
1456-
RumSessionScope.RUM_SESSION_SAMPLE_RATE_BUS_MESSAGE_KEY to testedScope.sessionSampleRate
1478+
RumSessionScope.RUM_SESSION_SAMPLE_RATE_BUS_MESSAGE_KEY to testedScope.sessionSampleRate,
1479+
RumSessionScope.RUM_KEEP_SESSION_BUS_MESSAGE_KEY to
1480+
(testedScope.sessionState == RumSessionScope.State.TRACKED)
14571481
)
14581482
)
14591483
assertThat(argumentCaptor.secondValue).isEqualTo(
14601484
mapOf(
14611485
RumSessionScope.SESSION_REPLAY_BUS_MESSAGE_TYPE_KEY to
14621486
RumSessionScope.RUM_SESSION_RENEWED_BUS_MESSAGE,
14631487
RumSessionScope.RUM_SESSION_ID_BUS_MESSAGE_KEY to secondSessionId,
1464-
RumSessionScope.RUM_SESSION_SAMPLE_RATE_BUS_MESSAGE_KEY to testedScope.sessionSampleRate
1488+
RumSessionScope.RUM_SESSION_SAMPLE_RATE_BUS_MESSAGE_KEY to testedScope.sessionSampleRate,
1489+
RumSessionScope.RUM_KEEP_SESSION_BUS_MESSAGE_KEY to
1490+
(testedScope.sessionState == RumSessionScope.State.TRACKED)
14651491
)
14661492
)
14671493
}
@@ -1492,15 +1518,19 @@ internal class RumSessionScopeTest {
14921518
RumSessionScope.SESSION_REPLAY_BUS_MESSAGE_TYPE_KEY to
14931519
RumSessionScope.RUM_SESSION_RENEWED_BUS_MESSAGE,
14941520
RumSessionScope.RUM_SESSION_ID_BUS_MESSAGE_KEY to firstSessionId,
1495-
RumSessionScope.RUM_SESSION_SAMPLE_RATE_BUS_MESSAGE_KEY to testedScope.sessionSampleRate
1521+
RumSessionScope.RUM_SESSION_SAMPLE_RATE_BUS_MESSAGE_KEY to testedScope.sessionSampleRate,
1522+
RumSessionScope.RUM_KEEP_SESSION_BUS_MESSAGE_KEY to
1523+
(testedScope.sessionState == RumSessionScope.State.TRACKED)
14961524
)
14971525
)
14981526
assertThat(argumentCaptor.secondValue).isEqualTo(
14991527
mapOf(
15001528
RumSessionScope.SESSION_REPLAY_BUS_MESSAGE_TYPE_KEY to
15011529
RumSessionScope.RUM_SESSION_RENEWED_BUS_MESSAGE,
15021530
RumSessionScope.RUM_SESSION_ID_BUS_MESSAGE_KEY to secondSessionId,
1503-
RumSessionScope.RUM_SESSION_SAMPLE_RATE_BUS_MESSAGE_KEY to testedScope.sessionSampleRate
1531+
RumSessionScope.RUM_SESSION_SAMPLE_RATE_BUS_MESSAGE_KEY to testedScope.sessionSampleRate,
1532+
RumSessionScope.RUM_KEEP_SESSION_BUS_MESSAGE_KEY to
1533+
(testedScope.sessionState == RumSessionScope.State.TRACKED)
15041534
)
15051535
)
15061536
}
@@ -1532,23 +1562,29 @@ internal class RumSessionScopeTest {
15321562
RumSessionScope.SESSION_REPLAY_BUS_MESSAGE_TYPE_KEY to
15331563
RumSessionScope.RUM_SESSION_RENEWED_BUS_MESSAGE,
15341564
RumSessionScope.RUM_SESSION_ID_BUS_MESSAGE_KEY to firstSessionId,
1535-
RumSessionScope.RUM_SESSION_SAMPLE_RATE_BUS_MESSAGE_KEY to testedScope.sessionSampleRate
1565+
RumSessionScope.RUM_SESSION_SAMPLE_RATE_BUS_MESSAGE_KEY to testedScope.sessionSampleRate,
1566+
RumSessionScope.RUM_KEEP_SESSION_BUS_MESSAGE_KEY to
1567+
(testedScope.sessionState == RumSessionScope.State.TRACKED)
15361568
)
15371569
)
15381570
assertThat(argumentCaptor.secondValue).isEqualTo(
15391571
mapOf(
15401572
RumSessionScope.SESSION_REPLAY_BUS_MESSAGE_TYPE_KEY to
15411573
RumSessionScope.RUM_SESSION_RENEWED_BUS_MESSAGE,
15421574
RumSessionScope.RUM_SESSION_ID_BUS_MESSAGE_KEY to secondSessionId,
1543-
RumSessionScope.RUM_SESSION_SAMPLE_RATE_BUS_MESSAGE_KEY to testedScope.sessionSampleRate
1575+
RumSessionScope.RUM_SESSION_SAMPLE_RATE_BUS_MESSAGE_KEY to testedScope.sessionSampleRate,
1576+
RumSessionScope.RUM_KEEP_SESSION_BUS_MESSAGE_KEY to
1577+
(testedScope.sessionState == RumSessionScope.State.TRACKED)
15441578
)
15451579
)
15461580
assertThat(argumentCaptor.thirdValue).isEqualTo(
15471581
mapOf(
15481582
RumSessionScope.SESSION_REPLAY_BUS_MESSAGE_TYPE_KEY to
15491583
RumSessionScope.RUM_SESSION_RENEWED_BUS_MESSAGE,
15501584
RumSessionScope.RUM_SESSION_ID_BUS_MESSAGE_KEY to secondSessionId,
1551-
RumSessionScope.RUM_SESSION_SAMPLE_RATE_BUS_MESSAGE_KEY to testedScope.sessionSampleRate
1585+
RumSessionScope.RUM_SESSION_SAMPLE_RATE_BUS_MESSAGE_KEY to testedScope.sessionSampleRate,
1586+
RumSessionScope.RUM_KEEP_SESSION_BUS_MESSAGE_KEY to
1587+
(testedScope.sessionState == RumSessionScope.State.TRACKED)
15521588
)
15531589
)
15541590
}

features/dd-sdk-android-session-replay/src/main/kotlin/com/datadog/android/sessionreplay/internal/SessionReplayFeature.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ internal class SessionReplayFeature(
279279
DeterministicSampler(
280280
idConverter = SessionSamplingIdProvider::provideId,
281281
sampleRate = DeterministicSampling.combinedSampleRate(
282-
sessionSampleRate = sessionData.sessionSampleRate,
282+
rumSessionSampleRate = sessionData.sessionSampleRate,
283283
featureSampleRate = configuredSampleRate
284284
)
285285
).sample(sessionData.sessionId)

features/dd-sdk-android-session-replay/src/test/kotlin/com/datadog/android/sessionreplay/internal/SessionReplayFeatureTest.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,6 @@ internal class SessionReplayFeatureTest {
9393

9494
private var fakeSampleRate: Float = 75f
9595

96-
private fun sampledInSessionId(sessionId: String): String {
97-
return sessionId.replaceAfterLast("-", "000000000000")
98-
}
99-
10096
@BeforeEach
10197
fun `set up`(forge: Forge) {
10298
fakeSampleRate = forge.aFloat(min = 1f, max = 100f)
@@ -1335,6 +1331,10 @@ internal class SessionReplayFeatureTest {
13351331
}
13361332
}
13371333

1334+
private fun sampledInSessionId(sessionId: String): String {
1335+
return sessionId.replaceAfterLast("-", "000000000000")
1336+
}
1337+
13381338
internal data class SessionRecordingScenario(
13391339
val startRecordingImmediately: Boolean,
13401340
val sampleInSession: Boolean,

0 commit comments

Comments
 (0)