Skip to content

Commit

Permalink
Merge pull request #889 from embrace-io/remove-user-info
Browse files Browse the repository at this point in the history
Remove legacy user info field
  • Loading branch information
fractalwrench authored May 30, 2024
2 parents 53a33ef + efdc127 commit 203ee02
Show file tree
Hide file tree
Showing 20 changed files with 56 additions and 69 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,6 @@ internal fun verifySessionMessage(sessionMessage: SessionMessage) {
assertNotNull(sessionMessage.deviceInfo)

if (sessionMessage.session.messageType == "en") {
assertNotNull(sessionMessage.userInfo)
assertNotNull(sessionMessage.performanceInfo)
}
}
Expand All @@ -231,7 +230,6 @@ internal fun verifyBgActivityMessage(message: SessionMessage) {
assertNotNull(message.deviceInfo)

if (message.session.messageType == "en") {
assertNotNull(message.userInfo)
assertNotNull(message.performanceInfo)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ package io.embrace.android.embracesdk.features

import androidx.test.ext.junit.runners.AndroidJUnit4
import io.embrace.android.embracesdk.IntegrationTestRule
import io.embrace.android.embracesdk.config.remote.OTelRemoteConfig
import io.embrace.android.embracesdk.config.remote.RemoteConfig
import io.embrace.android.embracesdk.fakes.fakeOTelBehavior
import io.embrace.android.embracesdk.payload.SessionMessage
import io.embrace.android.embracesdk.payload.UserInfo
import io.embrace.android.embracesdk.recordSession
Expand All @@ -16,7 +19,11 @@ internal class PersonaFeaturesTest {
@JvmField
val testRule: IntegrationTestRule = IntegrationTestRule(
harnessSupplier = {
IntegrationTestRule.newHarness(startImmediately = false)
IntegrationTestRule.Harness(startImmediately = false).apply {
overriddenConfigService.oTelBehavior = fakeOTelBehavior {
RemoteConfig(oTelConfig = OTelRemoteConfig(isDevEnabled = true))
}
}
}
)

Expand Down Expand Up @@ -57,7 +64,8 @@ internal class PersonaFeaturesTest {
private fun SessionMessage.assertPersonaDoesNotExist(persona: String) = assertPersona(false, this, persona)

private fun assertPersona(exists: Boolean, session: SessionMessage, persona: String) {
assertEquals(exists, session.userInfo?.personas?.find { it == persona } != null)
val personas = checkNotNull(session.metadata).personas
assertEquals(exists, personas?.find { it == persona } != null)
assertEquals(
exists,
testRule.harness.overriddenAndroidServicesModule.preferencesService.userPersonas?.find { it == persona } != null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ package io.embrace.android.embracesdk.features

import androidx.test.ext.junit.runners.AndroidJUnit4
import io.embrace.android.embracesdk.IntegrationTestRule
import io.embrace.android.embracesdk.config.remote.OTelRemoteConfig
import io.embrace.android.embracesdk.config.remote.RemoteConfig
import io.embrace.android.embracesdk.fakes.fakeOTelBehavior
import io.embrace.android.embracesdk.payload.SessionMessage
import io.embrace.android.embracesdk.prefs.PreferencesService
import io.embrace.android.embracesdk.recordSession
Expand All @@ -17,7 +20,11 @@ internal class UserFeaturesTest {
@JvmField
val testRule: IntegrationTestRule = IntegrationTestRule(
harnessSupplier = {
IntegrationTestRule.newHarness(startImmediately = false)
IntegrationTestRule.Harness(startImmediately = false).apply {
overriddenConfigService.oTelBehavior = fakeOTelBehavior {
RemoteConfig(oTelConfig = OTelRemoteConfig(isDevEnabled = true))
}
}
}
)

Expand Down Expand Up @@ -56,11 +63,11 @@ internal class UserFeaturesTest {
}

private fun SessionMessage.assertUserInfo(preferencesService: PreferencesService, userId: String?, userName: String?, email: String?) {
assertEquals(userId, userInfo?.userId)
assertEquals(userId, checkNotNull(metadata).userId)
assertEquals(userId, preferencesService.userIdentifier)
assertEquals(userName, userInfo?.username)
assertEquals(userName, metadata.username)
assertEquals(userName, preferencesService.username)
assertEquals(email, userInfo?.email)
assertEquals(email, metadata.email)
assertEquals(email, preferencesService.userEmailAddress)
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.embrace.android.embracesdk.gating

import io.embrace.android.embracesdk.internal.payload.EnvelopeMetadata
import io.embrace.android.embracesdk.payload.SessionMessage

internal class SessionSanitizerFacade(
Expand All @@ -9,15 +10,27 @@ internal class SessionSanitizerFacade(

fun getSanitizedMessage(): SessionMessage {
val sanitizedSession = SessionSanitizer(sessionMessage.session, components).sanitize()
val sanitizedUserInfo = UserInfoSanitizer(sessionMessage.userInfo, components).sanitize()
val sanitizedPerformanceInfo = PerformanceInfoSanitizer(sessionMessage.performanceInfo, components).sanitize()
val sanitizedSpans = SpanSanitizer(sessionMessage.spans, components).sanitize()

return sessionMessage.copy(
session = sanitizedSession,
userInfo = sanitizedUserInfo,
performanceInfo = sanitizedPerformanceInfo,
spans = sanitizedSpans
spans = sanitizedSpans,
metadata = sanitizeMetadata(components)
)
}

private fun sanitizeMetadata(enabledComponents: Set<String>): EnvelopeMetadata {
if (sessionMessage.metadata == null) {
return EnvelopeMetadata()
}
if (!shouldSendUserPersonas(enabledComponents)) {
return sessionMessage.metadata.copy(personas = null)
}
return sessionMessage.metadata
}

private fun shouldSendUserPersonas(enabledComponents: Set<String>) =
enabledComponents.contains(SessionGatingKeys.USER_PERSONAS)
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ internal class SessionModuleImpl(
dataContainerModule.performanceInfoService,
dataCaptureServiceModule.webviewService,
nativeModule.nativeThreadSamplerService,
essentialServiceModule.userService,
androidServicesModule.preferencesService,
openTelemetryModule.spanRepository,
openTelemetryModule.spanSink,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,6 @@ internal data class SessionMessage @JvmOverloads internal constructor(
@Json(name = "s")
val session: Session,

/**
* The user information.
*/
@Json(name = "u")
val userInfo: UserInfo? = null,

/**
* The app information.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import io.embrace.android.embracesdk.capture.PerformanceInfoService
import io.embrace.android.embracesdk.capture.internal.errors.InternalErrorService
import io.embrace.android.embracesdk.capture.metadata.MetadataService
import io.embrace.android.embracesdk.capture.startup.StartupService
import io.embrace.android.embracesdk.capture.user.UserService
import io.embrace.android.embracesdk.capture.webview.WebViewService
import io.embrace.android.embracesdk.event.EventService
import io.embrace.android.embracesdk.event.LogMessageService
Expand All @@ -35,7 +34,6 @@ internal class V1PayloadMessageCollator(
private val performanceInfoService: PerformanceInfoService,
private val webViewService: WebViewService,
private val nativeThreadSamplerService: NativeThreadSamplerService?,
private val userService: UserService,
private val preferencesService: PreferencesService,
private val spanRepository: SpanRepository,
private val spanSink: SpanSink,
Expand Down Expand Up @@ -178,7 +176,6 @@ internal class V1PayloadMessageCollator(

return SessionMessage(
session = finalPayload,
userInfo = captureDataSafely(logger, userService::getUserInfo),
appInfo = captureDataSafely(logger, metadataService::getAppInfo),
deviceInfo = captureDataSafely(logger, metadataService::getDeviceInfo),
performanceInfo = captureDataSafely(logger) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import io.embrace.android.embracesdk.gating.SessionGatingKeys.SESSION_PROPERTIES
import io.embrace.android.embracesdk.gating.SessionGatingKeys.SESSION_USER_TERMINATION
import io.embrace.android.embracesdk.gating.SessionGatingKeys.STARTUP_MOMENT
import io.embrace.android.embracesdk.gating.SessionGatingKeys.USER_PERSONAS
import io.embrace.android.embracesdk.internal.payload.EnvelopeMetadata
import io.embrace.android.embracesdk.internal.serialization.EmbraceSerializer
import io.embrace.android.embracesdk.internal.utils.Uuid
import io.embrace.android.embracesdk.logging.EmbLogger
Expand Down Expand Up @@ -357,18 +358,18 @@ internal class EmbraceGatingServiceV1PayloadTest {

@Test
fun `test gate user personas for Session`() {
val userInfo = UserInfo(personas = setOf("persona"))

val sessionMessage = SessionMessage(
session = fakeSession(),
userInfo = userInfo,
performanceInfo = PerformanceInfo()
metadata = EnvelopeMetadata(
personas = setOf("persona")
),
performanceInfo = PerformanceInfo(),
)

cfg = buildCustomRemoteConfig(setOf(USER_PERSONAS), null)

val sanitizedMessage = gatingService.gateSessionMessage(sessionMessage)
assertNotNull(sanitizedMessage.userInfo?.personas)
assertNotNull(sanitizedMessage.metadata?.personas)
}

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,30 +1,31 @@
package io.embrace.android.embracesdk

import io.embrace.android.embracesdk.internal.payload.EnvelopeMetadata
import io.embrace.android.embracesdk.internal.spans.EmbraceSpanData
import io.embrace.android.embracesdk.payload.AppInfo
import io.embrace.android.embracesdk.payload.DeviceInfo
import io.embrace.android.embracesdk.payload.DiskUsage
import io.embrace.android.embracesdk.payload.PerformanceInfo
import io.embrace.android.embracesdk.payload.Session
import io.embrace.android.embracesdk.payload.SessionMessage
import io.embrace.android.embracesdk.payload.UserInfo
import io.opentelemetry.api.trace.StatusCode

internal fun fakeBackgroundActivityMessage(): SessionMessage {
val backgroundActivity = fakeBackgroundActivity()
val userInfo = UserInfo("fake-user-id")
val appInfo = AppInfo("fake-app-id")
val deviceInfo = DeviceInfo("fake-manufacturer")
val spans = listOf(EmbraceSpanData("fake-span-id", "", "", "", 0, 0, StatusCode.OK))
val perfInfo = PerformanceInfo(DiskUsage(1, 2))

return SessionMessage(
backgroundActivity,
userInfo,
appInfo,
deviceInfo,
perfInfo,
spans
spans,
metadata = EnvelopeMetadata(
userId = "fake-user-id"
)
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import io.embrace.android.embracesdk.fakes.fakePerformanceInfo
import io.embrace.android.embracesdk.fakes.fakeSession
import io.embrace.android.embracesdk.gating.SessionGatingKeys
import io.embrace.android.embracesdk.gating.SessionSanitizerFacade
import io.embrace.android.embracesdk.internal.payload.EnvelopeMetadata
import io.embrace.android.embracesdk.payload.AppInfo
import io.embrace.android.embracesdk.payload.DeviceInfo
import io.embrace.android.embracesdk.payload.Orientation
import io.embrace.android.embracesdk.payload.SessionMessage
import io.embrace.android.embracesdk.payload.UserInfo
import org.junit.Assert.assertNotNull
import org.junit.Assert.assertNull
import org.junit.Test
Expand All @@ -17,11 +17,6 @@ internal class SessionSanitizerFacadeTest {

private val sessionPerformanceInfo = fakePerformanceInfo()

private val userInfo = UserInfo(
personas = setOf("personas"),
email = "example@embrace.com"
)

private val session = fakeSession().copy(
properties = mapOf("example" to "example"),
orientations = listOf(Orientation(0, 0L)),
Expand All @@ -38,10 +33,13 @@ internal class SessionSanitizerFacadeTest {

private val sessionMessage = SessionMessage(
session = session,
userInfo = userInfo,
appInfo = AppInfo(),
deviceInfo = DeviceInfo(),
performanceInfo = sessionPerformanceInfo
performanceInfo = sessionPerformanceInfo,
metadata = EnvelopeMetadata(
email = "example@embrace.com",
personas = setOf("personas")
)
)

private val enabledComponents = setOf(
Expand Down Expand Up @@ -70,7 +68,7 @@ internal class SessionSanitizerFacadeTest {
val sanitizedMessage =
SessionSanitizerFacade(sessionMessage, enabledComponents).getSanitizedMessage()

assertNotNull(sanitizedMessage.userInfo?.personas)
assertNotNull(sanitizedMessage.metadata?.personas)

assertNotNull(sanitizedMessage.session.properties)
assertNotNull(sanitizedMessage.session.orientations)
Expand All @@ -96,7 +94,7 @@ internal class SessionSanitizerFacadeTest {
val sanitizedMessage =
SessionSanitizerFacade(sessionMessage, setOf()).getSanitizedMessage()

assertNull(sanitizedMessage.userInfo?.personas)
assertNull(sanitizedMessage.metadata?.personas)

assertNull(sanitizedMessage.session.properties)
assertNull(sanitizedMessage.session.orientations)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,13 @@ import org.junit.Test
internal class BackgroundActivityMessageTest {

private val backgroundActivity = fakeBackgroundActivity()
private val userInfo = UserInfo("fake-user-id")
private val appInfo = AppInfo("fake-app-id")
private val deviceInfo = DeviceInfo("fake-manufacturer")
private val spans = listOf(EmbraceSpanData("fake-span-id", "", "", "", 0, 0, StatusCode.OK))
private val perfInfo = PerformanceInfo(DiskUsage(1, 2))

private val info = SessionMessage(
backgroundActivity,
userInfo,
appInfo,
deviceInfo,
perfInfo,
Expand All @@ -40,7 +38,6 @@ internal class BackgroundActivityMessageTest {
assertNotNull(obj)

assertEquals(backgroundActivity.startTime, obj.session.startTime)
assertEquals(userInfo, obj.userInfo)
assertEquals(appInfo, obj.appInfo)
assertEquals(deviceInfo, obj.deviceInfo)
assertEquals(perfInfo, obj.performanceInfo)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import org.junit.Test
internal class SessionMessageTest {

private val session = fakeSession()
private val userInfo = UserInfo("fake-user-id", "fake-user-name")
private val appInfo = AppInfo("fake-app-version")
private val deviceInfo = DeviceInfo("fake-manufacturer")
private val performanceInfo = PerformanceInfo(DiskUsage(150923409L, 509209823L))
Expand All @@ -40,7 +39,6 @@ internal class SessionMessageTest {

private val info = SessionMessage(
session,
userInfo,
appInfo,
deviceInfo,
performanceInfo,
Expand All @@ -58,7 +56,6 @@ internal class SessionMessageTest {
val obj = deserializeJsonFromResource<SessionMessage>("session_message_expected.json")
assertNotNull(obj)
assertEquals(session, obj.session)
assertEquals(userInfo, obj.userInfo)
assertEquals(appInfo, obj.appInfo)
assertEquals(deviceInfo, obj.deviceInfo)
assertEquals(performanceInfo, obj.performanceInfo)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,6 @@ internal class PayloadFactoryBaTest {
performanceInfoService,
FakeWebViewService(),
null,
userService,
preferencesService,
spanRepository,
spanSink,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,6 @@ internal class SessionHandlerTest {
performanceInfoService,
webViewService,
null,
userService,
preferencesService,
initModule.openTelemetryModule.spanRepository,
initModule.openTelemetryModule.spanSink,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import io.embrace.android.embracesdk.fakes.FakeMetadataService
import io.embrace.android.embracesdk.fakes.FakePerformanceInfoService
import io.embrace.android.embracesdk.fakes.FakePreferenceService
import io.embrace.android.embracesdk.fakes.FakeStartupService
import io.embrace.android.embracesdk.fakes.FakeUserService
import io.embrace.android.embracesdk.fakes.FakeWebViewService
import io.embrace.android.embracesdk.fakes.fakeCompletedAnrInterval
import io.embrace.android.embracesdk.fakes.fakeInProgressAnrInterval
Expand Down Expand Up @@ -61,7 +60,6 @@ internal class V1PayloadMessageCollatorTest {
gatingService = gatingService,
nativeThreadSamplerService = null,
webViewService = FakeWebViewService(),
userService = FakeUserService(),
preferencesService = FakePreferenceService(),
eventService = FakeEventService(),
logMessageService = FakeLogMessageService(),
Expand Down Expand Up @@ -205,7 +203,6 @@ internal class V1PayloadMessageCollatorTest {
private fun SessionMessage.verifyFinalFieldsPopulated(
payloadType: PayloadType
) {
assertNotNull(userInfo)
assertNotNull(appInfo)
assertNotNull(deviceInfo)
assertNotNull(performanceInfo)
Expand Down
Loading

0 comments on commit 203ee02

Please sign in to comment.