Skip to content

Commit

Permalink
Merge pull request #1830 from DataDog/nogorodnikov/make-a-copy-of-att…
Browse files Browse the repository at this point in the history
…ributes-before-passing-to-rum-event

Make a copy of attributes before passing them to RUM event
  • Loading branch information
0xnm committed Jan 22, 2024
2 parents 3d5e3d6 + 2238f81 commit 8145782
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 5 deletions.
1 change: 1 addition & 0 deletions detekt_custom.yml
Original file line number Diff line number Diff line change
Expand Up @@ -925,6 +925,7 @@ datadog:
- "kotlin.collections.MutableMap.remove(kotlin.Long)"
- "kotlin.collections.MutableMap.remove(kotlin.String)"
- "kotlin.collections.MutableMap.safeMapValuesToJson(com.datadog.android.api.InternalLogger)"
- "kotlin.collections.MutableMap.toMutableMap()"
- "kotlin.collections.MutableMap?.forEach(kotlin.Function1)"
- "kotlin.collections.MutableSet.add(com.datadog.android.core.internal.persistence.ConsentAwareStorage.Batch)"
- "kotlin.collections.MutableSet.add(com.datadog.android.telemetry.internal.TelemetryEventId)"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ internal class RumActionScope(

val actualType = type
attributes.putAll(GlobalRumMonitor.get(sdkCore).getAttributes())
val eventAttributes = attributes.toMutableMap()
val rumContext = getRumContext()

// make a copy so that closure captures at the state as of now
Expand Down Expand Up @@ -288,7 +289,7 @@ internal class RumActionScope(
brand = datadogContext.deviceInfo.deviceBrand,
architecture = datadogContext.deviceInfo.architecture
),
context = ActionEvent.Context(additionalProperties = attributes),
context = ActionEvent.Context(additionalProperties = eventAttributes),
dd = ActionEvent.Dd(
session = ActionEvent.DdSession(
plan = ActionEvent.Plan.PLAN_1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ internal class RumResourceScope(
attributes.remove(RumAttributes.GRAPHQL_PAYLOAD) as? String?,
attributes.remove(RumAttributes.GRAPHQL_VARIABLES) as? String?
)
val eventAttributes = attributes.toMutableMap()
sdkCore.newRumEventWriteOperation(writer) { datadogContext ->
val user = datadogContext.userInfo
val hasReplay = featuresContextResolver.resolveViewHasReplay(
Expand Down Expand Up @@ -269,7 +270,7 @@ internal class RumResourceScope(
brand = datadogContext.deviceInfo.deviceBrand,
architecture = datadogContext.deviceInfo.architecture
),
context = ResourceEvent.Context(additionalProperties = attributes),
context = ResourceEvent.Context(additionalProperties = eventAttributes),
dd = ResourceEvent.Dd(
traceId = traceId,
spanId = spanId,
Expand Down Expand Up @@ -333,6 +334,7 @@ internal class RumResourceScope(

val rumContext = getRumContext()

val eventAttributes = attributes.toMutableMap()
val syntheticsAttribute = if (
rumContext.syntheticsTestId.isNullOrBlank() ||
rumContext.syntheticsResultId.isNullOrBlank()
Expand Down Expand Up @@ -411,7 +413,7 @@ internal class RumResourceScope(
brand = datadogContext.deviceInfo.deviceBrand,
architecture = datadogContext.deviceInfo.architecture
),
context = ErrorEvent.Context(additionalProperties = attributes),
context = ErrorEvent.Context(additionalProperties = eventAttributes),
dd = ErrorEvent.Dd(
session = ErrorEvent.DdSession(
plan = ErrorEvent.Plan.PLAN_1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -725,6 +725,9 @@ internal open class RumViewScope(
val memoryInfo = lastMemoryInfo
val refreshRateInfo = lastFrameRateInfo
val isSlowRendered = resolveRefreshRateInfo(refreshRateInfo) ?: false
// make a copy - by the time we iterate over it on another thread, it may already be changed
val eventFeatureFlags = featureFlags.toMutableMap()
val eventAdditionalAttributes = attributes.toMutableMap()

sdkCore.newRumEventWriteOperation(writer) { datadogContext ->
val currentViewId = rumContext.viewId.orEmpty()
Expand Down Expand Up @@ -757,7 +760,7 @@ internal open class RumViewScope(

ViewEvent(
date = eventTimestamp,
featureFlags = ViewEvent.Context(additionalProperties = featureFlags),
featureFlags = ViewEvent.Context(additionalProperties = eventFeatureFlags),
view = ViewEvent.ViewEventView(
id = currentViewId,
name = rumContext.viewName,
Expand Down Expand Up @@ -821,7 +824,7 @@ internal open class RumViewScope(
brand = datadogContext.deviceInfo.deviceBrand,
architecture = datadogContext.deviceInfo.architecture
),
context = ViewEvent.Context(additionalProperties = attributes),
context = ViewEvent.Context(additionalProperties = eventAdditionalAttributes),
dd = ViewEvent.Dd(
documentVersion = eventVersion,
session = ViewEvent.DdSession(
Expand Down

0 comments on commit 8145782

Please sign in to comment.