[RUM-13793] 🐛 Skip potential sanitize updates on unaltered fields#4298
Merged
Conversation
0a59001 to
c9c4d23
Compare
Bundles Sizes Evolution
🚀 CPU Performance
🧠 Memory Performance
|
|
✅ Tests 🎉 All green!❄️ No new flaky tests detected 🎯 Code Coverage (details) 🔗 Commit SHA: 5fa77a1 | Docs | Datadog PR Page | Was this helpful? React with 👍/👎 or give us feedback! |
bcaudan
reviewed
Mar 9, 2026
5f2356e to
18017a5
Compare
bcaudan
reviewed
Mar 11, 2026
f7ab50d to
e59859e
Compare
BenoitZugmeyer
approved these changes
Mar 12, 2026
bcaudan
approved these changes
Mar 12, 2026
This reverts commit 4874044.
With the current limitModification implementation, if the modifier doesn't perform any update on serverRumEvent.resource.url and the url happens to be too long, then it will be reset to undefined. This is an "undefined behavior" that creates a discrepancy when the user of the SDK doesn't provide a beforeSend in the init config. This commit solves the discrepancy by not calling sanitize on fields whose value (is a string) and hasn't been altered by the modifier.
Co-authored-by: Bastien Caudan <1331991+bcaudan@users.noreply.github.com>
e59859e to
5fa77a1
Compare
Contributor
Author
|
/to-staging |
|
View all feedbacks in Devflow UI.
Commit 5fa77a13ce will soon be integrated into staging-11.
Commit 5fa77a13ce has been merged into staging-11 in merge commit b57398e161. Check out the triggered DDCI request. If you need to revert this integration, you can use the following command: |
gh-worker-dd-mergequeue-cf854d Bot
added a commit
that referenced
this pull request
Mar 12, 2026
Integrated commit sha: 5fa77a1 Co-authored-by: bdibon <boris.dibon@datadoghq.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
When a RumResourceEvent has a
resource.urlfield that is too long one of two things can happen:beforeSend is used: the
sanitize()function will returnundefinedand thelimitModificationfunction will set theresource.urlfield toundefined, effectively deleting it. This caused problem on web-ui (now fixed).beforeSend is not used: the
createBatch()function will discard the message that contains the RumResourceEvent, we're loosing data.Reflection behind the changes
What do we even fix?
Sending invalid data
The problem that surfaced to our users is now fixed, web-ui doesn't break when a RumResourceEvent has no
resource.url.The SDK shouldn't send invalid data to intake, this can be fixed in several ways:
resource.urlfield we can simply truncate it instead of setting it to undefined, then "how much do we truncate?", at lest enough for the message to intake to not be discardedundefinedby either""or{}Inconsistent behavior
Also note the SDK is behaving in an inconsistent manner:
beforeSend()in the RumInitConfiguration, events with unsafe fields (large URL for example) will be discarded by the transport layer. The event is discardedbeforeSend()that doesn't alter theevent, unsafe fields will be sanitized, which mean they will be either set to undefined (string too long), or truncated (the object is too big); The event or context is updated while the user never intended to do it.Summary
Then we have two problems to solve:
beforeSend(),We solve 1. by not erasing required fields.
We solve 2. by not applying the sanitize process to fields the user hasn't modified, this requires us to compare the original value
object[field]with the newvalueinsetNestedValue(). This is easy for string values, but the implementation might be more involved for objects and potentially slow.For this PR, I've have decided to fix 1 completely and 2 partially.
For string values, we don't go through the sanitize process if they didn't change.
For object values, we still go through it, at the risk of tempering the value if it's a large object (serialization wise), meaning the resulting object might be truncated. I think this is an acceptable outcome given the low probability of occurence (objects whose serialized version length is superior to 225 280 characters).
Changes
After second feedback round:
Changes history
After first feedback round:
When a field is erased by the sanitize function, just replace it with""or{}depending on thefieldTypeAdd a related unit testBefore feedback:
Save resource.url before beforeSend runs, so the original value can be restored if the user callback corrupts itTruncate resource.url to 32 KiB if it exceeds that limit (or was set to undefined by beforeSend), with a display.warn messageAdd two unit tests in assembly.spec.ts covering truncation both with and without a beforeSend callback.Test instructions
yarn test:unit --spec 'packages/rum-core/src/domain/limitModification.spec.ts'Checklist