RUM-15277: Merge native user info to webview events#3306
RUM-15277: Merge native user info to webview events#3306
Conversation
022dd69 to
14549c7
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 14549c7219
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
...-webview/src/main/kotlin/com/datadog/android/webview/internal/log/WebViewLogEventConsumer.kt
Outdated
Show resolved
Hide resolved
...id-webview/src/main/kotlin/com/datadog/android/webview/internal/rum/WebViewRumEventMapper.kt
Outdated
Show resolved
Hide resolved
|
🎯 Code Coverage (details) 🔗 Commit SHA: de7985d | Docs | Datadog PR Page | Was this helpful? React with 👍/👎 or give us feedback! |
14549c7 to
e09a136
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #3306 +/- ##
===========================================
+ Coverage 71.49% 71.56% +0.07%
===========================================
Files 946 946
Lines 34895 34912 +17
Branches 5906 5912 +6
===========================================
+ Hits 24947 24983 +36
+ Misses 8283 8277 -6
+ Partials 1665 1652 -13
🚀 New features to boost your workflow:
|
183ca6b to
b9f52a4
Compare
b9f52a4 to
de7985d
Compare
| private fun addUserInfo(event: JsonObject, datadogContext: DatadogContext) { | ||
| val usr = event.getAsJsonObject(USR_KEY_NAME) ?: JsonObject() | ||
| for ((key, value) in datadogContext.userInfo.toJson().asJsonObject.entrySet()) { | ||
| if (!usr.has(key)) { |
There was a problem hiding this comment.
Question: The logic seems like it overrides only a part of the user info if they are absent and keep the rest of them if present, what's the reason of doing that?
There was a problem hiding this comment.
The logic here is that we do not override the information that is already present from the browser side, and just add new fields that are not there (anonymousId will be the case for example). I added an image on the pr description for some clarity.
There was a problem hiding this comment.
This sounds strange for me, in some corner cases when Browser SDK and native SDK both possess partial user info can lead to a fake composed user info if I am not wrong.
// Webview
UserInfo(
anonymousId = null,
id = "001" ,
name = "John" ,
email = null
)
// Native
UserInfo(
anonymousId = "anonymous name",
id = "002" ,
name = "Bob" ,
email = "Bob@datadoghq.com"
)
// After the logic it becomes
UserInfo(
anonymousId = "anonymous name",
id = "001" ,
name = "John" ,
email = "Bob@datadoghq.com"
)
There was a problem hiding this comment.
Oh ok I didn't understand previously, thanks! So maybe I should just stick to adding the anonymousId, which is a native field only, wdyt?
There was a problem hiding this comment.
it can be an option, or the alternative solution is to completely override the user info of Browser SDK. it's better to check with iOS what is their approach.
There was a problem hiding this comment.
iOS doesn't do it yet as well, I'm supposed to do the same there: RUM-15279.
I had tried before to override everything, but it didn't work because some fields disappeared (web-side name and email for example). Tested it in Shopist. Also, codex advised against this in the above resolved comments.
There was a problem hiding this comment.
I think codex missed the whole picture when giving the advise, IMO the correct path should be:
- If we detect that two user info are same, by checking id for example, we are safe to merge them
- If not, we need to make a decision that if we want to keep the native one or browser one.
Also it's better to add a unit test to protect this corner case.
There was a problem hiding this comment.
I don't know the exact logic of webviews and browser sdk, but isn't the id set on their side when on a webview? If so, ids will never be the same. I think info from browser and from native is unrelated, and trying to merge them can change behaviour unexpectedly. That's why I was only adding non-existing fields, but the safest is definitely just adding the anonymousId (which is only present on the native side).
There was a problem hiding this comment.
The anonymousId field is not a mobile field only, you can also have it the browser SDK, I think the difference is that in the browser SDK is disabled by default and we enable it by default on mobile if I'm not mistaken.
I'd say here we should simply add the anonymousId if not present to ensure we don't make any breaking changes in minor versions as people can be depending on things working like they do now. If we want to review this at some point we should do so in a major version.
There was a problem hiding this comment.
I notice that on webview events context also has a usr field, and it seems that we're not setting anonymousId there:
{
(...)
"context": {
"usr": {
"use_new_checkout_flow": true,
"name": "harper.harry",
"id": "1gfdsgsdfg",
"team": "engineering",
"use_discount": false,
"email": "harper.harry@example.com"
},
"browser_test": false
}
(...)
}
I'm not sure if there's any backend functionality that specifically looks for context.usr, but maybe the safe option would be to add it also there ? As it seems that if browser were to set anonymousId itself, this would also be there.
What does this PR do?
Merges the native SDK's user info (including
anonymous_id) into webview RUM and Log events, without overwriting fields already set by the Browser SDK. Native fields are only added when the key doesn't already exist in the event'susrobject.Example of before vs after:


Motivation
RUMS-5561
Review checklist (to be filled by reviewers)