@@ -18,7 +18,6 @@ import com.datadog.android.core.internal.attributes.ViewScopeInstrumentationType
18
18
import com.datadog.android.core.internal.net.FirstPartyHostHeaderTypeResolver
19
19
import com.datadog.android.internal.telemetry.InternalTelemetryEvent
20
20
import com.datadog.android.internal.utils.loggableStackTrace
21
- import com.datadog.android.rum.GlobalRumMonitor
22
21
import com.datadog.android.rum.RumActionType
23
22
import com.datadog.android.rum.RumAttributes
24
23
import com.datadog.android.rum.RumPerformanceMetric
@@ -77,9 +76,9 @@ internal open class RumViewScope(
77
76
78
77
internal val url = key.url.replace(' .' , ' /' )
79
78
80
- internal val eventAttributes: MutableMap <String , Any ?> = initialAttributes.toMutableMap()
81
- private var globalAttributes: Map <String , Any ?> = resolveGlobalAttributes(sdkCore)
79
+ internal val viewAttributes: MutableMap <String , Any ?> = initialAttributes.toMutableMap()
82
80
private val internalAttributes: MutableMap <String , Any ?> = mutableMapOf ()
81
+ private var memoizedParentAttributes: Map <String , Any ?> = emptyMap()
83
82
84
83
private var sessionId: String = parentScope.getRumContext().sessionId
85
84
internal var viewId: String = UUID .randomUUID().toString()
@@ -187,7 +186,6 @@ internal open class RumViewScope(
187
186
event : RumRawEvent ,
188
187
writer : DataWriter <Any >
189
188
): RumScope ? {
190
- updateGlobalAttributes(sdkCore, event)
191
189
when (event) {
192
190
is RumRawEvent .ResourceSent -> onResourceSent(event, writer)
193
191
is RumRawEvent .ActionSent -> onActionSent(event, writer)
@@ -252,6 +250,14 @@ internal open class RumViewScope(
252
250
)
253
251
}
254
252
253
+ override fun getCustomAttributes (): Map <String , Any ?> {
254
+ return if (! stopped) {
255
+ parentScope.getCustomAttributes() + viewAttributes
256
+ } else {
257
+ memoizedParentAttributes + viewAttributes
258
+ }
259
+ }
260
+
255
261
override fun isActive (): Boolean {
256
262
return ! stopped
257
263
}
@@ -365,7 +371,8 @@ internal open class RumViewScope(
365
371
)
366
372
}
367
373
}
368
- eventAttributes.putAll(event.attributes)
374
+ viewAttributes.putAll(event.attributes)
375
+ memoizedParentAttributes = parentScope.getCustomAttributes().toMap()
369
376
}
370
377
}
371
378
}
@@ -427,13 +434,10 @@ internal open class RumViewScope(
427
434
delegateEventToChildren(event, writer)
428
435
if (stopped) return
429
436
430
- val updatedEvent = event.copy(
431
- attributes = addExtraAttributes(event.attributes)
432
- )
433
437
activeResourceScopes[event.key] = RumResourceScope .fromEvent(
434
438
this ,
435
439
sdkCore,
436
- updatedEvent ,
440
+ event ,
437
441
firstPartyHostHeaderTypeResolver,
438
442
serverTimeOffsetInMs,
439
443
featuresContextResolver,
@@ -454,10 +458,11 @@ internal open class RumViewScope(
454
458
455
459
val rumContext = getRumContext()
456
460
457
- val updatedAttributes = addExtraAttributes(event.attributes)
458
- val isFatal = updatedAttributes
459
- .remove(RumAttributes .INTERNAL_ERROR_IS_CRASH ) as ? Boolean == true || event.isFatal
460
- val errorFingerprint = updatedAttributes.remove(RumAttributes .ERROR_FINGERPRINT ) as ? String
461
+ val errorCustomAttributes = getCustomAttributes().toMutableMap()
462
+ errorCustomAttributes.putAll(event.attributes)
463
+ val isFatal = errorCustomAttributes.remove(RumAttributes .INTERNAL_ERROR_IS_CRASH ) as ? Boolean == true ||
464
+ event.isFatal
465
+ val errorFingerprint = errorCustomAttributes.remove(RumAttributes .ERROR_FINGERPRINT ) as ? String
461
466
// if a cross-platform crash was already reported, do not send its native version
462
467
if (crashCount > 0 && isFatal) return
463
468
@@ -559,7 +564,7 @@ internal open class RumViewScope(
559
564
brand = datadogContext.deviceInfo.deviceBrand,
560
565
architecture = datadogContext.deviceInfo.architecture
561
566
),
562
- context = ErrorEvent .Context (additionalProperties = updatedAttributes ),
567
+ context = ErrorEvent .Context (additionalProperties = errorCustomAttributes ),
563
568
dd = ErrorEvent .Dd (
564
569
session = ErrorEvent .DdSession (
565
570
sessionPrecondition = rumContext.sessionStartReason.toErrorSessionPrecondition()
@@ -897,7 +902,7 @@ internal open class RumViewScope(
897
902
val isSlowRendered = resolveRefreshRateInfo(refreshRateInfo) ? : false
898
903
// make a copy - by the time we iterate over it on another thread, it may already be changed
899
904
val eventFeatureFlags = featureFlags.toMutableMap()
900
- val eventAdditionalAttributes = (eventAttributes + globalAttributes ).toMutableMap()
905
+ val viewCustomAttributes = getCustomAttributes( ).toMutableMap()
901
906
val uiSlownessReport = slowFramesListener?.resolveReport(viewId, viewComplete, durationNs)
902
907
val slowFrames = uiSlownessReport?.slowFramesRecords?.map {
903
908
ViewEvent .SlowFrame (
@@ -957,7 +962,6 @@ internal open class RumViewScope(
957
962
} else {
958
963
ViewEvent .ViewEventSessionType .SYNTHETICS
959
964
}
960
-
961
965
ViewEvent (
962
966
date = eventTimestamp,
963
967
featureFlags = ViewEvent .Context (additionalProperties = eventFeatureFlags),
@@ -1032,7 +1036,7 @@ internal open class RumViewScope(
1032
1036
brand = datadogContext.deviceInfo.deviceBrand,
1033
1037
architecture = datadogContext.deviceInfo.architecture
1034
1038
),
1035
- context = ViewEvent .Context (additionalProperties = eventAdditionalAttributes ),
1039
+ context = ViewEvent .Context (additionalProperties = viewCustomAttributes ),
1036
1040
dd = ViewEvent .Dd (
1037
1041
documentVersion = eventVersion,
1038
1042
session = ViewEvent .DdSession (
@@ -1050,16 +1054,6 @@ internal open class RumViewScope(
1050
1054
}.submit()
1051
1055
}
1052
1056
1053
- private fun updateGlobalAttributes (sdkCore : InternalSdkCore , event : RumRawEvent ) {
1054
- if (! stopped && event !is RumRawEvent .StartView ) {
1055
- globalAttributes = resolveGlobalAttributes(sdkCore)
1056
- }
1057
- }
1058
-
1059
- private fun resolveGlobalAttributes (sdkCore : InternalSdkCore ): Map <String , Any ?> {
1060
- return GlobalRumMonitor .get(sdkCore).getAttributes().toMap()
1061
- }
1062
-
1063
1057
private fun resolveViewDuration (event : RumRawEvent ) {
1064
1058
stoppedNanos = event.eventTime.nanoTime
1065
1059
val duration = stoppedNanos - startedNanos
@@ -1114,12 +1108,6 @@ internal open class RumViewScope(
1114
1108
null
1115
1109
}
1116
1110
1117
- private fun addExtraAttributes (
1118
- attributes : Map <String , Any ?>
1119
- ): MutableMap <String , Any ?> {
1120
- return attributes.toMutableMap().apply { putAll(globalAttributes) }
1121
- }
1122
-
1123
1111
@Suppress(" LongMethod" )
1124
1112
@WorkerThread
1125
1113
private fun onApplicationStarted (
@@ -1128,7 +1116,7 @@ internal open class RumViewScope(
1128
1116
) {
1129
1117
pendingActionCount++
1130
1118
val rumContext = getRumContext()
1131
- val localCopyOfGlobalAttributes = globalAttributes .toMutableMap()
1119
+ val actionCustomAttributes = getCustomAttributes() .toMutableMap()
1132
1120
sdkCore.newRumEventWriteOperation(writer) { datadogContext ->
1133
1121
val user = datadogContext.userInfo
1134
1122
val syntheticsAttribute = if (
@@ -1199,7 +1187,7 @@ internal open class RumViewScope(
1199
1187
architecture = datadogContext.deviceInfo.architecture
1200
1188
),
1201
1189
context = ActionEvent .Context (
1202
- additionalProperties = localCopyOfGlobalAttributes
1190
+ additionalProperties = actionCustomAttributes
1203
1191
),
1204
1192
dd = ActionEvent .Dd (
1205
1193
session = ActionEvent .DdSession (
@@ -1231,9 +1219,10 @@ internal open class RumViewScope(
1231
1219
if (stopped) return
1232
1220
1233
1221
val rumContext = getRumContext()
1234
- val updatedAttributes = addExtraAttributes(
1235
- mapOf (RumAttributes .LONG_TASK_TARGET to event.target)
1236
- )
1222
+ val longTaskCustomAttributes = getCustomAttributes().toMutableMap().apply {
1223
+ put(RumAttributes .LONG_TASK_TARGET , event.target)
1224
+ }
1225
+
1237
1226
val timestamp = event.eventTime.timestamp + serverTimeOffsetInMs
1238
1227
val isFrozenFrame = event.durationNs > FROZEN_FRAME_THRESHOLD_NS
1239
1228
slowFramesListener?.onAddLongTask(event.durationNs)
@@ -1307,7 +1296,7 @@ internal open class RumViewScope(
1307
1296
brand = datadogContext.deviceInfo.deviceBrand,
1308
1297
architecture = datadogContext.deviceInfo.architecture
1309
1298
),
1310
- context = LongTaskEvent .Context (additionalProperties = updatedAttributes ),
1299
+ context = LongTaskEvent .Context (additionalProperties = longTaskCustomAttributes ),
1311
1300
dd = LongTaskEvent .Dd (
1312
1301
session = LongTaskEvent .DdSession (
1313
1302
sessionPrecondition = rumContext.sessionStartReason.toLongTaskSessionPrecondition()
@@ -1367,7 +1356,7 @@ internal open class RumViewScope(
1367
1356
viewChangedListener?.onViewChanged(
1368
1357
RumViewInfo (
1369
1358
key = key,
1370
- attributes = eventAttributes ,
1359
+ attributes = viewAttributes ,
1371
1360
isActive = isActive()
1372
1361
)
1373
1362
)
0 commit comments