@datadog/mobile-react-native 3.4.0 → 3.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (69) hide show
  1. package/DatadogSDKReactNative.podspec +7 -7
  2. package/android/build.gradle +7 -7
  3. package/android/src/main/kotlin/com/datadog/reactnative/DdSdkImplementation.kt +4 -5
  4. package/android/src/main/kotlin/com/datadog/reactnative/DdSdkNativeInitialization.kt +1 -0
  5. package/android/src/main/kotlin/com/datadog/reactnative/FrameRateProvider.kt +16 -8
  6. package/android/src/main/kotlin/com/datadog/reactnative/JsThreadExecutor.kt +27 -0
  7. package/android/src/main/kotlin/com/datadog/reactnative/SdkVersion.kt +1 -1
  8. package/android/src/test/kotlin/com/datadog/reactnative/DdSdkTest.kt +63 -5
  9. package/android/src/test/kotlin/com/datadog/tools/unit/MockRumMonitor.kt +25 -0
  10. package/android/src/test/kotlin/com/datadog/tools/unit/TestJsThreadExecutor.kt +16 -0
  11. package/ios/Sources/RNDdSdkConfiguration.swift +2 -0
  12. package/ios/Sources/SdkVersion.swift +1 -1
  13. package/lib/commonjs/DdSdkReactNative.js +19 -19
  14. package/lib/commonjs/DdSdkReactNative.js.map +1 -1
  15. package/lib/commonjs/rum/instrumentation/resourceTracking/DdRumResourceTracking.js +22 -0
  16. package/lib/commonjs/rum/instrumentation/resourceTracking/DdRumResourceTracking.js.map +1 -1
  17. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/XHRProxy.js +11 -4
  18. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/XHRProxy.js.map +1 -1
  19. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/interfaces/RequestProxy.js.map +1 -1
  20. package/lib/commonjs/sdk/AttributesEncoding/helpers.js +5 -12
  21. package/lib/commonjs/sdk/AttributesEncoding/helpers.js.map +1 -1
  22. package/lib/commonjs/sdk/UserInfoSingleton/UserInfoSingleton.js +13 -1
  23. package/lib/commonjs/sdk/UserInfoSingleton/UserInfoSingleton.js.map +1 -1
  24. package/lib/commonjs/types.js.map +1 -1
  25. package/lib/commonjs/version.js +1 -1
  26. package/lib/module/DdSdkReactNative.js +19 -19
  27. package/lib/module/DdSdkReactNative.js.map +1 -1
  28. package/lib/module/rum/instrumentation/resourceTracking/DdRumResourceTracking.js +22 -0
  29. package/lib/module/rum/instrumentation/resourceTracking/DdRumResourceTracking.js.map +1 -1
  30. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/XHRProxy.js +11 -4
  31. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/XHRProxy.js.map +1 -1
  32. package/lib/module/sdk/AttributesEncoding/helpers.js +5 -12
  33. package/lib/module/sdk/AttributesEncoding/helpers.js.map +1 -1
  34. package/lib/module/sdk/UserInfoSingleton/UserInfoSingleton.js +13 -1
  35. package/lib/module/sdk/UserInfoSingleton/UserInfoSingleton.js.map +1 -1
  36. package/lib/module/types.js.map +1 -1
  37. package/lib/module/version.js +1 -1
  38. package/lib/typescript/DdSdkReactNative.d.ts +6 -9
  39. package/lib/typescript/DdSdkReactNative.d.ts.map +1 -1
  40. package/lib/typescript/config/async/PartialInitializationConfiguration.d.ts +1 -0
  41. package/lib/typescript/config/async/PartialInitializationConfiguration.d.ts.map +1 -1
  42. package/lib/typescript/rum/instrumentation/resourceTracking/DdRumResourceTracking.d.ts +10 -0
  43. package/lib/typescript/rum/instrumentation/resourceTracking/DdRumResourceTracking.d.ts.map +1 -1
  44. package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/XHRProxy.d.ts +4 -0
  45. package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/XHRProxy.d.ts.map +1 -1
  46. package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/interfaces/RequestProxy.d.ts +3 -0
  47. package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/interfaces/RequestProxy.d.ts.map +1 -1
  48. package/lib/typescript/sdk/UserInfoSingleton/UserInfoSingleton.d.ts +4 -1
  49. package/lib/typescript/sdk/UserInfoSingleton/UserInfoSingleton.d.ts.map +1 -1
  50. package/lib/typescript/sdk/UserInfoSingleton/types.d.ts +1 -1
  51. package/lib/typescript/sdk/UserInfoSingleton/types.d.ts.map +1 -1
  52. package/lib/typescript/types.d.ts +8 -7
  53. package/lib/typescript/types.d.ts.map +1 -1
  54. package/lib/typescript/version.d.ts +1 -1
  55. package/package.json +2 -2
  56. package/src/DdSdkReactNative.tsx +34 -35
  57. package/src/__tests__/DdSdkReactNative.test.tsx +21 -3
  58. package/src/config/async/PartialInitializationConfiguration.ts +1 -0
  59. package/src/rum/instrumentation/resourceTracking/DdRumResourceTracking.tsx +26 -0
  60. package/src/rum/instrumentation/resourceTracking/__tests__/DdRumResourceTracking.test.ts +87 -0
  61. package/src/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/XHRProxy.ts +12 -4
  62. package/src/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/__tests__/XHRProxy.test.ts +61 -0
  63. package/src/rum/instrumentation/resourceTracking/requestProxy/interfaces/RequestProxy.ts +3 -0
  64. package/src/sdk/AttributesEncoding/__tests__/attributesEncoding.test.ts +13 -14
  65. package/src/sdk/AttributesEncoding/helpers.ts +9 -18
  66. package/src/sdk/UserInfoSingleton/UserInfoSingleton.ts +15 -2
  67. package/src/sdk/UserInfoSingleton/types.ts +1 -1
  68. package/src/types.tsx +6 -7
  69. package/src/version.ts +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"XHRProxy.d.ts","sourceRoot":"","sources":["../../../../../../../src/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/XHRProxy.ts"],"names":[],"mappings":"AA+BA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACtE,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAG1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,uCAAuC,CAAC;AAyBzE,UAAU,iBAAiB;IACvB,OAAO,EAAE,OAAO,cAAc,CAAC;IAC/B,gBAAgB,EAAE,gBAAgB,CAAC;CACtC;AAED;;GAEG;AACH,qBAAa,QAAS,SAAQ,YAAY;IACtC,OAAO,CAAC,SAAS,CAAoB;IACrC,OAAO,CAAC,MAAM,CAAC,eAAe,CAAuC;IACrE,OAAO,CAAC,MAAM,CAAC,eAAe,CAAuC;IACrE,OAAO,CAAC,MAAM,CAAC,2BAA2B,CAAmD;gBAEjF,SAAS,EAAE,iBAAiB;IAKxC,MAAM,CAAC,0BAA0B;IAOjC,eAAe,YAAa,mBAAmB,UAK7C;IAEF,cAAc,aAKZ;CACL"}
1
+ {"version":3,"file":"XHRProxy.d.ts","sourceRoot":"","sources":["../../../../../../../src/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/XHRProxy.ts"],"names":[],"mappings":"AA+BA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACtE,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAG1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,uCAAuC,CAAC;AAyBzE,UAAU,iBAAiB;IACvB,OAAO,EAAE,OAAO,cAAc,CAAC;IAC/B,gBAAgB,EAAE,gBAAgB,CAAC;CACtC;AAED;;GAEG;AACH,qBAAa,QAAS,SAAQ,YAAY;IACtC,OAAO,CAAC,SAAS,CAAoB;IACrC,OAAO,CAAC,OAAO,CAAoC;IACnD,OAAO,CAAC,MAAM,CAAC,eAAe,CAAuC;IACrE,OAAO,CAAC,MAAM,CAAC,eAAe,CAAuC;IACrE,OAAO,CAAC,MAAM,CAAC,2BAA2B,CAAmD;gBAEjF,SAAS,EAAE,iBAAiB;IAKxC,MAAM,CAAC,0BAA0B;IAOjC,eAAe,YAAa,mBAAmB,UAM7C;IAEF,cAAc,aAMZ;IAEF,gBAAgB,YAAa;QAAE,mBAAmB,EAAE,MAAM,CAAA;KAAE,UAK1D;CACL"}
@@ -10,5 +10,8 @@ export type RegexMap = {
10
10
  export declare abstract class RequestProxy {
11
11
  abstract onTrackingStart: (context: RequestProxyOptions) => void;
12
12
  abstract onTrackingStop: () => void;
13
+ abstract onTrackingUpdate: (context: {
14
+ tracingSamplingRate: number;
15
+ }) => void;
13
16
  }
14
17
  //# sourceMappingURL=RequestProxy.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"RequestProxy.d.ts","sourceRoot":"","sources":["../../../../../../../src/rum/instrumentation/resourceTracking/requestProxy/interfaces/RequestProxy.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAExD,MAAM,WAAW,mBAAmB;IAChC,mBAAmB,EAAE,MAAM,CAAC;IAC5B,uBAAuB,EAAE,QAAQ,CAAC;CACrC;AAED,MAAM,MAAM,QAAQ,GAAG;IACnB,KAAK,EAAE,MAAM,CAAC;IACd,cAAc,EAAE,cAAc,CAAC;CAClC,EAAE,CAAC;AAEJ,8BAAsB,YAAY;IAC9B,QAAQ,CAAC,eAAe,EAAE,CAAC,OAAO,EAAE,mBAAmB,KAAK,IAAI,CAAC;IACjE,QAAQ,CAAC,cAAc,EAAE,MAAM,IAAI,CAAC;CACvC"}
1
+ {"version":3,"file":"RequestProxy.d.ts","sourceRoot":"","sources":["../../../../../../../src/rum/instrumentation/resourceTracking/requestProxy/interfaces/RequestProxy.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAExD,MAAM,WAAW,mBAAmB;IAChC,mBAAmB,EAAE,MAAM,CAAC;IAC5B,uBAAuB,EAAE,QAAQ,CAAC;CACrC;AAED,MAAM,MAAM,QAAQ,GAAG;IACnB,KAAK,EAAE,MAAM,CAAC;IACd,cAAc,EAAE,cAAc,CAAC;CAClC,EAAE,CAAC;AAEJ,8BAAsB,YAAY;IAC9B,QAAQ,CAAC,eAAe,EAAE,CAAC,OAAO,EAAE,mBAAmB,KAAK,IAAI,CAAC;IACjE,QAAQ,CAAC,cAAc,EAAE,MAAM,IAAI,CAAC;IACpC,QAAQ,CAAC,gBAAgB,EAAE,CAAC,OAAO,EAAE;QACjC,mBAAmB,EAAE,MAAM,CAAC;KAC/B,KAAK,IAAI,CAAC;CACd"}
@@ -1,7 +1,10 @@
1
1
  import type { UserInfo } from './types';
2
2
  declare class UserInfoProvider {
3
3
  private userInfo;
4
- setUserInfo: (userInfo: UserInfo) => void;
4
+ setUserInfo: (userInfo: UserInfo & {
5
+ id: string;
6
+ }) => void;
7
+ addUserExtraInfo: (extraInfo: Record<string, unknown>) => void;
5
8
  getUserInfo: () => UserInfo | undefined;
6
9
  clearUserInfo: () => void;
7
10
  }
@@ -1 +1 @@
1
- {"version":3,"file":"UserInfoSingleton.d.ts","sourceRoot":"","sources":["../../../../src/sdk/UserInfoSingleton/UserInfoSingleton.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAExC,cAAM,gBAAgB;IAClB,OAAO,CAAC,QAAQ,CAAmC;IAEnD,WAAW,aAAc,QAAQ,UAG/B;IAEF,WAAW,QAAO,QAAQ,GAAG,SAAS,CAEpC;IAEF,aAAa,aAEX;CACL;AAED,qBAAa,iBAAiB;IAC1B,OAAO,CAAC,MAAM,CAAC,gBAAgB,CAA0B;IAEzD,MAAM,CAAC,WAAW,QAAO,gBAAgB,CAEvC;IAEF,MAAM,CAAC,KAAK,aAEV;CACL"}
1
+ {"version":3,"file":"UserInfoSingleton.d.ts","sourceRoot":"","sources":["../../../../src/sdk/UserInfoSingleton/UserInfoSingleton.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAExC,cAAM,gBAAgB;IAClB,OAAO,CAAC,QAAQ,CAAmC;IAEnD,WAAW,aAAc,QAAQ,GAAG;QAAE,EAAE,EAAE,MAAM,CAAA;KAAE,UAMhD;IAEF,gBAAgB,cAAe,OAAO,MAAM,EAAE,OAAO,CAAC,UAQpD;IAEF,WAAW,QAAO,QAAQ,GAAG,SAAS,CAEpC;IAEF,aAAa,aAEX;CACL;AAED,qBAAa,iBAAiB;IAC1B,OAAO,CAAC,MAAM,CAAC,gBAAgB,CAA0B;IAEzD,MAAM,CAAC,WAAW,QAAO,gBAAgB,CAEvC;IAEF,MAAM,CAAC,KAAK,aAEV;CACL"}
@@ -1,5 +1,5 @@
1
1
  export type UserInfo = {
2
- readonly id: string;
2
+ readonly id?: string;
3
3
  readonly name?: string;
4
4
  readonly email?: string;
5
5
  readonly extraInfo?: Record<string, unknown>;
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/sdk/UserInfoSingleton/types.ts"],"names":[],"mappings":"AAMA,MAAM,MAAM,QAAQ,GAAG;IACnB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAChD,CAAC"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/sdk/UserInfoSingleton/types.ts"],"names":[],"mappings":"AAMA,MAAM,MAAM,QAAQ,GAAG;IACnB,QAAQ,CAAC,EAAE,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAChD,CAAC"}
@@ -33,13 +33,14 @@ export type DdSdkType = {
33
33
  */
34
34
  removeAttributes(keys: string[]): Promise<void>;
35
35
  /**
36
- * Sets the user information.
37
- * @param id: A unique user identifier (relevant to your business domain)
38
- * @param name: The user name or alias.
39
- * @param email: The user email.
40
- * @param extraInfo: Additional information.
36
+ * Sets the user information. Requires a user ID — setting user properties
37
+ * like name or email implies a known user, so an ID must be provided.
38
+ * To add custom attributes without setting a user ID, use {@link addUserExtraInfo} instead.
39
+ * @param userInfo: The user object (id is required, name, email and extraInfo are optional).
41
40
  */
42
- setUserInfo(userInfo: UserInfo): Promise<void>;
41
+ setUserInfo(userInfo: UserInfo & {
42
+ id: string;
43
+ }): Promise<void>;
43
44
  /**
44
45
  * Clears the user information.
45
46
  */
@@ -91,7 +92,7 @@ export type DdTraceType = {
91
92
  finishSpan(spanId: string, context?: object, timestampMs?: number): Promise<void>;
92
93
  };
93
94
  export type UserInfo = {
94
- id: string;
95
+ id?: string;
95
96
  name?: string;
96
97
  email?: string;
97
98
  extraInfo?: object;
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.tsx"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,2CAA2C,CAAC;AAE1F,OAAO,CAAC,MAAM,CAAC;IAEX,IAAI,8BAA8B,EAAE,OAAO,CAAC;CAC/C;AAED;;GAEG;AACH,MAAM,MAAM,SAAS,GAAG;IACpB;;;OAGG;IACH,UAAU,CAAC,aAAa,EAAE,wBAAwB,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEnE;;;;OAIG;IACH,YAAY,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAExD;;;OAGG;IACH,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAE5C;;;OAGG;IACH,aAAa,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEjD;;;OAGG;IACH,gBAAgB,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,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WAAW;CACpB;AAED,oBAAY,uBAAuB;IAC/B,KAAK,UAAU;IACf,SAAS,cAAc;IACvB,KAAK,UAAU;CAClB"}
@@ -1,2 +1,2 @@
1
- export declare const version = "3.4.0";
1
+ export declare const version = "3.5.1";
2
2
  //# sourceMappingURL=version.d.ts.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@datadog/mobile-react-native",
3
- "version": "3.4.0",
3
+ "version": "3.5.1",
4
4
  "description": "A client-side React Native module to interact with Datadog",
5
5
  "keywords": [
6
6
  "datadog",
@@ -118,5 +118,5 @@
118
118
  "dependencies": {
119
119
  "big-integer": "^1.6.52"
120
120
  },
121
- "gitHead": "1f9a6afbda5541be33e0fe43664fd99ea0295afb"
121
+ "gitHead": "d854f9497bc143138f8bf6b40a75af2b548592a5"
122
122
  }
@@ -41,6 +41,7 @@ import { BufferSingleton } from './sdk/DatadogProvider/Buffer/BufferSingleton';
41
41
  import { NativeDdSdk } from './sdk/DdSdkInternal';
42
42
  import { GlobalState } from './sdk/GlobalState/GlobalState';
43
43
  import { UserInfoSingleton } from './sdk/UserInfoSingleton/UserInfoSingleton';
44
+ import type { UserInfo } from './sdk/UserInfoSingleton/types';
44
45
  import { adaptLongTaskThreshold } from './utils/longTasksUtils';
45
46
  import { version as sdkVersion } from './version';
46
47
 
@@ -184,13 +185,24 @@ export class DdSdkReactNative {
184
185
  return new Promise(resolve => resolve());
185
186
  }
186
187
 
187
- return DdSdkReactNative.initializeNativeSDK(
188
- buildConfigurationFromPartialConfiguration(
189
- DdSdkReactNative.features,
190
- configuration
191
- ),
192
- { initializationModeForTelemetry: 'PARTIAL' }
188
+ const builtConfiguration = buildConfigurationFromPartialConfiguration(
189
+ DdSdkReactNative.features,
190
+ configuration
193
191
  );
192
+
193
+ // The XHRProxy was installed at provider mount with the features'
194
+ // default resourceTraceSampleRate; re-apply the resolved value so a
195
+ // resourceTraceSampleRate supplied via DatadogProvider.initialize
196
+ // takes effect on subsequent fetch/XHR calls.
197
+ DdRumResourceTracking.updateTrackingContext({
198
+ resourceTraceSampleRate:
199
+ builtConfiguration.rumConfiguration?.resourceTraceSampleRate ??
200
+ RUM_DEFAULTS.resourceTraceSampleRate
201
+ });
202
+
203
+ return DdSdkReactNative.initializeNativeSDK(builtConfiguration, {
204
+ initializationModeForTelemetry: 'PARTIAL'
205
+ });
194
206
  };
195
207
 
196
208
  /**
@@ -251,19 +263,23 @@ export class DdSdkReactNative {
251
263
  };
252
264
 
253
265
  /**
254
- * Sets the user information.
255
- * @param id: A mandatory unique user identifier (relevant to your business domain).
256
- * @param name: The user name or alias.
257
- * @param email: The user email.
258
- * @param extraInfo: Additional information.
266
+ * Sets the user information. Requires a user ID — setting user properties
267
+ * like name or email implies a known user, so an ID must be provided.
268
+ * To add custom attributes without setting a user ID, use {@link addUserExtraInfo} instead.
269
+ * @param userInfo: The user object (id is required, name, email and extraInfo are optional).
259
270
  * @returns a Promise.
260
271
  */
261
- static setUserInfo = async (userInfo: {
262
- id: string;
263
- name?: string;
264
- email?: string;
265
- extraInfo?: Record<string, unknown>;
266
- }): Promise<void> => {
272
+ static setUserInfo = async (
273
+ userInfo: UserInfo & { id: string }
274
+ ): Promise<void> => {
275
+ if (typeof userInfo.id !== 'string' || userInfo.id.length === 0) {
276
+ InternalLog.log(
277
+ 'setUserInfo requires a valid user ID. Please provide a non-empty string as the id field.',
278
+ SdkVerbosity.WARN
279
+ );
280
+ return;
281
+ }
282
+
267
283
  InternalLog.log(
268
284
  `Setting user ${JSON.stringify(userInfo)}`,
269
285
  SdkVerbosity.DEBUG
@@ -296,25 +312,8 @@ export class DdSdkReactNative {
296
312
  SdkVerbosity.DEBUG
297
313
  );
298
314
 
299
- const userInfo = UserInfoSingleton.getInstance().getUserInfo();
300
- if (!userInfo) {
301
- InternalLog.log(
302
- 'Skipped adding User Extra Info: User Info is currently undefined. A user ID must be set before adding extra info. Please call setUserInfo() first.',
303
- SdkVerbosity.WARN
304
- );
305
-
306
- return;
307
- }
308
- const updatedUserInfo = {
309
- ...userInfo,
310
- extraInfo: {
311
- ...userInfo.extraInfo,
312
- ...extraUserInfo
313
- }
314
- };
315
-
316
315
  await NativeDdSdk.addUserExtraInfo(extraUserInfo);
317
- UserInfoSingleton.getInstance().setUserInfo(updatedUserInfo);
316
+ UserInfoSingleton.getInstance().addUserExtraInfo(extraUserInfo);
318
317
  };
319
318
 
320
319
  /**
@@ -1298,6 +1298,24 @@ describe('DdSdkReactNative', () => {
1298
1298
  }
1299
1299
  });
1300
1300
  });
1301
+
1302
+ it('calls SDK method when addUserExtraInfo without prior setUserInfo', async () => {
1303
+ // GIVEN
1304
+ const extraInfo = { testId: 'abc123' };
1305
+
1306
+ // WHEN
1307
+ await DdSdkReactNative.addUserExtraInfo(extraInfo);
1308
+
1309
+ // THEN
1310
+ expect(NativeDdSdk.addUserExtraInfo).toHaveBeenCalledWith(
1311
+ extraInfo
1312
+ );
1313
+ expect(UserInfoSingleton.getInstance().getUserInfo()).toEqual({
1314
+ extraInfo: {
1315
+ testId: 'abc123'
1316
+ }
1317
+ });
1318
+ });
1301
1319
  });
1302
1320
 
1303
1321
  describe('clearUserInfo', () => {
@@ -1320,9 +1338,9 @@ describe('DdSdkReactNative', () => {
1320
1338
  // THEN
1321
1339
  expect(NativeDdSdk.clearUserInfo).toHaveBeenCalledTimes(1);
1322
1340
  expect(NativeDdSdk.setUserInfo).toHaveBeenCalled();
1323
- expect(UserInfoSingleton.getInstance().getUserInfo()).toEqual(
1324
- undefined
1325
- );
1341
+ expect(
1342
+ UserInfoSingleton.getInstance().getUserInfo()
1343
+ ).toBeUndefined();
1326
1344
  });
1327
1345
  });
1328
1346
 
@@ -46,6 +46,7 @@ export type PartialInitializationConfiguration = {
46
46
  readonly customEndpoint?: string;
47
47
  readonly trackNonFatalAnrs?: boolean;
48
48
  readonly appHangThreshold?: number;
49
+ readonly resourceTraceSampleRate?: number;
49
50
  };
50
51
  readonly logsConfiguration?: {
51
52
  readonly bundleLogsWithRum?: boolean;
@@ -73,6 +73,32 @@ class RumResourceTracking {
73
73
  );
74
74
  }
75
75
 
76
+ /**
77
+ * Applies a new resource trace sample rate to the already-installed
78
+ * request proxy. Used by deferred-initialization flows
79
+ * (DatadogProvider.initialize) where tracking is started at provider
80
+ * mount with default features, and the final sample rate is only known
81
+ * later. No-op if tracking has not started.
82
+ */
83
+ updateTrackingContext({
84
+ resourceTraceSampleRate
85
+ }: {
86
+ resourceTraceSampleRate: number;
87
+ }): void {
88
+ if (!this._isTracking || !this._requestProxy) {
89
+ return;
90
+ }
91
+ this._requestProxy.onTrackingUpdate({
92
+ tracingSamplingRate: resourceTraceSampleRate
93
+ });
94
+ // Keep the distributed-tracing sampler's max-trace-id in sync; the
95
+ // shouldSampleTrace path consults this for rates strictly between 0
96
+ // and 100.
97
+ DistributedTracingSampling.setResourceTraceSampleRate(
98
+ resourceTraceSampleRate
99
+ );
100
+ }
101
+
76
102
  stopTracking(): void {
77
103
  if (this._isTracking) {
78
104
  this._isTracking = false;
@@ -9,6 +9,7 @@ import { NativeModules } from 'react-native';
9
9
  import { BufferSingleton } from '../../../../sdk/DatadogProvider/Buffer/BufferSingleton';
10
10
  import { PropagatorType } from '../../../types';
11
11
  import { DdRumResourceTracking } from '../DdRumResourceTracking';
12
+ import { SAMPLING_PRIORITY_HEADER_KEY } from '../distributedTracing/headers';
12
13
 
13
14
  import { XMLHttpRequestMock } from './__utils__/XMLHttpRequestMock';
14
15
 
@@ -90,4 +91,90 @@ describe('DdRumResourceTracking', () => {
90
91
  expect(DdRum.startResource).not.toHaveBeenCalled();
91
92
  expect(DdRum.stopResource).not.toHaveBeenCalled();
92
93
  });
94
+
95
+ describe('updateTrackingContext', () => {
96
+ beforeEach(() => {
97
+ DdRumResourceTracking.stopTracking();
98
+ });
99
+
100
+ afterEach(() => {
101
+ DdRumResourceTracking.stopTracking();
102
+ });
103
+
104
+ it('is a no-op when called before startTracking', async () => {
105
+ // GIVEN tracking was never started
106
+
107
+ // WHEN
108
+ DdRumResourceTracking.updateTrackingContext({
109
+ resourceTraceSampleRate: 100
110
+ });
111
+
112
+ executeRequest('https://api.example.com/v2/user');
113
+ await flushPromises();
114
+
115
+ // THEN: no XHR proxy was installed; no resource events captured
116
+ expect(DdRum.startResource).not.toHaveBeenCalled();
117
+ expect(DdRum.stopResource).not.toHaveBeenCalled();
118
+ });
119
+
120
+ it('applies the updated sampling rate to subsequent requests', () => {
121
+ // GIVEN tracking installed with rate=0
122
+ DdRumResourceTracking.startTracking({
123
+ resourceTraceSampleRate: 0,
124
+ firstPartyHosts: [
125
+ {
126
+ match: 'api.example.com',
127
+ propagatorTypes: [PropagatorType.DATADOG]
128
+ }
129
+ ]
130
+ });
131
+
132
+ // pre-update request gets sampling priority '0'
133
+ const xhrBeforeUpdate = new XMLHttpRequestMock();
134
+ xhrBeforeUpdate.open('GET', 'https://api.example.com/v2/user');
135
+ xhrBeforeUpdate.send();
136
+ expect(
137
+ xhrBeforeUpdate.requestHeaders.get(SAMPLING_PRIORITY_HEADER_KEY)
138
+ ).toBe('0');
139
+
140
+ // WHEN
141
+ DdRumResourceTracking.updateTrackingContext({
142
+ resourceTraceSampleRate: 100
143
+ });
144
+
145
+ // THEN: post-update request uses the new rate
146
+ const xhrAfterUpdate = new XMLHttpRequestMock();
147
+ xhrAfterUpdate.open('GET', 'https://api.example.com/v2/user');
148
+ xhrAfterUpdate.send();
149
+ expect(
150
+ xhrAfterUpdate.requestHeaders.get(SAMPLING_PRIORITY_HEADER_KEY)
151
+ ).toBe('1');
152
+ });
153
+
154
+ it('is a no-op after tracking has been stopped', async () => {
155
+ // GIVEN
156
+ DdRumResourceTracking.startTracking({
157
+ resourceTraceSampleRate: 100,
158
+ firstPartyHosts: [
159
+ {
160
+ match: 'api.example.com',
161
+ propagatorTypes: [PropagatorType.DATADOG]
162
+ }
163
+ ]
164
+ });
165
+ DdRumResourceTracking.stopTracking();
166
+
167
+ // WHEN
168
+ DdRumResourceTracking.updateTrackingContext({
169
+ resourceTraceSampleRate: 100
170
+ });
171
+
172
+ executeRequest('https://api.example.com/v2/user');
173
+ await flushPromises();
174
+
175
+ // THEN: tracking remains stopped, nothing captured
176
+ expect(DdRum.startResource).not.toHaveBeenCalled();
177
+ expect(DdRum.stopResource).not.toHaveBeenCalled();
178
+ });
179
+ });
93
180
  });
@@ -68,6 +68,7 @@ interface XHRProxyProviders {
68
68
  */
69
69
  export class XHRProxy extends RequestProxy {
70
70
  private providers: XHRProxyProviders;
71
+ private context: RequestProxyOptions | null = null;
71
72
  private static originalXhrOpen: typeof XMLHttpRequest.prototype.open;
72
73
  private static originalXhrSend: typeof XMLHttpRequest.prototype.send;
73
74
  private static originalXhrSetRequestHeader: typeof XMLHttpRequest.prototype.setRequestHeader;
@@ -88,6 +89,7 @@ export class XHRProxy extends RequestProxy {
88
89
  XHRProxy.originalXhrOpen = this.providers.xhrType.prototype.open;
89
90
  XHRProxy.originalXhrSend = this.providers.xhrType.prototype.send;
90
91
  XHRProxy.originalXhrSetRequestHeader = this.providers.xhrType.prototype.setRequestHeader;
92
+ this.context = context;
91
93
  proxyRequests(this.providers, context);
92
94
  };
93
95
 
@@ -96,6 +98,14 @@ export class XHRProxy extends RequestProxy {
96
98
  this.providers.xhrType.prototype.send = XHRProxy.originalXhrSend;
97
99
  this.providers.xhrType.prototype.setRequestHeader =
98
100
  XHRProxy.originalXhrSetRequestHeader;
101
+ this.context = null;
102
+ };
103
+
104
+ onTrackingUpdate = (options: { tracingSamplingRate: number }) => {
105
+ if (this.context === null) {
106
+ return;
107
+ }
108
+ this.context.tracingSamplingRate = options.tracingSamplingRate;
99
109
  };
100
110
  }
101
111
 
@@ -113,8 +123,6 @@ const proxyOpen = (
113
123
  context: RequestProxyOptions
114
124
  ): void => {
115
125
  const originalXhrOpen = xhrType.prototype.open;
116
- const firstPartyHostsRegexMap = context.firstPartyHostsRegexMap;
117
- const tracingSamplingRate = context.tracingSamplingRate;
118
126
 
119
127
  xhrType.prototype.open = function open(
120
128
  this: DdRumXhr,
@@ -132,8 +140,8 @@ const proxyOpen = (
132
140
  graphql: {},
133
141
  tracingAttributes: getTracingAttributes({
134
142
  hostname,
135
- firstPartyHostsRegexMap,
136
- tracingSamplingRate,
143
+ firstPartyHostsRegexMap: context.firstPartyHostsRegexMap,
144
+ tracingSamplingRate: context.tracingSamplingRate,
137
145
  rumSessionId: getCachedSessionId(),
138
146
  userId: getCachedUserId(),
139
147
  accountId: getCachedAccountId()
@@ -455,6 +455,67 @@ describe('XHRProxy', () => {
455
455
  );
456
456
  });
457
457
 
458
+ it('applies a tracingSamplingRate updated via onTrackingUpdate to subsequent XHRs (regression: RUMS-5973)', async () => {
459
+ // GIVEN
460
+ const method = 'GET';
461
+ const url = 'https://api.example.com/v2/user';
462
+ const firstPartyHostsRegexMap = firstPartyHostsRegexMapBuilder([
463
+ {
464
+ match: 'api.example.com',
465
+ propagatorTypes: [PropagatorType.DATADOG]
466
+ }
467
+ ]);
468
+ xhrProxy.onTrackingStart({
469
+ tracingSamplingRate: 0,
470
+ firstPartyHostsRegexMap
471
+ });
472
+
473
+ // WHEN: an XHR is opened with the initial rate of 0
474
+ const xhrBeforeUpdate = new XMLHttpRequestMock();
475
+ xhrBeforeUpdate.open(method, url);
476
+ xhrBeforeUpdate.send();
477
+ xhrBeforeUpdate.notifyResponseArrived();
478
+ xhrBeforeUpdate.complete(200, 'ok');
479
+ await flushPromises();
480
+
481
+ // AND: the tracking context is updated to 100
482
+ xhrProxy.onTrackingUpdate({
483
+ tracingSamplingRate: 100
484
+ });
485
+
486
+ // AND: a second XHR is opened
487
+ const xhrAfterUpdate = new XMLHttpRequestMock();
488
+ xhrAfterUpdate.open(method, url);
489
+ xhrAfterUpdate.send();
490
+ xhrAfterUpdate.notifyResponseArrived();
491
+ xhrAfterUpdate.complete(200, 'ok');
492
+ await flushPromises();
493
+
494
+ // THEN: the pre-update request keeps priority 0, the post-update one is sampled at 100%
495
+ expect(
496
+ xhrBeforeUpdate.requestHeaders.get(SAMPLING_PRIORITY_HEADER_KEY)
497
+ ).toBe('0');
498
+ expect(
499
+ xhrAfterUpdate.requestHeaders.get(SAMPLING_PRIORITY_HEADER_KEY)
500
+ ).toBe('1');
501
+ });
502
+
503
+ it('ignores onTrackingUpdate when tracking has not started', () => {
504
+ // GIVEN: tracking was never started, so XMLHttpRequest is not proxied
505
+
506
+ // WHEN
507
+ xhrProxy.onTrackingUpdate({
508
+ tracingSamplingRate: 100
509
+ });
510
+
511
+ // THEN: no throw, and a subsequent open is not instrumented
512
+ const xhr = new XMLHttpRequestMock();
513
+ xhr.open('GET', 'https://api.example.com/v2/user');
514
+ expect(
515
+ xhr.requestHeaders.get(SAMPLING_PRIORITY_HEADER_KEY)
516
+ ).toBeUndefined();
517
+ });
518
+
458
519
  it('adds the x-datadog-tracked-by header for first party host requests', async () => {
459
520
  // GIVEN
460
521
  const method = 'GET';
@@ -19,4 +19,7 @@ export type RegexMap = {
19
19
  export abstract class RequestProxy {
20
20
  abstract onTrackingStart: (context: RequestProxyOptions) => void;
21
21
  abstract onTrackingStop: () => void;
22
+ abstract onTrackingUpdate: (context: {
23
+ tracingSamplingRate: number;
24
+ }) => void;
22
25
  }
@@ -216,7 +216,7 @@ describe('encodeAttributes', () => {
216
216
  );
217
217
  });
218
218
 
219
- it('does not modify original object when attribute limit is reached', () => {
219
+ it('does not modify original object when encoding many attributes', () => {
220
220
  const input: Record<string, string> = {};
221
221
  for (let i = 0; i < 200; i++) {
222
222
  input[`k${i}`] = `v${i}`;
@@ -224,7 +224,7 @@ describe('encodeAttributes', () => {
224
224
  const snapshot = { ...input };
225
225
 
226
226
  const result = encodeAttributes(input);
227
- expect(Object.keys(result)).toHaveLength(128);
227
+ expect(Object.keys(result)).toHaveLength(200);
228
228
  expect(input).toEqual(snapshot); // original still has 200 keys
229
229
  });
230
230
 
@@ -380,31 +380,30 @@ describe('encodeAttributes', () => {
380
380
  );
381
381
  });
382
382
 
383
- it('drops attributes after reaching the 128 limit and warns once', () => {
384
- // Prepare 200 simple attributes — max=128
383
+ it('warns once when the 256 attribute limit is exceeded, but does not drop attributes', () => {
384
+ // Prepare 300 simple attributes — exceeds max=256
385
385
  const input: Record<string, number> = {};
386
- for (let i = 0; i < 200; i++) {
386
+ for (let i = 0; i < 300; i++) {
387
387
  input[`key${i}`] = i;
388
388
  }
389
389
 
390
390
  const result = encodeAttributes(input);
391
391
 
392
- // Check that only 128 attributes remain
393
- expect(Object.keys(result)).toHaveLength(128);
392
+ // All 300 attributes are preserved — no hard cap
393
+ expect(Object.keys(result)).toHaveLength(300);
394
394
 
395
- // Check the first ones are preserved
395
+ // All attributes are present
396
396
  expect(result).toHaveProperty('key0', 0);
397
- expect(result).toHaveProperty('key127', 127);
398
-
399
- // Check later ones were dropped
400
- expect(result).not.toHaveProperty('key128');
397
+ expect(result).toHaveProperty('key255', 255);
398
+ expect(result).toHaveProperty('key256', 256);
399
+ expect(result).toHaveProperty('key299', 299);
401
400
 
402
- // Check that a warning was shown at least once
401
+ // A single warning is emitted when the limit is exceeded
403
402
  expect(warn).toHaveBeenCalledWith(
404
403
  expect.stringContaining('Attribute limit')
405
404
  );
406
405
 
407
- // Check there is only one "limit reached" warning (even if multiple attributes were dropped)
406
+ // Exactly one "limit exceeded" warning (not one per extra attribute)
408
407
  const limitWarnings = (warn as jest.Mock).mock.calls.filter(([msg]) =>
409
408
  msg.includes('Attribute limit')
410
409
  );
@@ -7,7 +7,7 @@
7
7
  import type { AttributeEncoder, Encodable } from './types';
8
8
  import { formatPathForLog, isPlainObject, warn } from './utils';
9
9
 
10
- const MAX_ATTRIBUTES = 128;
10
+ const MAX_ATTRIBUTES = 256;
11
11
 
12
12
  export interface EncodeContext {
13
13
  numOfAttributes: number;
@@ -152,25 +152,16 @@ function addEncodedAttribute(
152
152
  value: Encodable,
153
153
  context: EncodeContext
154
154
  ): void {
155
- if (context.numOfAttributes >= MAX_ATTRIBUTES) {
156
- // Only warn once to avoid log spam
157
- if (!context.limitReachedWarned) {
158
- warn(
159
- `Attribute limit of ${MAX_ATTRIBUTES} reached; further attributes will be dropped.`
160
- );
161
- context.limitReachedWarned = true;
162
- }
155
+ out[path.join('.')] = value;
156
+ context.numOfAttributes++;
163
157
 
164
- // Optional: warn for specific dropped attribute (if desired)
158
+ if (
159
+ context.numOfAttributes > MAX_ATTRIBUTES &&
160
+ !context.limitReachedWarned
161
+ ) {
165
162
  warn(
166
- `Dropped attribute at '${formatPathForLog(
167
- path
168
- )}' because limit of ${MAX_ATTRIBUTES} attributes was reached. All further attributes will be dropped.`
163
+ `Attribute limit of ${MAX_ATTRIBUTES} exceeded; the backend may drop some attributes.`
169
164
  );
170
-
171
- return;
165
+ context.limitReachedWarned = true;
172
166
  }
173
-
174
- out[path.join('.')] = value;
175
- context.numOfAttributes++;
176
167
  }