Skip to content

Commit 2c00192

Browse files
Simplify activeView and rumContext
1 parent 2182f07 commit 2c00192

File tree

6 files changed

+79
-115
lines changed

6 files changed

+79
-115
lines changed

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,8 @@ internal class RumSessionScope(
153153

154154
val actualWriter = if (sessionState == State.TRACKED) writer else noOpWriter
155155

156+
val rumContext = activeView?.getRumContext() ?: getRumContext()
157+
156158
when (event) {
157159
is RumRawEvent.AppStartTTIDEvent -> {
158160
if (sessionState == State.TRACKED) {
@@ -161,9 +163,8 @@ internal class RumSessionScope(
161163
datadogContext = datadogContext,
162164
writeScope = writeScope,
163165
writer = actualWriter,
164-
rumContext = getRumContext(),
165-
customAttributes = getCustomAttributes(),
166-
activeView = activeView
166+
rumContext = rumContext,
167+
customAttributes = getCustomAttributes()
167168
)
168169
}
169170
}
@@ -179,9 +180,8 @@ internal class RumSessionScope(
179180
datadogContext = datadogContext,
180181
writeScope = writeScope,
181182
writer = actualWriter,
182-
rumContext = getRumContext(),
183-
customAttributes = getCustomAttributes(),
184-
activeView = activeView
183+
rumContext = rumContext,
184+
customAttributes = getCustomAttributes()
185185
)
186186
}
187187
}

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

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ internal class RumVitalAppLaunchEventHelper(
3333
datadogContext: DatadogContext,
3434
eventAttributes: Map<String, Any?>,
3535
customAttributes: Map<String, Any?>,
36-
view: RumViewScope?,
3736
hasReplay: Boolean?,
3837
rumContext: RumContext,
3938
durationNs: Long,
@@ -62,6 +61,20 @@ internal class RumVitalAppLaunchEventHelper(
6261
val displayInfo = displayInfoProvider.getState()
6362
val user = datadogContext.userInfo
6463

64+
val viewId = rumContext.viewId
65+
val viewUrl = rumContext.viewUrl
66+
67+
val view = if (viewId != null && viewUrl != null) {
68+
RumVitalAppLaunchEvent.RumVitalAppLaunchEventView(
69+
id = viewId,
70+
referrer = null,
71+
url = viewUrl,
72+
name = rumContext.viewName
73+
)
74+
} else {
75+
null
76+
}
77+
6578
return RumVitalAppLaunchEvent(
6679
date = timestampMs,
6780
context = RumVitalAppLaunchEvent.Context(
@@ -85,14 +98,7 @@ internal class RumVitalAppLaunchEventHelper(
8598
type = sessionType,
8699
hasReplay = hasReplay
87100
),
88-
view = view?.let {
89-
RumVitalAppLaunchEvent.RumVitalAppLaunchEventView(
90-
id = it.viewId,
91-
referrer = null,
92-
url = it.url,
93-
name = it.key.name
94-
)
95-
},
101+
view = view,
96102
source = RumVitalAppLaunchEvent.RumVitalAppLaunchEventSource.tryFromSource(
97103
source = datadogContext.source,
98104
internalLogger = internalLogger

features/dd-sdk-android-rum/src/main/kotlin/com/datadog/android/rum/internal/startup/RumSessionScopeStartupManager.kt

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import com.datadog.android.api.storage.DataWriter
1313
import com.datadog.android.core.InternalSdkCore
1414
import com.datadog.android.rum.internal.domain.RumContext
1515
import com.datadog.android.rum.internal.domain.scope.RumRawEvent
16-
import com.datadog.android.rum.internal.domain.scope.RumViewScope
1716
import com.datadog.android.rum.internal.domain.scope.RumVitalAppLaunchEventHelper
1817
import com.datadog.android.rum.internal.utils.newRumEventWriteOperation
1918
import com.datadog.android.rum.model.RumVitalAppLaunchEvent
@@ -27,8 +26,7 @@ internal interface RumSessionScopeStartupManager {
2726
writeScope: EventWriteScope,
2827
writer: DataWriter<Any>,
2928
rumContext: RumContext,
30-
customAttributes: Map<String, Any?>,
31-
activeView: RumViewScope?
29+
customAttributes: Map<String, Any?>
3230
)
3331

3432
fun onTTFDEvent(
@@ -37,8 +35,7 @@ internal interface RumSessionScopeStartupManager {
3735
writeScope: EventWriteScope,
3836
writer: DataWriter<Any>,
3937
rumContext: RumContext,
40-
customAttributes: Map<String, Any?>,
41-
activeView: RumViewScope?
38+
customAttributes: Map<String, Any?>
4239
)
4340

4441
companion object {
@@ -87,8 +84,7 @@ internal class RumSessionScopeStartupManagerImpl(
8784
writeScope: EventWriteScope,
8885
writer: DataWriter<Any>,
8986
rumContext: RumContext,
90-
customAttributes: Map<String, Any?>,
91-
activeView: RumViewScope?
87+
customAttributes: Map<String, Any?>
9288
) {
9389
ttidReportedForScenario = true
9490

@@ -109,7 +105,6 @@ internal class RumSessionScopeStartupManagerImpl(
109105
datadogContext = datadogContext,
110106
eventAttributes = emptyMap(),
111107
customAttributes = customAttributes,
112-
view = activeView,
113108
hasReplay = null,
114109
rumContext = rumContext,
115110
durationNs = event.info.durationNs,
@@ -130,8 +125,7 @@ internal class RumSessionScopeStartupManagerImpl(
130125
rumContext = rumContext,
131126
customAttributes = customAttributes,
132127
durationNs = event.info.durationNs,
133-
scenario = event.info.scenario,
134-
activeView = activeView
128+
scenario = event.info.scenario
135129
)
136130
}
137131
}
@@ -143,8 +137,7 @@ internal class RumSessionScopeStartupManagerImpl(
143137
writeScope: EventWriteScope,
144138
writer: DataWriter<Any>,
145139
rumContext: RumContext,
146-
customAttributes: Map<String, Any?>,
147-
activeView: RumViewScope?
140+
customAttributes: Map<String, Any?>
148141
) {
149142
if (ttfdReportedForSession) {
150143
return
@@ -191,8 +184,7 @@ internal class RumSessionScopeStartupManagerImpl(
191184
rumContext = rumContext,
192185
customAttributes = customAttributes,
193186
durationNs = event.eventTime.nanoTime - scenario.initialTime.nanoTime,
194-
scenario = scenario,
195-
activeView = activeView
187+
scenario = scenario
196188
)
197189
}
198190

@@ -203,16 +195,14 @@ internal class RumSessionScopeStartupManagerImpl(
203195
rumContext: RumContext,
204196
customAttributes: Map<String, Any?>,
205197
durationNs: Long,
206-
scenario: RumStartupScenario,
207-
activeView: RumViewScope?
198+
scenario: RumStartupScenario
208199
) {
209200
sdkCore.newRumEventWriteOperation(datadogContext, writeScope, writer) {
210201
rumVitalAppLaunchEventHelper.newVitalAppLaunchEvent(
211202
timestampMs = scenario.initialTime.timestamp + sdkCore.time.serverTimeOffsetMs,
212203
datadogContext = datadogContext,
213204
eventAttributes = emptyMap(),
214205
customAttributes = customAttributes,
215-
view = activeView,
216206
hasReplay = null,
217207
rumContext = rumContext,
218208
durationNs = durationNs,

features/dd-sdk-android-rum/src/test/kotlin/com/datadog/android/rum/assertj/VitalAppLaunchEventAssert.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,23 +105,23 @@ internal class VitalAppLaunchEventAssert(
105105
.isNull()
106106
}
107107

108-
fun hasViewId(expectedId: String) = apply {
108+
fun hasViewId(expectedId: String?) = apply {
109109
assertThat(actual.view?.id)
110110
.overridingErrorMessage(
111111
"Expected event data to have view.id $expectedId but was ${actual.view?.id}"
112112
)
113113
.isEqualTo(expectedId)
114114
}
115115

116-
fun hasName(expected: String) = apply {
116+
fun hasName(expected: String?) = apply {
117117
assertThat(actual.view?.name)
118118
.overridingErrorMessage(
119119
"Expected event data to have view.name $expected but was ${actual.view?.name}"
120120
)
121121
.isEqualTo(expected)
122122
}
123123

124-
fun hasUrl(expected: String) = apply {
124+
fun hasUrl(expected: String?) = apply {
125125
assertThat(actual.view?.url)
126126
.overridingErrorMessage(
127127
"Expected event data to have view.url $expected but was ${actual.view?.url}"

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1543,8 +1543,7 @@ internal class RumSessionScopeTest {
15431543
writeScope = mockEventWriteScope,
15441544
writer = mockWriter,
15451545
rumContext = rumContext,
1546-
customAttributes = fakeParentAttributes,
1547-
activeView = testedScope.activeView
1546+
customAttributes = fakeParentAttributes
15481547
)
15491548

15501549
verifyNoMoreInteractions(mockRumSessionScopeStartupManager)
@@ -1579,8 +1578,7 @@ internal class RumSessionScopeTest {
15791578
writeScope = mockEventWriteScope,
15801579
writer = mockWriter,
15811580
rumContext = rumContext,
1582-
customAttributes = fakeParentAttributes,
1583-
activeView = testedScope.activeView
1581+
customAttributes = fakeParentAttributes
15841582
)
15851583

15861584
verifyNoMoreInteractions(mockRumSessionScopeStartupManager)

0 commit comments

Comments
 (0)