[RUM-8674] Mandatory user id in setUserInfo API#818
Conversation
| id: string; | ||
| name?: string; | ||
| email?: string; | ||
| extraInfo?: Record<string, unknown>; |
There was a problem hiding this comment.
This userInfo type should become the new type used by the UserInfoSingleton once setUser gets deprecated.
| readonly extraInfo?: Record<string, unknown>; | ||
| readonly [ | ||
| key: string | ||
| ]: unknown /** @deprecated To be removed alongside DdSdkReactnative.setUser */; |
There was a problem hiding this comment.
This should be removed once setUser is deprecated as it "breaks" the parameter structure and contract with its native counterparts.
a1353f9 to
518b97e
Compare
Datadog ReportBranch report: ✅ 0 Failed, 653 Passed, 1 Skipped, 12.03s Total Time |
518b97e to
060b2bb
Compare
060b2bb to
1705fa7
Compare
marco-saia-datadog
left a comment
There was a problem hiding this comment.
Looks good! Nice work. I have left some minor suggestions.
| * nested up to 8 levels deep. Keys using more than 8 levels will be sanitized by SDK. | ||
| */ | ||
| fun setUserInfo( | ||
| @Deprecated("UserInfo id property is now mandatory.") |
There was a problem hiding this comment.
See my previous comment 🔝
| * @param user The user object (use builtin attributes: 'id', 'email', 'name', and/or any custom | ||
| * attribute). | ||
| */ | ||
| @Deprecated("UserInfo id property is now mandatory.") |
There was a problem hiding this comment.
See my previous comment 🔝
| * @param user The user object (use builtin attributes: 'id', 'email', 'name', and/or any custom | ||
| * attribute). | ||
| */ | ||
| @Deprecated("UserInfo id property is now mandatory.") |
There was a problem hiding this comment.
See my previous comment 🔝
| * @param user The user object (use builtin attributes: 'id', 'email', 'name', and/or any custom | ||
| * attribute). | ||
| */ | ||
| @Deprecated("UserInfo id property is now mandatory.") |
There was a problem hiding this comment.
See my previous comment 🔝
| */ | ||
|
|
There was a problem hiding this comment.
MINOR: Extra new line here
1705fa7 to
0fd95f5
Compare
0fd95f5 to
0a63f08
Compare
0a63f08 to
743a63b
Compare
743a63b to
4637bef
Compare
What does this PR do?
This PR modifies the serUserInfo API to make the user id mandatory at React Native level.
It also streamlines and aligns the setUserInfo and addUserExtraInfo methods with their native counterparts, while adding a new batch of tests for them all.
Method alignment
ON the React Native SDK, the current api exposes
setUseronly. This does then natively call the equivalent setUserInfo on both Android and iOS. However, due to the implementation of the Typescript-levelUserInfoSingleton, this allows users to avoid the id enforcement by allowing to pass a Dictionary with any key to setUser. This is then passed down to its native counterparts by extractingid,nameandemailkeys separately and properly assigning them to their respective parameter, while appending every other key to the extraInfo dictionary parameter.This means, that with the current API, even if we enforce id as a mandatory property at UserInfoSingleton level, it won't make much difference as it can be rewritten by any other key that gets appended after it.
For this reason, and also to move forward to an aligned API with consisten method names I've opted to mark
setUseras deprecated but allowing it to still work with the UserInfoSingleton in the same way as before, but adding a newsetUserInfomethod, that enforces the id, and that also respects the native parameter structure, and only allows for extra keys if they are provided inside theextraInfoobject property.Apart from this, I've also exposed
addUserExtraInfo, that directly calls it's native counterpart and allows the user to add new fields to theextraInfodictionary.Motivation
User id is becoming a mandatory parameter, therefore public APIs must enforce it.
Additional Notes
Current status of API:
Tests
Tested on Android and iOS on both old and new architecture.

Review checklist (to be filled by reviewers)