Skip to content

Commit 0e18281

Browse files
committed
refactored PrivacyProfile options to be boolean based
1 parent c7661b8 commit 0e18281

File tree

4 files changed

+27
-91
lines changed

4 files changed

+27
-91
lines changed

e2e/android/app/src/main/java/com/example/androidobservability/BaseApplication.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ open class BaseApplication : Application() {
3636
instrumentations = listOf(
3737
ReplayInstrumentation(
3838
options = ReplayOptions(
39-
privacyProfile = PrivacyProfile.optIn(listOf(PrivacyProfile.sensitiveMatcher))
39+
privacyProfile = PrivacyProfile(maskText = false)
4040
)
4141
)
4242
),

sdk/@launchdarkly/observability-android/lib/src/main/kotlin/com/launchdarkly/observability/replay/PrivacyProfile.kt

Lines changed: 24 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,35 @@ import androidx.compose.ui.semantics.getOrNull
55
import com.launchdarkly.observability.replay.MaskMatcher
66

77
/**
8-
* The [PrivacyProfile] class encapsulates options and functionality related to privacy of session
8+
* [PrivacyProfile] encapsulates options and functionality related to privacy of session
99
* replay functionality.
1010
*
11-
* By default, session replay will apply an opaque mask to elemetns that match the [builtInMatchers].
12-
* To customize this behavior, use one of [strict], [optIn], [optOut]
11+
* By default, session replay will apply an opaque mask to text inputs, text, and sensitive views.
12+
* See [sensitiveMatcher] for specific details.
13+
*
14+
* @param maskTextInputs set to false to turn off masking text inputs
15+
* @param maskText set to false to turn off masking text
16+
* @param maskSensitive set to false to turn off masking sensitive views
17+
* @param maskAdditionalMatchers list of additional [MaskMatcher]s that will be masked when they match
1318
**/
14-
data class PrivacyProfile private constructor(
15-
internal val maskMatchers: List<MaskMatcher>,
19+
data class PrivacyProfile(
20+
val maskTextInputs: Boolean = true,
21+
val maskText: Boolean = true,
22+
val maskSensitive: Boolean = true,
23+
val maskAdditionalMatchers: List<MaskMatcher> = emptyList(),
1624
) {
17-
companion object {
1825

26+
/**
27+
* Converts this [PrivacyProfile] into its equivalent [MaskMatcher] list.
28+
*/
29+
internal fun asMatchersList(): List<MaskMatcher> = buildList {
30+
if (maskTextInputs) add(textInputMatcher)
31+
if (maskText) add(textMatcher)
32+
if (maskSensitive) add(sensitiveMatcher)
33+
addAll(maskAdditionalMatchers)
34+
}
35+
36+
companion object {
1937
/**
2038
* This matcher will match most text inputs, but there may be special cases where it will
2139
* miss as we can't account for all possible future semantic properties.
@@ -81,88 +99,6 @@ data class PrivacyProfile private constructor(
8199
}
82100
}
83101

84-
/**
85-
* The list of built in matchers.
86-
*/
87-
val builtInMatchers = listOf(textInputMatcher, textMatcher, sensitiveMatcher)
88-
89-
/**
90-
* A [PrivacyProfile] that will perform no masking.
91-
*
92-
* @sample
93-
* ```kotlin
94-
* ReplayInstrumentation(
95-
* options = ReplayOptions(
96-
* privacyProfile = PrivacyProfile.noMasking()
97-
* )
98-
* )
99-
* ```
100-
*/
101-
fun noMasking() = PrivacyProfile(
102-
maskMatchers = emptyList(),
103-
)
104-
105-
/**
106-
* A [PrivacyProfile] that uses [builtInMatchers] plus any additional [MaskMatcher]s provided.
107-
*
108-
* Matchers should not do heavy work, should execute synchronously, and not dispatch to other
109-
* threads for performance reasons. If you add a matcher and notice jitter, this may be
110-
* the cause.
111-
*
112-
* @sample
113-
* ```kotlin
114-
* ReplayInstrumentation(
115-
* options = ReplayOptions(
116-
* privacyProfile = PrivacyProfile.strict()
117-
* )
118-
* )
119-
* ```
120-
*
121-
* @param additionalMatchers additional matchers that will also run after built in matchers
122-
*/
123-
fun strict(additionalMatchers: List<MaskMatcher> = emptyList()) = PrivacyProfile(
124-
maskMatchers = buildList {
125-
addAll(builtInMatchers)
126-
addAll(additionalMatchers)
127-
},
128-
)
129-
130-
/**
131-
* A [PrivacyProfile] that uses only the provided [MaskMatcher]s
132-
*
133-
* @sample
134-
* ```kotlin
135-
* ReplayInstrumentation(
136-
* options = ReplayOptions(
137-
* privacyProfile = PrivacyProfile.optIn(listOf(PrivacyProfile.sensitiveMatcher))
138-
* )
139-
* )
140-
* ```
141-
*
142-
* @param matchers the matchers to use
143-
*/
144-
fun optIn(matchers: List<MaskMatcher>) = PrivacyProfile(
145-
maskMatchers = matchers,
146-
)
147-
148-
/**
149-
* A [PrivacyProfile] that uses all [builtInMatchers] except those provided.
150-
*
151-
* @sample
152-
* ```kotlin
153-
* ReplayInstrumentation(
154-
* options = ReplayOptions(
155-
* privacyProfile = PrivacyProfile.optOut(listOf(PrivacyProfile.textMatcher))
156-
* )
157-
* )
158-
* ```
159-
*
160-
* @param matchers the matchers to NOT use
161-
*/
162-
fun optOut(matchers: List<MaskMatcher>) = PrivacyProfile(
163-
maskMatchers = builtInMatchers.filter { it !in matchers },
164-
)
165-
166102
// this list of sensitive keywords is used to detect sensitive content descriptions
167103
private val sensitiveKeywords = listOf(
168104
"sensitive",

sdk/@launchdarkly/observability-android/lib/src/main/kotlin/com/launchdarkly/observability/replay/ReplayInstrumentation.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ class ReplayInstrumentation(
7878

7979
override fun install(ctx: InstallationContext) {
8080
_otelLogger = ctx.openTelemetry.logsBridge.get(INSTRUMENTATION_SCOPE_NAME)
81-
_captureSource = CaptureSource(ctx.sessionManager, options.privacyProfile.maskMatchers)
81+
_captureSource = CaptureSource(ctx.sessionManager, options.privacyProfile.asMatchersList())
8282
_captureSource.attachToApplication(ctx.application)
8383

8484
// TODO: O11Y-621 - don't use global scope

sdk/@launchdarkly/observability-android/lib/src/main/kotlin/com/launchdarkly/observability/replay/ReplayOptions.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ data class ReplayOptions(
1717
val serviceVersion: String = BuildConfig.OBSERVABILITY_SDK_VERSION,
1818
val backendUrl: String = DEFAULT_BACKEND_URL,
1919
val debug: Boolean = false,
20-
val privacyProfile: PrivacyProfile = PrivacyProfile.strict(),
20+
val privacyProfile: PrivacyProfile = PrivacyProfile(),
2121
val capturePeriodMillis: Long = 1000, // defaults to ever 1 second
2222
// TODO O11Y-623 - Add storage options
2323
)

0 commit comments

Comments
 (0)