Skip to content

[RUM-8674] Mandatory user id in setUserInfo API#818

Merged
sbarrio merged 1 commit into
developfrom
sbarrio/RUM-8674/make-user-id-mandatory-in-setUserInfo-API
Mar 28, 2025
Merged

[RUM-8674] Mandatory user id in setUserInfo API#818
sbarrio merged 1 commit into
developfrom
sbarrio/RUM-8674/make-user-id-mandatory-in-setUserInfo-API

Conversation

@sbarrio

@sbarrio sbarrio commented Mar 12, 2025

Copy link
Copy Markdown
Contributor

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 setUser only. This does then natively call the equivalent setUserInfo on both Android and iOS. However, due to the implementation of the Typescript-level UserInfoSingleton, 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 extracting id, name and email keys 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 setUser as deprecated but allowing it to still work with the UserInfoSingleton in the same way as before, but adding a new setUserInfo method, that enforces the id, and that also respects the native parameter structure, and only allows for extra keys if they are provided inside the extraInfo object 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 the extraInfo dictionary.

Motivation

User id is becoming a mandatory parameter, therefore public APIs must enforce it.

Additional Notes

Current status of API:

React Native iOS Android Notes
setUser setUserInfo (optional id) setUserInfo (optional id) Non-matching name with native call. Allows rewriting mandatory parameters. To be deprecated
setUserInfo setUserInfo (mandatory and optional id versions) setUserInfo (mandatory and optional id versions) 1:1 with native call. Should stop calling optional version of the native API once setUser is deprecated and UserInfoSingleton modified to enforce user id
addUserExtraInfo addUserExtraInfo addUserProperties Match with iOS. Android exposes addUserProperties instead

Tests

Tested on Android and iOS on both old and new architecture.
Screenshot 2025-03-12 at 14 07 09

Screenshot 2025-03-12 at 14 06 51 Screenshot 2025-03-12 at 17 28 12

Review checklist (to be filled by reviewers)

  • Feature or bugfix MUST have appropriate tests
  • 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)
  • If this PR is auto-generated, please make sure also to manually update the code related to the change

Comment thread packages/core/src/specs/NativeDdSdk.ts
Comment thread packages/core/src/specs/NativeDdSdk.ts
id: string;
name?: string;
email?: string;
extraInfo?: Record<string, unknown>;

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.

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 */;

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.

This should be removed once setUser is deprecated as it "breaks" the parameter structure and contract with its native counterparts.

@sbarrio
sbarrio force-pushed the sbarrio/RUM-8674/make-user-id-mandatory-in-setUserInfo-API branch from a1353f9 to 518b97e Compare March 12, 2025 12:55
@datadog-datadog-prod-us1

datadog-datadog-prod-us1 Bot commented Mar 12, 2025

Copy link
Copy Markdown

Datadog Report

Branch report: sbarrio/RUM-8674/make-user-id-mandatory-in-setUserInfo-API
Commit report: 0fd95f5
Test service: dd-sdk-reactnative

✅ 0 Failed, 653 Passed, 1 Skipped, 12.03s Total Time

@sbarrio
sbarrio force-pushed the sbarrio/RUM-8674/make-user-id-mandatory-in-setUserInfo-API branch from 518b97e to 060b2bb Compare March 12, 2025 16:26
@sbarrio
sbarrio marked this pull request as ready for review March 12, 2025 16:28
@sbarrio
sbarrio requested a review from a team as a code owner March 12, 2025 16:28
@sbarrio
sbarrio force-pushed the sbarrio/RUM-8674/make-user-id-mandatory-in-setUserInfo-API branch from 060b2bb to 1705fa7 Compare March 12, 2025 16:31
@sbarrio sbarrio changed the title RUM-8674 Mandatory UserId in setUserInfo API RUM-8674 Mandatory user id in setUserInfo API Mar 13, 2025

@marco-saia-datadog marco-saia-datadog left a comment

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.

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

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.

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

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.

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

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.

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

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.

See my previous comment 🔝

Comment thread packages/core/src/specs/NativeDdSdk.ts
Comment thread packages/core/src/types.tsx Outdated
Comment on lines +99 to +100
*/

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.

MINOR: Extra new line here

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.

Changes at 0a63f08

@sbarrio
sbarrio force-pushed the sbarrio/RUM-8674/make-user-id-mandatory-in-setUserInfo-API branch from 1705fa7 to 0fd95f5 Compare March 18, 2025 11:56
Comment thread packages/react-native-apollo-client/__mocks__/react-native.ts
Comment thread packages/codepush/__mocks__/react-native.ts
@sbarrio
sbarrio marked this pull request as draft March 18, 2025 12:00
@sbarrio
sbarrio force-pushed the sbarrio/RUM-8674/make-user-id-mandatory-in-setUserInfo-API branch from 0fd95f5 to 0a63f08 Compare March 18, 2025 12:02
@sbarrio
sbarrio marked this pull request as ready for review March 18, 2025 12:02
@sbarrio sbarrio changed the title RUM-8674 Mandatory user id in setUserInfo API [RUM-8674] Mandatory user id in setUserInfo API Mar 21, 2025
@sbarrio
sbarrio force-pushed the sbarrio/RUM-8674/make-user-id-mandatory-in-setUserInfo-API branch from 0a63f08 to 743a63b Compare March 21, 2025 16:41
@sbarrio
sbarrio force-pushed the sbarrio/RUM-8674/make-user-id-mandatory-in-setUserInfo-API branch from 743a63b to 4637bef Compare March 24, 2025 15:36
@sbarrio sbarrio self-assigned this Mar 26, 2025
@sbarrio
sbarrio merged commit df73f3f into develop Mar 28, 2025
@sbarrio
sbarrio deleted the sbarrio/RUM-8674/make-user-id-mandatory-in-setUserInfo-API branch March 28, 2025 10:22
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.

2 participants