@@ -12,7 +12,6 @@ import com.datadog.android.api.storage.DataWriter
12
12
import com.datadog.android.core.InternalSdkCore
13
13
import com.datadog.android.core.internal.net.FirstPartyHostHeaderTypeResolver
14
14
import com.datadog.android.internal.utils.loggableStackTrace
15
- import com.datadog.android.rum.GlobalRumMonitor
16
15
import com.datadog.android.rum.RumAttributes
17
16
import com.datadog.android.rum.RumErrorSource
18
17
import com.datadog.android.rum.RumResourceKind
@@ -35,7 +34,7 @@ import java.util.UUID
35
34
36
35
@Suppress(" LongParameterList" , " TooManyFunctions" )
37
36
internal class RumResourceScope (
38
- internal val parentScope : RumScope ,
37
+ override val parentScope : RumScope ,
39
38
internal val sdkCore : InternalSdkCore ,
40
39
internal val url : String ,
41
40
internal val method : RumResourceMethod ,
@@ -50,9 +49,8 @@ internal class RumResourceScope(
50
49
) : RumScope {
51
50
52
51
internal val resourceId: String = UUID .randomUUID().toString()
53
- internal val attributes: MutableMap <String , Any ?> = initialAttributes.toMutableMap().apply {
54
- putAll(GlobalRumMonitor .get(sdkCore).getAttributes())
55
- }
52
+ internal val resourceAttributes: MutableMap <String , Any ?> = initialAttributes.toMutableMap()
53
+
56
54
private var timing: ResourceTiming ? = null
57
55
private val initialContext = parentScope.getRumContext()
58
56
@@ -95,6 +93,10 @@ internal class RumResourceScope(
95
93
return initialContext
96
94
}
97
95
96
+ override fun getCustomAttributes (): Map <String , Any ?> {
97
+ return parentScope.getCustomAttributes() + resourceAttributes
98
+ }
99
+
98
100
override fun isActive (): Boolean {
99
101
return ! stopped
100
102
}
@@ -110,7 +112,7 @@ internal class RumResourceScope(
110
112
) {
111
113
if (key != event.key) return
112
114
stopped = true
113
- attributes .putAll(event.attributes)
115
+ resourceAttributes .putAll(event.attributes)
114
116
kind = event.kind
115
117
statusCode = event.statusCode
116
118
size = event.size
@@ -138,7 +140,7 @@ internal class RumResourceScope(
138
140
writer : DataWriter <Any >
139
141
) {
140
142
if (key != event.key) return
141
- attributes .putAll(event.attributes)
143
+ resourceAttributes .putAll(event.attributes)
142
144
sendError(
143
145
event.message,
144
146
event.source,
@@ -157,7 +159,7 @@ internal class RumResourceScope(
157
159
writer : DataWriter <Any >
158
160
) {
159
161
if (key != event.key) return
160
- attributes .putAll(event.attributes)
162
+ resourceAttributes .putAll(event.attributes)
161
163
162
164
val errorCategory =
163
165
if (event.stackTrace.isNotEmpty()) ErrorEvent .Category .EXCEPTION else null
@@ -182,10 +184,9 @@ internal class RumResourceScope(
182
184
eventTime : Time ,
183
185
writer : DataWriter <Any >
184
186
) {
185
- attributes.putAll(GlobalRumMonitor .get(sdkCore).getAttributes())
186
- val traceId = attributes.remove(RumAttributes .TRACE_ID )?.toString()
187
- val spanId = attributes.remove(RumAttributes .SPAN_ID )?.toString()
188
- val rulePsr = attributes.remove(RumAttributes .RULE_PSR ) as ? Number
187
+ val traceId = resourceAttributes.remove(RumAttributes .TRACE_ID )?.toString()
188
+ val spanId = resourceAttributes.remove(RumAttributes .SPAN_ID )?.toString()
189
+ val rulePsr = resourceAttributes.remove(RumAttributes .RULE_PSR ) as ? Number
189
190
190
191
val rumContext = getRumContext()
191
192
val syntheticsAttribute = if (
@@ -207,15 +208,14 @@ internal class RumResourceScope(
207
208
208
209
@Suppress(" UNCHECKED_CAST" )
209
210
val finalTiming = timing ? : extractResourceTiming(
210
- attributes .remove(RumAttributes .RESOURCE_TIMINGS ) as ? Map <String , Any ?>
211
+ resourceAttributes .remove(RumAttributes .RESOURCE_TIMINGS ) as ? Map <String , Any ?>
211
212
)
212
213
val graphql = resolveGraphQLAttributes(
213
- attributes .remove(RumAttributes .GRAPHQL_OPERATION_TYPE ) as ? String? ,
214
- attributes .remove(RumAttributes .GRAPHQL_OPERATION_NAME ) as ? String? ,
215
- attributes .remove(RumAttributes .GRAPHQL_PAYLOAD ) as ? String? ,
216
- attributes .remove(RumAttributes .GRAPHQL_VARIABLES ) as ? String?
214
+ resourceAttributes .remove(RumAttributes .GRAPHQL_OPERATION_TYPE ) as ? String? ,
215
+ resourceAttributes .remove(RumAttributes .GRAPHQL_OPERATION_NAME ) as ? String? ,
216
+ resourceAttributes .remove(RumAttributes .GRAPHQL_PAYLOAD ) as ? String? ,
217
+ resourceAttributes .remove(RumAttributes .GRAPHQL_VARIABLES ) as ? String?
217
218
)
218
- val eventAttributes = attributes.toMutableMap()
219
219
sdkCore.newRumEventWriteOperation(writer) { datadogContext ->
220
220
val user = datadogContext.userInfo
221
221
val hasReplay = featuresContextResolver.resolveViewHasReplay(
@@ -282,7 +282,7 @@ internal class RumResourceScope(
282
282
brand = datadogContext.deviceInfo.deviceBrand,
283
283
architecture = datadogContext.deviceInfo.architecture
284
284
),
285
- context = ResourceEvent .Context (additionalProperties = eventAttributes ),
285
+ context = ResourceEvent .Context (additionalProperties = getCustomAttributes().toMutableMap() ),
286
286
dd = ResourceEvent .Dd (
287
287
traceId = traceId,
288
288
spanId = spanId,
@@ -343,12 +343,9 @@ internal class RumResourceScope(
343
343
writer : DataWriter <Any >,
344
344
resourceStopTimestampInNanos : Long
345
345
) {
346
- attributes.putAll(GlobalRumMonitor .get(sdkCore).getAttributes())
347
- val errorFingerprint = attributes.remove(RumAttributes .ERROR_FINGERPRINT ) as ? String
348
-
346
+ val errorFingerprint = resourceAttributes.remove(RumAttributes .ERROR_FINGERPRINT ) as ? String
349
347
val rumContext = getRumContext()
350
348
351
- val eventAttributes = attributes.toMutableMap()
352
349
val syntheticsAttribute = if (
353
350
rumContext.syntheticsTestId.isNullOrBlank() ||
354
351
rumContext.syntheticsResultId.isNullOrBlank()
@@ -431,7 +428,7 @@ internal class RumResourceScope(
431
428
brand = datadogContext.deviceInfo.deviceBrand,
432
429
architecture = datadogContext.deviceInfo.architecture
433
430
),
434
- context = ErrorEvent .Context (additionalProperties = eventAttributes ),
431
+ context = ErrorEvent .Context (additionalProperties = getCustomAttributes().toMutableMap() ),
435
432
dd = ErrorEvent .Dd (
436
433
session = ErrorEvent .DdSession (
437
434
sessionPrecondition = rumContext.sessionStartReason.toErrorSessionPrecondition()
0 commit comments