-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
RUMM-2421 Processor - process FullSnapshotRecords and dispatch to per…
…sister
- Loading branch information
Showing
25 changed files
with
1,108 additions
and
15 deletions.
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
...rc/main/kotlin/com/datadog/android/sessionreplay/internal/SessionReplayContextProvider.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* | ||
* 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.rum.GlobalRum | ||
import com.datadog.android.sessionreplay.utils.RumContextProvider | ||
|
||
internal class SessionReplayContextProvider : RumContextProvider { | ||
override fun getRumContext(): com.datadog.android.sessionreplay.utils.SessionReplayRumContext { | ||
return GlobalRum.getRumContext().let { | ||
com.datadog.android.sessionreplay.utils.SessionReplayRumContext( | ||
applicationId = it.applicationId, | ||
sessionId = it.sessionId, | ||
viewId = it.viewId | ||
?: com.datadog.android.rum.internal.domain.RumContext.NULL_UUID | ||
) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
...est/kotlin/com/datadog/android/sessionreplay/internal/SessionReplayContextProviderTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/* | ||
* 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.rum.GlobalRum | ||
import com.datadog.android.rum.internal.domain.RumContext | ||
import com.datadog.android.utils.config.GlobalRumMonitorTestConfiguration | ||
import com.datadog.android.utils.forge.Configurator | ||
import com.datadog.tools.unit.annotations.TestConfigurationsProvider | ||
import com.datadog.tools.unit.extensions.TestConfigurationExtension | ||
import com.datadog.tools.unit.extensions.config.TestConfiguration | ||
import fr.xgouchet.elmyr.junit5.ForgeConfiguration | ||
import fr.xgouchet.elmyr.junit5.ForgeExtension | ||
import java.util.UUID | ||
import org.assertj.core.api.Assertions.assertThat | ||
import org.junit.jupiter.api.BeforeEach | ||
import org.junit.jupiter.api.Test | ||
import org.junit.jupiter.api.extension.ExtendWith | ||
import org.junit.jupiter.api.extension.Extensions | ||
import org.mockito.junit.jupiter.MockitoExtension | ||
import org.mockito.junit.jupiter.MockitoSettings | ||
import org.mockito.quality.Strictness | ||
|
||
@Extensions( | ||
ExtendWith(MockitoExtension::class), | ||
ExtendWith(ForgeExtension::class), | ||
ExtendWith(TestConfigurationExtension::class) | ||
) | ||
@MockitoSettings(strictness = Strictness.LENIENT) | ||
@ForgeConfiguration(Configurator::class) | ||
internal class SessionReplayContextProviderTest { | ||
|
||
lateinit var testedSessionReplayContextProvider: SessionReplayContextProvider | ||
|
||
@BeforeEach | ||
fun `set up`() { | ||
testedSessionReplayContextProvider = SessionReplayContextProvider() | ||
} | ||
|
||
@Test | ||
fun `M provide a valid Rum context W getRumContext()`() { | ||
// When | ||
rumMonitor.context = rumMonitor.context.copy(viewId = UUID.randomUUID().toString()) | ||
GlobalRum.updateRumContext(rumMonitor.context) | ||
val context = testedSessionReplayContextProvider.getRumContext() | ||
|
||
// Then | ||
assertThat(context.applicationId).isEqualTo(rumMonitor.context.applicationId) | ||
assertThat(context.sessionId).isEqualTo(rumMonitor.context.sessionId) | ||
assertThat(context.viewId).isEqualTo(rumMonitor.context.viewId) | ||
} | ||
|
||
@Test | ||
fun `M provide an invalid Rum context W getRumContext() { RUM not initialized }`() { | ||
// Given | ||
GlobalRum.updateRumContext(RumContext()) | ||
|
||
// When | ||
val context = testedSessionReplayContextProvider.getRumContext() | ||
|
||
// Then | ||
assertThat(context.applicationId).isEqualTo(RumContext.NULL_UUID) | ||
assertThat(context.sessionId).isEqualTo(RumContext.NULL_UUID) | ||
assertThat(context.viewId).isEqualTo(RumContext.NULL_UUID) | ||
} | ||
|
||
companion object { | ||
|
||
val rumMonitor = GlobalRumMonitorTestConfiguration() | ||
|
||
@TestConfigurationsProvider | ||
@JvmStatic | ||
fun getTestConfigurations(): List<TestConfiguration> { | ||
return listOf(rumMonitor) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
...sion-replay/src/main/kotlin/com/datadog/android/sessionreplay/processor/EnrichedRecord.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* 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.processor | ||
|
||
import com.datadog.android.sessionreplay.model.MobileSegment | ||
import com.google.gson.JsonArray | ||
import com.google.gson.JsonObject | ||
|
||
internal data class EnrichedRecord( | ||
val applicationId: String, | ||
val sessionId: String, | ||
val viewId: String, | ||
val records: List<MobileSegment.MobileRecord> | ||
) { | ||
|
||
fun toJson(): String { | ||
val json = JsonObject() | ||
json.addProperty(APPLICATION_ID_KEY, applicationId) | ||
json.addProperty(SESSION_ID_KEY, sessionId) | ||
json.addProperty(VIEW_ID_KEY, viewId) | ||
val recordsJsonArray = JsonArray() | ||
records.map { it.toJson() } | ||
.fold(recordsJsonArray) { acc, jsonElement -> | ||
acc.add(jsonElement) | ||
acc | ||
} | ||
json.add(RECORD_KEY, recordsJsonArray) | ||
return json.toString() | ||
} | ||
|
||
companion object { | ||
const val APPLICATION_ID_KEY = "application_id" | ||
const val SESSION_ID_KEY = "session_id" | ||
const val VIEW_ID_KEY = "view_id" | ||
const val RECORD_KEY = "records" | ||
} | ||
} |
Oops, something went wrong.