diff --git a/features/dd-sdk-android-rum/src/main/kotlin/com/datadog/android/rum/internal/domain/RumContext.kt b/features/dd-sdk-android-rum/src/main/kotlin/com/datadog/android/rum/internal/domain/RumContext.kt index d40c93d211..f6e3fdcba0 100644 --- a/features/dd-sdk-android-rum/src/main/kotlin/com/datadog/android/rum/internal/domain/RumContext.kt +++ b/features/dd-sdk-android-rum/src/main/kotlin/com/datadog/android/rum/internal/domain/RumContext.kt @@ -26,11 +26,11 @@ internal data class RumContext( return mapOf( APPLICATION_ID to applicationId, SESSION_ID to sessionId, - SESSION_STATE to sessionState, + SESSION_STATE to sessionState.asString, VIEW_ID to viewId, VIEW_NAME to viewName, VIEW_URL to viewUrl, - VIEW_TYPE to viewType, + VIEW_TYPE to viewType.asString, ACTION_ID to actionId ) } @@ -52,23 +52,21 @@ internal data class RumContext( fun fromFeatureContext(featureContext: Map): RumContext { val applicationId = featureContext[APPLICATION_ID] as? String val sessionId = featureContext[SESSION_ID] as? String - val sessionState = featureContext[SESSION_STATE] as? RumSessionScope.State - ?: RumSessionScope.State.NOT_TRACKED + val sessionState = RumSessionScope.State.fromString(featureContext[SESSION_STATE] as? String) val viewId = featureContext[VIEW_ID] as? String val viewName = featureContext[VIEW_NAME] as? String val viewUrl = featureContext[VIEW_URL] as? String - val viewType = featureContext[VIEW_TYPE] as? RumViewScope.RumViewType - ?: RumViewScope.RumViewType.NONE + val viewType = RumViewScope.RumViewType.fromString(featureContext[VIEW_TYPE] as? String) val actionId = featureContext[ACTION_ID] as? String return RumContext( applicationId = applicationId ?: NULL_UUID, sessionId = sessionId ?: NULL_UUID, - sessionState = sessionState, + sessionState = sessionState ?: RumSessionScope.State.NOT_TRACKED, viewId = viewId, viewName = viewName, viewUrl = viewUrl, - viewType = viewType, + viewType = viewType ?: RumViewScope.RumViewType.NONE, actionId = actionId ) } diff --git a/features/dd-sdk-android-rum/src/main/kotlin/com/datadog/android/rum/internal/domain/scope/RumSessionScope.kt b/features/dd-sdk-android-rum/src/main/kotlin/com/datadog/android/rum/internal/domain/scope/RumSessionScope.kt index 760f370183..f9d046a886 100644 --- a/features/dd-sdk-android-rum/src/main/kotlin/com/datadog/android/rum/internal/domain/scope/RumSessionScope.kt +++ b/features/dd-sdk-android-rum/src/main/kotlin/com/datadog/android/rum/internal/domain/scope/RumSessionScope.kt @@ -70,10 +70,16 @@ internal class RumSessionScope( } } - enum class State { - NOT_TRACKED, - TRACKED, - EXPIRED + enum class State(val asString: String) { + NOT_TRACKED("NOT_TRACKED"), + TRACKED("TRACKED"), + EXPIRED("EXPIRED"); + + companion object { + fun fromString(string: String?): State? { + return values().firstOrNull { it.asString == string } + } + } } // region RumScope diff --git a/features/dd-sdk-android-rum/src/main/kotlin/com/datadog/android/rum/internal/domain/scope/RumViewScope.kt b/features/dd-sdk-android-rum/src/main/kotlin/com/datadog/android/rum/internal/domain/scope/RumViewScope.kt index 025a624456..3dfc1c3f62 100644 --- a/features/dd-sdk-android-rum/src/main/kotlin/com/datadog/android/rum/internal/domain/scope/RumViewScope.kt +++ b/features/dd-sdk-android-rum/src/main/kotlin/com/datadog/android/rum/internal/domain/scope/RumViewScope.kt @@ -1014,11 +1014,17 @@ internal open class RumViewScope( return stopped && activeResourceScopes.isEmpty() && (pending <= 0L) } - enum class RumViewType { - NONE, - FOREGROUND, - BACKGROUND, - APPLICATION_LAUNCH + enum class RumViewType(val asString: String) { + NONE("NONE"), + FOREGROUND("FOREGROUND"), + BACKGROUND("BACKGROUND"), + APPLICATION_LAUNCH("APPLICATION_LAUNCH"); + + companion object { + fun fromString(string: String?): RumViewType? { + return values().firstOrNull { it.asString == string } + } + } } // endregion diff --git a/features/dd-sdk-android-rum/src/test/kotlin/com/datadog/android/rum/internal/domain/scope/RumSessionScopeTest.kt b/features/dd-sdk-android-rum/src/test/kotlin/com/datadog/android/rum/internal/domain/scope/RumSessionScopeTest.kt index 5e2742df9a..4eb6d3bb7f 100644 --- a/features/dd-sdk-android-rum/src/test/kotlin/com/datadog/android/rum/internal/domain/scope/RumSessionScopeTest.kt +++ b/features/dd-sdk-android-rum/src/test/kotlin/com/datadog/android/rum/internal/domain/scope/RumSessionScopeTest.kt @@ -130,7 +130,7 @@ internal class RumSessionScopeTest { assertThat(rumContext["application_id"]).isEqualTo(expectedContext.applicationId) assertThat(rumContext["session_id"]).isEqualTo(expectedContext.sessionId) - assertThat(rumContext["session_state"]).isEqualTo(expectedContext.sessionState) + assertThat(rumContext["session_state"]).isEqualTo(expectedContext.sessionState.asString) } } diff --git a/features/dd-sdk-android-rum/src/test/kotlin/com/datadog/android/rum/internal/domain/scope/RumViewScopeTest.kt b/features/dd-sdk-android-rum/src/test/kotlin/com/datadog/android/rum/internal/domain/scope/RumViewScopeTest.kt index d68a1b41b0..2e6f019d98 100644 --- a/features/dd-sdk-android-rum/src/test/kotlin/com/datadog/android/rum/internal/domain/scope/RumViewScopeTest.kt +++ b/features/dd-sdk-android-rum/src/test/kotlin/com/datadog/android/rum/internal/domain/scope/RumViewScopeTest.kt @@ -388,7 +388,7 @@ internal class RumViewScopeTest { function.invoke(acc) acc } - assertThat(rumContext["view_type"]).isEqualTo(fakeViewEventType) + assertThat(rumContext["view_type"]).isEqualTo(fakeViewEventType.asString) } } @@ -432,8 +432,7 @@ internal class RumViewScopeTest { function.invoke(acc) acc } - assertThat(rumContext["view_type"]) - .isEqualTo(RumViewScope.RumViewType.NONE) + assertThat(rumContext["view_type"]).isEqualTo(RumViewScope.RumViewType.NONE.asString) } } @@ -458,8 +457,7 @@ internal class RumViewScopeTest { ) val rumContext = mutableMapOf() lastValue.invoke(rumContext) - assertThat(rumContext["view_type"]) - .isEqualTo(RumViewScope.RumViewType.FOREGROUND) + assertThat(rumContext["view_type"]).isEqualTo(RumViewScope.RumViewType.FOREGROUND.asString) } } @@ -511,16 +509,11 @@ internal class RumViewScopeTest { acc } - assertThat(rumContext["view_type"]) - .isEqualTo(expectedViewType) - assertThat(rumContext["view_name"]) - .isEqualTo(anotherScope.getRumContext().viewName) - assertThat(rumContext["view_id"]) - .isEqualTo(anotherScope.getRumContext().viewId) - assertThat(rumContext["view_url"]) - .isEqualTo(anotherScope.getRumContext().viewUrl) - assertThat(rumContext["action_id"]) - .isEqualTo(anotherScope.getRumContext().actionId) + assertThat(rumContext["view_type"]).isEqualTo(expectedViewType.asString) + assertThat(rumContext["view_name"]).isEqualTo(anotherScope.getRumContext().viewName) + assertThat(rumContext["view_id"]).isEqualTo(anotherScope.getRumContext().viewId) + assertThat(rumContext["view_url"]).isEqualTo(anotherScope.getRumContext().viewUrl) + assertThat(rumContext["action_id"]).isEqualTo(anotherScope.getRumContext().actionId) } mockInternalLogger.verifyLog( InternalLogger.Level.DEBUG, @@ -560,8 +553,7 @@ internal class RumViewScopeTest { acc } - assertThat(rumContext["view_type"]) - .isEqualTo(RumViewScope.RumViewType.NONE) + assertThat(rumContext["view_type"]).isEqualTo(RumViewScope.RumViewType.NONE.asString) assertThat(rumContext["view_name"]).isNull() assertThat(rumContext["view_id"]).isNull() assertThat(rumContext["view_url"]).isNull() @@ -603,16 +595,11 @@ internal class RumViewScopeTest { acc } - assertThat(rumContext["view_type"]) - .isEqualTo(RumViewScope.RumViewType.NONE) - assertThat(rumContext["view_name"]) - .isNull() - assertThat(rumContext["view_id"]) - .isNull() - assertThat(rumContext["view_url"]) - .isNull() - assertThat(rumContext["action_id"]) - .isNull() + assertThat(rumContext["view_type"]).isEqualTo(RumViewScope.RumViewType.NONE.asString) + assertThat(rumContext["view_name"]).isNull() + assertThat(rumContext["view_id"]).isNull() + assertThat(rumContext["view_url"]).isNull() + assertThat(rumContext["action_id"]).isNull() } mockInternalLogger.verifyLog( @@ -707,7 +694,7 @@ internal class RumViewScopeTest { function.invoke(acc) acc } - assertThat(rumContext["view_type"]).isEqualTo(viewType) + assertThat(rumContext["view_type"]).isEqualTo(viewType.asString) } } @@ -764,7 +751,7 @@ internal class RumViewScopeTest { function.invoke(acc) acc } - assertThat(rumContext["view_type"]).isEqualTo(viewType) + assertThat(rumContext["view_type"]).isEqualTo(viewType.asString) } }