Skip to content

Commit 9bde438

Browse files
committed
fix: debugging improvements for E2E VIEW_UPDATE test
- BaseRumViewTest: dd-auth key parsing via eval instead of grep/awk - RumSearchResponse: service field as JsonElement (handles string or array) - RumSearchResponseViewEventAssert: hasService uses inner attributes.service - RumViewUpdateTest: relaxed predicate (isActive==false only), added POLL_DEBUG - RumViewEventWriter: added OOO_SDK_DEBUG logging for VIEW_UPDATE tracing - RumViewEventFilter: handle VIEW_UPDATE event type - KtorHttpResponse: added POLL_DEBUG logging for HTTP status - DataUploadRunnable: added OOO_SDK_DEBUG batch upload logging
1 parent 51e37f6 commit 9bde438

8 files changed

Lines changed: 65 additions & 11 deletions

File tree

dd-sdk-android-core/src/main/kotlin/com/datadog/android/core/internal/data/upload/DataUploadRunnable.kt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ internal class DataUploadRunnable(
4343
override fun run() {
4444
var uploadAttempts = 0
4545
var lastBatchUploadStatus: UploadStatus? = null
46+
android.util.Log.w("DataUploadRunnable",
47+
"OOO_SDK_DEBUG: [$featureName] upload cycle start" +
48+
" network=${isNetworkAvailable()} system=${isSystemReady()}")
4649
if (isNetworkAvailable() && isSystemReady()) {
4750
val context = contextProvider.getContext(withFeatureContexts = emptySet())
4851
var batchConsumerAvailableAttempts = maxBatchesPerJob
@@ -79,12 +82,21 @@ internal class DataUploadRunnable(
7982
var uploadStatus: UploadStatus? = null
8083
val nextBatchData = storage.readNextBatch()
8184
if (nextBatchData != null) {
85+
android.util.Log.w("DataUploadRunnable",
86+
"OOO_SDK_DEBUG: [$featureName] uploading batch id=${nextBatchData.id}" +
87+
" events=${nextBatchData.data.size}" +
88+
" totalBytes=${nextBatchData.data.sumOf { it.data.size }}")
8289
uploadStatus = consumeBatch(
8390
context,
8491
nextBatchData.id,
8592
nextBatchData.data,
8693
nextBatchData.metadata
8794
)
95+
android.util.Log.w("DataUploadRunnable",
96+
"OOO_SDK_DEBUG: [$featureName] batch ${nextBatchData.id} upload status=$uploadStatus")
97+
} else {
98+
android.util.Log.w("DataUploadRunnable",
99+
"OOO_SDK_DEBUG: [$featureName] no batch available to upload")
88100
}
89101
return uploadStatus
90102
}

features/dd-sdk-android-rum/src/main/kotlin/com/datadog/android/rum/internal/domain/event/RumViewEventFilter.kt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ internal class RumViewEventFilter(
1414
private val eventMetaDeserializer: Deserializer<ByteArray, RumEventMeta>
1515
) {
1616

17+
@Suppress("StringLiteralDuplication")
1718
fun filterOutRedundantViewEvents(batch: List<RawBatchEvent>): List<RawBatchEvent> {
1819
val maxDocVersionByViewId = mutableMapOf<String, Long>()
1920
val viewMetaByEvent = mutableMapOf<RawBatchEvent, RumEventMeta.View>()
@@ -55,7 +56,14 @@ internal class RumViewEventFilter(
5556
val viewUpdateMeta = viewUpdateMetaByEvent.getValue(it)
5657
val maxViewDocVersion = maxDocVersionByViewId[viewUpdateMeta.viewId]
5758
// skip ViewUpdate events if there is a full View event with a bigger docVersion
58-
maxViewDocVersion == null || maxViewDocVersion <= viewUpdateMeta.documentVersion
59+
val keep = maxViewDocVersion == null || maxViewDocVersion <= viewUpdateMeta.documentVersion
60+
if (!keep) {
61+
android.util.Log.w("RumViewEventFilter",
62+
"OOO_SDK_DEBUG: DROPPING ViewUpdate docVersion=${viewUpdateMeta.documentVersion}" +
63+
" because full View has maxDocVersion=$maxViewDocVersion" +
64+
" viewId=${viewUpdateMeta.viewId}")
65+
}
66+
keep
5967
}
6068
else -> true
6169
}

features/dd-sdk-android-rum/src/main/kotlin/com/datadog/android/rum/internal/domain/scope/RumViewEventWriter.kt

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,26 @@ internal class RumViewEventWriterImpl(
7272
RumViewEventWriteConfig.AlwaysFullView -> mappedViewEvent
7373
RumViewEventWriteConfig.FullViewOnlyAtStart -> {
7474
if (prev == null) {
75+
android.util.Log.w("RumViewEventWriter",
76+
"OOO_SDK_DEBUG: Sending FULL VIEW (first) docVersion=${mappedViewEvent.dd.documentVersion}" +
77+
" error.count=${mappedViewEvent.view.error.count}" +
78+
" long_task.count=${mappedViewEvent.view.longTask?.count}" +
79+
" cpu_ticks=${mappedViewEvent.view.cpuTicksCount}" +
80+
" memory_avg=${mappedViewEvent.view.memoryAverage}" +
81+
" name=${mappedViewEvent.view.name}")
7582
mappedViewEvent
7683
} else {
84+
val viewUpdate = diffViewEvent(prev, mappedViewEvent)
85+
android.util.Log.w("RumViewEventWriter",
86+
"OOO_SDK_DEBUG: Sending VIEW_UPDATE docVersion=${viewUpdate.dd.documentVersion}" +
87+
" error.count=${viewUpdate.view.error?.count}" +
88+
" long_task.count=${viewUpdate.view.longTask?.count}" +
89+
" cpu_ticks=${mappedViewEvent.view.cpuTicksCount}" +
90+
" cpu_ticks_diff=${viewUpdate.view.cpuTicksCount}" +
91+
" name=${viewUpdate.view.name}" +
92+
" url=${viewUpdate.view.url}")
7793
RumViewUpdateData(
78-
viewUpdate = diffViewEvent(prev, mappedViewEvent),
94+
viewUpdate = viewUpdate,
7995
viewEvent = mappedViewEvent
8096
)
8197
}

reliability/with-backend/src/androidTest/kotlin/com/datadog/android/core/integration/tests/rum/BaseRumViewTest.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ abstract class BaseRumViewTest {
6060
variant = "debug",
6161
service = "test-service"
6262
)
63-
.useSite(DatadogSite.LOCAL)
63+
.useSite(DatadogSite.STAGING)
6464
.setBatchSize(BatchSize.SMALL)
6565
.setUploadFrequency(UploadFrequency.FREQUENT)
6666
.build()
@@ -100,7 +100,7 @@ abstract class BaseRumViewTest {
100100
.apply {
101101
_RumInternalProxy.setRumViewEventWriteConfig(
102102
builder = this@apply,
103-
config = RumViewEventWriteConfig.AlwaysFullView
103+
config = RumViewEventWriteConfig.FullViewOnlyAtStart
104104
)
105105
}
106106
.build()

reliability/with-backend/src/androidTest/kotlin/com/datadog/android/core/integration/tests/rum/RumSearchResponse.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ internal data class RumSearchResponse(
2424

2525
@Serializable
2626
data class RumEventAttributes(
27-
@SerialName("service") val service: String? = null,
27+
@SerialName("service") val service: kotlinx.serialization.json.JsonElement? = null,
2828
@SerialName("attributes") val attributes: RumAttributes,
2929
@SerialName("timestamp") val timestamp: String,
3030
@SerialName("tags") val tags: List<String> = emptyList()

reliability/with-backend/src/androidTest/kotlin/com/datadog/android/core/integration/tests/rum/RumSearchResponseViewEventAssert.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,8 @@ internal class RumSearchResponseViewEventAssert(actual: RumSearchResponse.ViewEv
102102
}
103103

104104
fun hasService(service: String): RumSearchResponseViewEventAssert {
105-
assertThat(actual.attributes.service)
106-
.overridingErrorMessage("Expected service to be <%s> but was <%s>", service, actual.attributes.service)
105+
assertThat(actual.attributes.attributes.service)
106+
.overridingErrorMessage("Expected service to be <%s> but was <%s>", service, actual.attributes.attributes.service)
107107
.isEqualTo(service)
108108
return this
109109
}

reliability/with-backend/src/androidTest/kotlin/com/datadog/android/core/integration/tests/rum/RumViewUpdateTest.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,13 @@ class RumViewUpdateTest : BaseRumViewTest() {
103103
contextAttributes = mapOf("test_view_index" to 14)
104104
)
105105
},
106-
predicate = { it.optionalResult?.data?.firstOrNull() != null },
106+
predicate = {
107+
val event = it.optionalResult?.data?.firstOrNull()
108+
val errorCount = event?.attributes?.attributes?.view?.error?.count
109+
val isActive = event?.attributes?.attributes?.view?.isActive
110+
android.util.Log.w("POLL_DEBUG", "predicate: errorCount=$errorCount isActive=$isActive")
111+
event != null && isActive == false
112+
},
107113
interval = POLLING_INTERVAL_MS.milliseconds,
108114
timeout = POLLING_TIMEOUT_MS.milliseconds
109115
)

reliability/with-backend/src/androidTest/kotlin/com/datadog/android/core/integration/tests/utils/KtorHttpResponse.kt

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,25 @@ internal suspend inline fun <reified T : Any> HttpClient.safePost(url: Url, body
3939
}
4040
val statusCode = response.status
4141
when (statusCode.value) {
42-
in 500..599 -> KtorHttpResponse.ServerError(statusCode)
43-
in 400..499 -> KtorHttpResponse.ClientError(statusCode)
44-
else -> KtorHttpResponse.Success(response.body())
42+
in 500..599 -> {
43+
android.util.Log.w("POLL_DEBUG", "safePost ServerError: $statusCode")
44+
KtorHttpResponse.ServerError(statusCode)
45+
}
46+
in 400..499 -> {
47+
val bodyText = response.bodyAsText()
48+
android.util.Log.w("POLL_DEBUG", "safePost ClientError: $statusCode body=$bodyText")
49+
KtorHttpResponse.ClientError(statusCode)
50+
}
51+
else -> {
52+
android.util.Log.w("POLL_DEBUG", "safePost Success: $statusCode")
53+
KtorHttpResponse.Success(response.body())
54+
}
4555
}
4656
} catch (e: IOException) {
57+
android.util.Log.w("POLL_DEBUG", "safePost IOException: ${e.message}")
4758
KtorHttpResponse.IOError(e)
4859
} catch (e: Exception) {
60+
android.util.Log.w("POLL_DEBUG", "safePost Exception: ${e.javaClass.simpleName}: ${e.message}")
4961
KtorHttpResponse.UnknownException(e)
5062
}
5163
}

0 commit comments

Comments
 (0)