Skip to content

RUM-15277: Merge native user info to webview events#3306

Open
kikoveiga wants to merge 2 commits intodevelopfrom
kikoveiga/RUM-15277/propagate-anonymous-user-id-to-webview-events
Open

RUM-15277: Merge native user info to webview events#3306
kikoveiga wants to merge 2 commits intodevelopfrom
kikoveiga/RUM-15277/propagate-anonymous-user-id-to-webview-events

Conversation

@kikoveiga
Copy link
Copy Markdown
Contributor

@kikoveiga kikoveiga commented Mar 30, 2026

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's usr object.

Example of before vs after:
image
image

Motivation

RUMS-5561

Review checklist (to be filled by reviewers)

  • Feature or bugfix MUST have appropriate tests (unit, integration, e2e)
  • Make sure you discussed the feature or bugfix with the maintaining team in an Issue
  • Make sure each commit and the PR mention the Issue number (cf the CONTRIBUTING doc)

@kikoveiga kikoveiga force-pushed the kikoveiga/RUM-15277/propagate-anonymous-user-id-to-webview-events branch 3 times, most recently from 022dd69 to 14549c7 Compare March 30, 2026 15:36
@kikoveiga kikoveiga requested a review from cdn34dd March 30, 2026 15:36
@kikoveiga kikoveiga marked this pull request as ready for review March 30, 2026 15:44
@kikoveiga kikoveiga requested review from a team as code owners March 30, 2026 15:44
0xnm
0xnm previously approved these changes Mar 30, 2026
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

@datadog-datadog-prod-us1-2
Copy link
Copy Markdown

datadog-datadog-prod-us1-2 bot commented Mar 30, 2026

🎯 Code Coverage (details)
Patch Coverage: 100.00%
Overall Coverage: 71.41% (-0.12%)

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: de7985d | Docs | Datadog PR Page | Was this helpful? React with 👍/👎 or give us feedback!

@kikoveiga kikoveiga self-assigned this Mar 30, 2026
@kikoveiga kikoveiga force-pushed the kikoveiga/RUM-15277/propagate-anonymous-user-id-to-webview-events branch from 14549c7 to e09a136 Compare March 31, 2026 10:07
0xnm
0xnm previously approved these changes Mar 31, 2026
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Mar 31, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 71.56%. Comparing base (41ae98f) to head (de7985d).

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     
Files with missing lines Coverage Δ
...kotlin/com/datadog/android/api/context/UserInfo.kt 64.58% <ø> (ø)
...id/webview/internal/log/WebViewLogEventConsumer.kt 82.47% <100.00%> (+1.16%) ⬆️
...id/webview/internal/rum/WebViewRumEventConsumer.kt 92.06% <100.00%> (+0.68%) ⬆️
...roid/webview/internal/rum/WebViewRumEventMapper.kt 100.00% <100.00%> (ø)

... and 44 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@kikoveiga kikoveiga changed the title Propagate user info to webview events Merge native user info to webview events Mar 31, 2026
@kikoveiga kikoveiga force-pushed the kikoveiga/RUM-15277/propagate-anonymous-user-id-to-webview-events branch 2 times, most recently from 183ca6b to b9f52a4 Compare March 31, 2026 11:57
@kikoveiga kikoveiga force-pushed the kikoveiga/RUM-15277/propagate-anonymous-user-id-to-webview-events branch from b9f52a4 to de7985d Compare March 31, 2026 11:59
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)) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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"
) 

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

@kikoveiga kikoveiga Apr 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member

@ambushwork ambushwork Apr 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Copy link
Copy Markdown
Contributor

@cdn34dd cdn34dd Apr 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@kikoveiga kikoveiga changed the title Merge native user info to webview events RUM-15277: Merge native user info to webview events Apr 1, 2026
@mariusc83 mariusc83 closed this Apr 2, 2026
Copy link
Copy Markdown
Contributor

@cdn34dd cdn34dd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@kikoveiga kikoveiga reopened this Apr 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants