Skip to content

Commit

Permalink
RUM-6385: Default sample rate for session replay
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanmos committed Oct 15, 2024
1 parent ca952c5 commit f9716c4
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 5 deletions.
2 changes: 1 addition & 1 deletion features/dd-sdk-android-session-replay/api/apiSurface
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ object com.datadog.android.sessionreplay.SessionReplay
fun stopRecording(com.datadog.android.api.SdkCore = Datadog.getInstance())
data class com.datadog.android.sessionreplay.SessionReplayConfiguration
class Builder
constructor(Float)
constructor(Float? = null)
fun addExtensionSupport(ExtensionSupport): Builder
fun useCustomEndpoint(String): Builder
DEPRECATED fun setPrivacy(SessionReplayPrivacy): Builder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ public final class com/datadog/android/sessionreplay/SessionReplayConfiguration
}

public final class com/datadog/android/sessionreplay/SessionReplayConfiguration$Builder {
public fun <init> (F)V
public fun <init> ()V
public fun <init> (Ljava/lang/Float;)V
public synthetic fun <init> (Ljava/lang/Float;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public final fun addExtensionSupport (Lcom/datadog/android/sessionreplay/ExtensionSupport;)Lcom/datadog/android/sessionreplay/SessionReplayConfiguration$Builder;
public final fun build ()Lcom/datadog/android/sessionreplay/SessionReplayConfiguration;
public final fun setDynamicOptimizationEnabled (Z)Lcom/datadog/android/sessionreplay/SessionReplayConfiguration$Builder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,10 @@ data class SessionReplayConfiguration internal constructor(
* @param sampleRate must be a value between 0 and 100. A value of 0
* means no session will be recorded, 100 means all sessions will be recorded.
*/
class Builder(@FloatRange(from = 0.0, to = 100.0) private val sampleRate: Float) {
class Builder(@FloatRange(from = 0.0, to = 100.0) inputSampleRate: Float? = null) {
private var customEndpointUrl: String? = null
private var privacy = SessionReplayPrivacy.MASK
private val sampleRate = inputSampleRate ?: SAMPLE_IN_ALL_SESSIONS

// indicates whether fine grained masking levels have been explicitly set
private var fineGrainedMaskingSet = false
Expand Down Expand Up @@ -196,5 +197,9 @@ data class SessionReplayConfiguration internal constructor(
private fun customMappers(): List<MapperTypeWrapper<*>> {
return extensionSupport.getCustomViewMappers()
}

internal companion object {
internal const val SAMPLE_IN_ALL_SESSIONS = 100.0f
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
package com.datadog.android.sessionreplay

import android.view.View
import com.datadog.android.sessionreplay.SessionReplayConfiguration.Builder.Companion.SAMPLE_IN_ALL_SESSIONS
import com.datadog.android.sessionreplay.forge.ForgeConfigurator
import fr.xgouchet.elmyr.annotation.BoolForgery
import fr.xgouchet.elmyr.annotation.FloatForgery
Expand Down Expand Up @@ -47,7 +48,7 @@ internal class SessionReplayConfigurationBuilderTest {
fun `set up`() {
fakeExpectedCustomMappers = listOf(MapperTypeWrapper(View::class.java, mock()))
whenever(mockExtensionSupport.getCustomViewMappers()).thenReturn(fakeExpectedCustomMappers)
testedBuilder = SessionReplayConfiguration.Builder(fakeSampleRate)
testedBuilder = SessionReplayConfiguration.Builder()
}

@Test
Expand All @@ -60,9 +61,9 @@ internal class SessionReplayConfigurationBuilderTest {
assertThat(sessionReplayConfiguration.privacy).isEqualTo(SessionReplayPrivacy.MASK)
assertThat(sessionReplayConfiguration.imagePrivacy).isEqualTo(ImagePrivacy.MASK_ALL)
assertThat(sessionReplayConfiguration.touchPrivacy).isEqualTo(TouchPrivacy.HIDE)
assertThat(sessionReplayConfiguration.sampleRate).isEqualTo(SAMPLE_IN_ALL_SESSIONS)
assertThat(sessionReplayConfiguration.customMappers).isEmpty()
assertThat(sessionReplayConfiguration.customOptionSelectorDetectors).isEmpty()
assertThat(sessionReplayConfiguration.sampleRate).isEqualTo(fakeSampleRate)
assertThat(sessionReplayConfiguration.dynamicOptimizationEnabled).isEqualTo(true)
}

Expand All @@ -71,6 +72,7 @@ internal class SessionReplayConfigurationBuilderTest {
@StringForgery(regex = "https://[a-z]+\\.com") sessionReplayUrl: String
) {
// When
testedBuilder = SessionReplayConfiguration.Builder(fakeSampleRate)
val sessionReplayConfiguration = testedBuilder
.useCustomEndpoint(sessionReplayUrl)
.build()
Expand Down

0 comments on commit f9716c4

Please sign in to comment.