Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make a copy of attributes before passing them to RUM event #1830

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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