Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RUM-6566: Extract privacy error handling #2335

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
* This product includes software developed at Datadog (https://www.datadoghq.com/).
* Copyright 2016-Present Datadog, Inc.
*/

package com.datadog.android.sessionreplay.internal

import com.datadog.android.api.InternalLogger

internal class PrivacyHelper(private val internalLogger: InternalLogger) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❔ question: ‏ Are we creating this helper only for this purpose ? Seems a bit too much for me, can't we find a different way to share this code ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Potentially this class could hold additional common logic in the future, and I don't see a better place at the moment to put this. Let's discuss

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think instead of creating one class and one instance for this I would rather have this call duplicated in those classes. I am waiting to see what the others are saying also.

internal fun logInvalidPrivacyLevelError(e: Exception) {
internalLogger.log(
InternalLogger.Level.ERROR,
listOf(InternalLogger.Target.USER, InternalLogger.Target.TELEMETRY),
{ INVALID_PRIVACY_LEVEL_ERROR },
e
)
}

internal companion object {
internal const val INVALID_PRIVACY_LEVEL_ERROR = "Invalid privacy level"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import com.datadog.android.api.InternalLogger
import com.datadog.android.sessionreplay.ImagePrivacy
import com.datadog.android.sessionreplay.R
import com.datadog.android.sessionreplay.TextAndInputPrivacy
import com.datadog.android.sessionreplay.internal.PrivacyHelper
import com.datadog.android.sessionreplay.internal.async.RecordedDataQueueRefs
import com.datadog.android.sessionreplay.model.MobileSegment
import com.datadog.android.sessionreplay.recorder.MappingContext
Expand All @@ -25,7 +26,8 @@ internal class SnapshotProducer(
private val imageWireframeHelper: ImageWireframeHelper,
private val treeViewTraversal: TreeViewTraversal,
private val optionSelectorDetector: OptionSelectorDetector,
private val internalLogger: InternalLogger
private val internalLogger: InternalLogger,
private val privacyHelper: PrivacyHelper = PrivacyHelper(internalLogger)
) {

@UiThread
Expand Down Expand Up @@ -112,7 +114,7 @@ internal class SnapshotProducer(
ImagePrivacy.valueOf(privacy)
}
} catch (e: IllegalArgumentException) {
logInvalidPrivacyLevelError(e)
privacyHelper.logInvalidPrivacyLevelError(e)
mappingContext.imagePrivacy
}

Expand All @@ -125,7 +127,7 @@ internal class SnapshotProducer(
TextAndInputPrivacy.valueOf(privacy)
}
} catch (e: IllegalArgumentException) {
logInvalidPrivacyLevelError(e)
privacyHelper.logInvalidPrivacyLevelError(e)
mappingContext.textAndInputPrivacy
}

Expand All @@ -134,17 +136,4 @@ internal class SnapshotProducer(
textAndInputPrivacy = textAndInputPrivacy
)
}

private fun logInvalidPrivacyLevelError(e: Exception) {
internalLogger.log(
InternalLogger.Level.ERROR,
listOf(InternalLogger.Target.USER, InternalLogger.Target.TELEMETRY),
{ INVALID_PRIVACY_LEVEL_ERROR },
e
)
}

internal companion object {
internal const val INVALID_PRIVACY_LEVEL_ERROR = "Invalid privacy level"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import com.datadog.android.sessionreplay.ImagePrivacy
import com.datadog.android.sessionreplay.R
import com.datadog.android.sessionreplay.TextAndInputPrivacy
import com.datadog.android.sessionreplay.forge.ForgeConfigurator
import com.datadog.android.sessionreplay.internal.PrivacyHelper.Companion.INVALID_PRIVACY_LEVEL_ERROR
import com.datadog.android.sessionreplay.internal.async.RecordedDataQueueRefs
import com.datadog.android.sessionreplay.internal.recorder.SnapshotProducer.Companion.INVALID_PRIVACY_LEVEL_ERROR
import com.datadog.android.sessionreplay.model.MobileSegment
import com.datadog.android.sessionreplay.recorder.MappingContext
import com.datadog.android.sessionreplay.recorder.SystemInformation
Expand Down