@datadog/mobile-react-native 3.8.0 → 3.9.0

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 (71) hide show
  1. package/android/src/main/kotlin/com/datadog/reactnative/SdkVersion.kt +1 -1
  2. package/ios/Sources/DdRumImplementation.swift +2 -2
  3. package/ios/Sources/SdkVersion.swift +1 -1
  4. package/lib/commonjs/DdSdkReactNative.js +15 -15
  5. package/lib/commonjs/DdSdkReactNative.js.map +1 -1
  6. package/lib/commonjs/rum/DdRum.js +2 -2
  7. package/lib/commonjs/rum/DdRum.js.map +1 -1
  8. package/lib/commonjs/rum/instrumentation/interactionTracking/DdRumUserInteractionTracking.js +3 -3
  9. package/lib/commonjs/rum/instrumentation/interactionTracking/DdRumUserInteractionTracking.js.map +1 -1
  10. package/lib/commonjs/sdk/AttributesEncoding/defaultEncoders.js +1 -1
  11. package/lib/commonjs/sdk/AttributesEncoding/defaultEncoders.js.map +1 -1
  12. package/lib/commonjs/sdk/AttributesEncoding/helpers.js +3 -3
  13. package/lib/commonjs/sdk/AttributesEncoding/helpers.js.map +1 -1
  14. package/lib/commonjs/sdk/AttributesEncoding/utils.js +8 -0
  15. package/lib/commonjs/sdk/AttributesEncoding/utils.js.map +1 -1
  16. package/lib/commonjs/sdk/DatadogProvider/Buffer/BoundedBuffer.js +2 -2
  17. package/lib/commonjs/sdk/DatadogProvider/Buffer/BoundedBuffer.js.map +1 -1
  18. package/lib/commonjs/sdk/DdSdkInternal.js +22 -22
  19. package/lib/commonjs/sdk/DdSdkInternal.js.map +1 -1
  20. package/lib/commonjs/sdk/EventMappers/EventMapper.js +2 -2
  21. package/lib/commonjs/sdk/EventMappers/EventMapper.js.map +1 -1
  22. package/lib/commonjs/utils/time-provider/TimeProvider.js +4 -1
  23. package/lib/commonjs/utils/time-provider/TimeProvider.js.map +1 -1
  24. package/lib/commonjs/version.js +1 -1
  25. package/lib/module/DdSdkReactNative.js +15 -15
  26. package/lib/module/DdSdkReactNative.js.map +1 -1
  27. package/lib/module/rum/DdRum.js +2 -2
  28. package/lib/module/rum/DdRum.js.map +1 -1
  29. package/lib/module/rum/instrumentation/interactionTracking/DdRumUserInteractionTracking.js +3 -3
  30. package/lib/module/rum/instrumentation/interactionTracking/DdRumUserInteractionTracking.js.map +1 -1
  31. package/lib/module/sdk/AttributesEncoding/defaultEncoders.js +2 -2
  32. package/lib/module/sdk/AttributesEncoding/defaultEncoders.js.map +1 -1
  33. package/lib/module/sdk/AttributesEncoding/helpers.js +4 -4
  34. package/lib/module/sdk/AttributesEncoding/helpers.js.map +1 -1
  35. package/lib/module/sdk/AttributesEncoding/utils.js +7 -0
  36. package/lib/module/sdk/AttributesEncoding/utils.js.map +1 -1
  37. package/lib/module/sdk/DatadogProvider/Buffer/BoundedBuffer.js +2 -2
  38. package/lib/module/sdk/DatadogProvider/Buffer/BoundedBuffer.js.map +1 -1
  39. package/lib/module/sdk/DdSdkInternal.js +21 -22
  40. package/lib/module/sdk/DdSdkInternal.js.map +1 -1
  41. package/lib/module/sdk/EventMappers/EventMapper.js +2 -2
  42. package/lib/module/sdk/EventMappers/EventMapper.js.map +1 -1
  43. package/lib/module/utils/time-provider/TimeProvider.js +4 -1
  44. package/lib/module/utils/time-provider/TimeProvider.js.map +1 -1
  45. package/lib/module/version.js +1 -1
  46. package/lib/typescript/sdk/AttributesEncoding/defaultEncoders.d.ts.map +1 -1
  47. package/lib/typescript/sdk/AttributesEncoding/utils.d.ts +1 -0
  48. package/lib/typescript/sdk/AttributesEncoding/utils.d.ts.map +1 -1
  49. package/lib/typescript/sdk/DdSdkInternal.d.ts +1 -8
  50. package/lib/typescript/sdk/DdSdkInternal.d.ts.map +1 -1
  51. package/lib/typescript/utils/time-provider/TimeProvider.d.ts.map +1 -1
  52. package/lib/typescript/version.d.ts +1 -1
  53. package/package.json +2 -2
  54. package/src/DdSdkReactNative.tsx +15 -15
  55. package/src/__tests__/DdSdkReactNative.test.tsx +139 -19
  56. package/src/__tests__/rum/instrumentation/DdRumUserInteractionTracking.test.tsx +3 -3
  57. package/src/rum/DdRum.ts +2 -2
  58. package/src/rum/__tests__/DdRum.test.ts +4 -4
  59. package/src/rum/instrumentation/interactionTracking/DdRumUserInteractionTracking.tsx +3 -3
  60. package/src/sdk/AttributesEncoding/__tests__/attributesEncoding.test.ts +25 -0
  61. package/src/sdk/AttributesEncoding/defaultEncoders.ts +6 -2
  62. package/src/sdk/AttributesEncoding/helpers.ts +6 -6
  63. package/src/sdk/AttributesEncoding/utils.ts +8 -0
  64. package/src/sdk/DatadogProvider/Buffer/BoundedBuffer.ts +2 -2
  65. package/src/sdk/DatadogProvider/Buffer/__tests__/BoundedBuffer.test.ts +5 -5
  66. package/src/sdk/DdSdkInternal.ts +23 -30
  67. package/src/sdk/EventMappers/EventMapper.ts +2 -2
  68. package/src/sdk/EventMappers/__tests__/EventMapper.test.ts +2 -2
  69. package/src/utils/__tests__/TimeProvider.test.tsx +49 -0
  70. package/src/utils/time-provider/TimeProvider.tsx +10 -1
  71. package/src/version.ts +1 -1
@@ -22,9 +22,10 @@ import { DdRumUserInteractionTracking } from '../rum/instrumentation/interaction
22
22
  import { DdRumResourceTracking } from '../rum/instrumentation/resourceTracking/DdRumResourceTracking';
23
23
  import { PropagatorType, RumActionType } from '../rum/types';
24
24
  import { AttributesSingleton } from '../sdk/AttributesSingleton/AttributesSingleton';
25
- import { NativeDdSdk } from '../sdk/DdSdkInternal';
25
+ import { DdSdkWrapper } from '../sdk/DdSdkInternal';
26
26
  import { GlobalState } from '../sdk/GlobalState/GlobalState';
27
27
  import { UserInfoSingleton } from '../sdk/UserInfoSingleton/UserInfoSingleton';
28
+ import NativeDdSdkSpec from '../specs/NativeDdSdk';
28
29
  import type { LogEvent } from '../types';
29
30
  import { ErrorSource } from '../types';
30
31
  import { version as sdkVersion } from '../version';
@@ -1184,8 +1185,8 @@ describe('DdSdkReactNative', () => {
1184
1185
  await DdSdkReactNative.addAttribute(key, value);
1185
1186
 
1186
1187
  // THEN
1187
- expect(NativeDdSdk.addAttribute).toHaveBeenCalledTimes(1);
1188
- expect(NativeDdSdk.addAttribute).toHaveBeenCalledWith(key, {
1188
+ expect(NativeDdSdkSpec.addAttribute).toHaveBeenCalledTimes(1);
1189
+ expect(NativeDdSdkSpec.addAttribute).toHaveBeenCalledWith(key, {
1189
1190
  value
1190
1191
  });
1191
1192
  expect(AttributesSingleton.getInstance().getAttribute(key)).toEqual(
@@ -1205,8 +1206,8 @@ describe('DdSdkReactNative', () => {
1205
1206
  await DdSdkReactNative.removeAttribute(key);
1206
1207
 
1207
1208
  // THEN
1208
- expect(NativeDdSdk.removeAttribute).toHaveBeenCalledTimes(1);
1209
- expect(NativeDdSdk.removeAttribute).toHaveBeenCalledWith(key);
1209
+ expect(NativeDdSdkSpec.removeAttribute).toHaveBeenCalledTimes(1);
1210
+ expect(NativeDdSdkSpec.removeAttribute).toHaveBeenCalledWith(key);
1210
1211
  expect(AttributesSingleton.getInstance().getAttribute(key)).toEqual(
1211
1212
  undefined
1212
1213
  );
@@ -1223,8 +1224,10 @@ describe('DdSdkReactNative', () => {
1223
1224
  await DdSdkReactNative.addAttributes(attributes);
1224
1225
 
1225
1226
  // THEN
1226
- expect(NativeDdSdk.addAttributes).toHaveBeenCalledTimes(1);
1227
- expect(NativeDdSdk.addAttributes).toHaveBeenCalledWith(attributes);
1227
+ expect(NativeDdSdkSpec.addAttributes).toHaveBeenCalledTimes(1);
1228
+ expect(NativeDdSdkSpec.addAttributes).toHaveBeenCalledWith(
1229
+ attributes
1230
+ );
1228
1231
  expect(AttributesSingleton.getInstance().getAttributes()).toEqual({
1229
1232
  foo: 'bar'
1230
1233
  });
@@ -1241,8 +1244,8 @@ describe('DdSdkReactNative', () => {
1241
1244
  await DdSdkReactNative.removeAttributes(['foo', 'baz']);
1242
1245
 
1243
1246
  // THEN
1244
- expect(NativeDdSdk.removeAttributes).toHaveBeenCalledTimes(1);
1245
- expect(NativeDdSdk.removeAttributes).toHaveBeenCalledWith([
1247
+ expect(NativeDdSdkSpec.removeAttributes).toHaveBeenCalledTimes(1);
1248
+ expect(NativeDdSdkSpec.removeAttributes).toHaveBeenCalledWith([
1246
1249
  'foo',
1247
1250
  'baz'
1248
1251
  ]);
@@ -1268,8 +1271,8 @@ describe('DdSdkReactNative', () => {
1268
1271
  await DdSdkReactNative.setUserInfo(userInfo);
1269
1272
 
1270
1273
  // THEN
1271
- expect(NativeDdSdk.setUserInfo).toHaveBeenCalledTimes(1);
1272
- expect(NativeDdSdk.setUserInfo).toHaveBeenCalledWith(userInfo);
1274
+ expect(NativeDdSdkSpec.setUserInfo).toHaveBeenCalledTimes(1);
1275
+ expect(NativeDdSdkSpec.setUserInfo).toHaveBeenCalledWith(userInfo);
1273
1276
  expect(UserInfoSingleton.getInstance().getUserInfo()).toEqual(
1274
1277
  userInfo
1275
1278
  );
@@ -1289,8 +1292,8 @@ describe('DdSdkReactNative', () => {
1289
1292
  await DdSdkReactNative.addUserExtraInfo(extraInfo);
1290
1293
 
1291
1294
  // THEN
1292
- expect(NativeDdSdk.addUserExtraInfo).toHaveBeenCalledTimes(1);
1293
- expect(NativeDdSdk.addUserExtraInfo).toHaveBeenCalledWith(
1295
+ expect(NativeDdSdkSpec.addUserExtraInfo).toHaveBeenCalledTimes(1);
1296
+ expect(NativeDdSdkSpec.addUserExtraInfo).toHaveBeenCalledWith(
1294
1297
  extraInfo
1295
1298
  );
1296
1299
  expect(UserInfoSingleton.getInstance().getUserInfo()).toEqual({
@@ -1310,7 +1313,7 @@ describe('DdSdkReactNative', () => {
1310
1313
  await DdSdkReactNative.addUserExtraInfo(extraInfo);
1311
1314
 
1312
1315
  // THEN
1313
- expect(NativeDdSdk.addUserExtraInfo).toHaveBeenCalledWith(
1316
+ expect(NativeDdSdkSpec.addUserExtraInfo).toHaveBeenCalledWith(
1314
1317
  extraInfo
1315
1318
  );
1316
1319
  expect(UserInfoSingleton.getInstance().getUserInfo()).toEqual({
@@ -1339,8 +1342,8 @@ describe('DdSdkReactNative', () => {
1339
1342
  await DdSdkReactNative.clearUserInfo();
1340
1343
 
1341
1344
  // THEN
1342
- expect(NativeDdSdk.clearUserInfo).toHaveBeenCalledTimes(1);
1343
- expect(NativeDdSdk.setUserInfo).toHaveBeenCalled();
1345
+ expect(NativeDdSdkSpec.clearUserInfo).toHaveBeenCalledTimes(1);
1346
+ expect(NativeDdSdkSpec.setUserInfo).toHaveBeenCalled();
1344
1347
  expect(
1345
1348
  UserInfoSingleton.getInstance().getUserInfo()
1346
1349
  ).toBeUndefined();
@@ -1357,8 +1360,8 @@ describe('DdSdkReactNative', () => {
1357
1360
  DdSdkReactNative.setTrackingConsent(consent);
1358
1361
 
1359
1362
  // THEN
1360
- expect(NativeDdSdk.setTrackingConsent).toHaveBeenCalledTimes(1);
1361
- expect(NativeDdSdk.setTrackingConsent).toHaveBeenCalledWith(
1363
+ expect(NativeDdSdkSpec.setTrackingConsent).toHaveBeenCalledTimes(1);
1364
+ expect(NativeDdSdkSpec.setTrackingConsent).toHaveBeenCalledWith(
1362
1365
  consent
1363
1366
  );
1364
1367
  });
@@ -1370,7 +1373,7 @@ describe('DdSdkReactNative', () => {
1370
1373
  DdSdkReactNative.clearAllData();
1371
1374
 
1372
1375
  // THEN
1373
- expect(NativeDdSdk.clearAllData).toHaveBeenCalledTimes(1);
1376
+ expect(NativeDdSdkSpec.clearAllData).toHaveBeenCalledTimes(1);
1374
1377
  });
1375
1378
  });
1376
1379
 
@@ -1500,4 +1503,121 @@ describe('DdSdkReactNative', () => {
1500
1503
  });
1501
1504
  }
1502
1505
  );
1506
+ describe('routing through DdSdkWrapper', () => {
1507
+ it('DdSdkReactNative.addAttribute reaches the native spec via the wrapper', async () => {
1508
+ const spy = jest.spyOn(DdSdkWrapper.prototype, 'addAttribute');
1509
+
1510
+ await DdSdkReactNative.addAttribute('key', 'value');
1511
+
1512
+ expect(spy).toHaveBeenCalled();
1513
+ spy.mockRestore();
1514
+ });
1515
+
1516
+ it('DdSdkReactNative.removeAttribute reaches the native spec via the wrapper', async () => {
1517
+ const spy = jest.spyOn(DdSdkWrapper.prototype, 'removeAttribute');
1518
+
1519
+ await DdSdkReactNative.removeAttribute('key');
1520
+
1521
+ expect(spy).toHaveBeenCalled();
1522
+ spy.mockRestore();
1523
+ });
1524
+
1525
+ it('DdSdkReactNative.addAttributes reaches the native spec via the wrapper', async () => {
1526
+ const spy = jest.spyOn(DdSdkWrapper.prototype, 'addAttributes');
1527
+
1528
+ await DdSdkReactNative.addAttributes({ key: 'value' });
1529
+
1530
+ expect(spy).toHaveBeenCalled();
1531
+ spy.mockRestore();
1532
+ });
1533
+
1534
+ it('DdSdkReactNative.removeAttributes reaches the native spec via the wrapper', async () => {
1535
+ const spy = jest.spyOn(DdSdkWrapper.prototype, 'removeAttributes');
1536
+
1537
+ await DdSdkReactNative.removeAttributes(['key']);
1538
+
1539
+ expect(spy).toHaveBeenCalled();
1540
+ spy.mockRestore();
1541
+ });
1542
+
1543
+ it('DdSdkReactNative.setUserInfo reaches the native spec via the wrapper', async () => {
1544
+ const spy = jest.spyOn(DdSdkWrapper.prototype, 'setUserInfo');
1545
+
1546
+ await DdSdkReactNative.setUserInfo({ id: 'user-id' });
1547
+
1548
+ expect(spy).toHaveBeenCalled();
1549
+ spy.mockRestore();
1550
+ });
1551
+
1552
+ it('DdSdkReactNative.clearUserInfo reaches the native spec via the wrapper', async () => {
1553
+ const spy = jest.spyOn(DdSdkWrapper.prototype, 'clearUserInfo');
1554
+
1555
+ await DdSdkReactNative.clearUserInfo();
1556
+
1557
+ expect(spy).toHaveBeenCalled();
1558
+ spy.mockRestore();
1559
+ });
1560
+
1561
+ it('DdSdkReactNative.addUserExtraInfo reaches the native spec via the wrapper', async () => {
1562
+ const spy = jest.spyOn(DdSdkWrapper.prototype, 'addUserExtraInfo');
1563
+
1564
+ await DdSdkReactNative.addUserExtraInfo({ role: 'admin' });
1565
+
1566
+ expect(spy).toHaveBeenCalled();
1567
+ spy.mockRestore();
1568
+ });
1569
+
1570
+ it('DdSdkReactNative.setAccountInfo reaches the native spec via the wrapper', async () => {
1571
+ const spy = jest.spyOn(DdSdkWrapper.prototype, 'setAccountInfo');
1572
+
1573
+ await DdSdkReactNative.setAccountInfo({ id: 'account-id' });
1574
+
1575
+ expect(spy).toHaveBeenCalled();
1576
+ spy.mockRestore();
1577
+ });
1578
+
1579
+ it('DdSdkReactNative.clearAccountInfo reaches the native spec via the wrapper', async () => {
1580
+ const spy = jest.spyOn(DdSdkWrapper.prototype, 'clearAccountInfo');
1581
+
1582
+ await DdSdkReactNative.clearAccountInfo();
1583
+
1584
+ expect(spy).toHaveBeenCalled();
1585
+ spy.mockRestore();
1586
+ });
1587
+
1588
+ it('DdSdkReactNative.addAccountExtraInfo reaches the native spec via the wrapper', async () => {
1589
+ // addAccountExtraInfo bails out early unless an account ID is set.
1590
+ await DdSdkReactNative.setAccountInfo({ id: 'account-id' });
1591
+ const spy = jest.spyOn(
1592
+ DdSdkWrapper.prototype,
1593
+ 'addAccountExtraInfo'
1594
+ );
1595
+
1596
+ await DdSdkReactNative.addAccountExtraInfo({ tier: 'premium' });
1597
+
1598
+ expect(spy).toHaveBeenCalled();
1599
+ spy.mockRestore();
1600
+ });
1601
+
1602
+ it('DdSdkReactNative.setTrackingConsent reaches the native spec via the wrapper', async () => {
1603
+ const spy = jest.spyOn(
1604
+ DdSdkWrapper.prototype,
1605
+ 'setTrackingConsent'
1606
+ );
1607
+
1608
+ await DdSdkReactNative.setTrackingConsent(TrackingConsent.GRANTED);
1609
+
1610
+ expect(spy).toHaveBeenCalled();
1611
+ spy.mockRestore();
1612
+ });
1613
+
1614
+ it('DdSdkReactNative.clearAllData reaches the native spec via the wrapper', async () => {
1615
+ const spy = jest.spyOn(DdSdkWrapper.prototype, 'clearAllData');
1616
+
1617
+ await DdSdkReactNative.clearAllData();
1618
+
1619
+ expect(spy).toHaveBeenCalled();
1620
+ spy.mockRestore();
1621
+ });
1622
+ });
1503
1623
  });
@@ -21,7 +21,7 @@ import React from 'react';
21
21
  import type { DdNativeRumType } from '../../../nativeModulesTypes';
22
22
  import { DdRumUserInteractionTracking } from '../../../rum/instrumentation/interactionTracking/DdRumUserInteractionTracking';
23
23
  import { BufferSingleton } from '../../../sdk/DatadogProvider/Buffer/BufferSingleton';
24
- import { NativeDdSdk } from '../../../sdk/DdSdkInternal';
24
+ import NativeDdSdkSpec from '../../../specs/NativeDdSdk';
25
25
 
26
26
  const styles = StyleSheet.create({
27
27
  button: {
@@ -467,7 +467,7 @@ describe('startTracking', () => {
467
467
  jest.setMock('react/jsx-runtime', {});
468
468
  DdRumUserInteractionTracking.startTracking({});
469
469
  expect(DdRumUserInteractionTracking['isTracking']).toBe(true);
470
- expect(NativeDdSdk.telemetryDebug).toBeCalledWith(
470
+ expect(NativeDdSdkSpec.telemetryDebug).toBeCalledWith(
471
471
  'React jsx runtime does not export new jsx transform'
472
472
  );
473
473
  });
@@ -477,7 +477,7 @@ describe('startTracking', () => {
477
477
 
478
478
  DdRumUserInteractionTracking.startTracking({});
479
479
  expect(DdRumUserInteractionTracking['isTracking']).toBe(true);
480
- expect(NativeDdSdk.telemetryDebug).toBeCalledWith(
480
+ expect(NativeDdSdkSpec.telemetryDebug).toBeCalledWith(
481
481
  'React version does not support new jsx transform'
482
482
  );
483
483
  });
package/src/rum/DdRum.ts CHANGED
@@ -13,7 +13,7 @@ import type { DdNativeRumType } from '../nativeModulesTypes';
13
13
  import { encodeAttributes } from '../sdk/AttributesEncoding/attributesEncoding';
14
14
  import type { Attributes } from '../sdk/AttributesSingleton/types';
15
15
  import { bufferVoidNativeCall } from '../sdk/DatadogProvider/Buffer/bufferNativeCall';
16
- import { NativeDdSdk } from '../sdk/DdSdkInternal';
16
+ import { DdSdk } from '../sdk/DdSdk';
17
17
  import { GlobalState } from '../sdk/GlobalState/GlobalState';
18
18
  import type { ErrorSource, FeatureOperationFailure } from '../types';
19
19
  import { getGlobalInstance } from '../utils/singletonUtils';
@@ -583,7 +583,7 @@ class DdRumWrapper implements DdRumType {
583
583
  }
584
584
  if (isOldStopActionAPI(args)) {
585
585
  if (this.lastActionData) {
586
- NativeDdSdk.telemetryDebug(
586
+ DdSdk.telemetryDebug(
587
587
  'DDdRum.stopAction called with the old signature'
588
588
  );
589
589
  const { type, name } = this.lastActionData;
@@ -11,8 +11,8 @@ import type { GestureResponderEvent } from 'react-native';
11
11
  import { InternalLog } from '../../InternalLog';
12
12
  import { SdkVerbosity } from '../../config/types';
13
13
  import { BufferSingleton } from '../../sdk/DatadogProvider/Buffer/BufferSingleton';
14
- import { NativeDdSdk } from '../../sdk/DdSdkInternal';
15
14
  import { GlobalState } from '../../sdk/GlobalState/GlobalState';
15
+ import NativeDdSdkSpec from '../../specs/NativeDdSdk';
16
16
  import { ErrorSource } from '../../types';
17
17
  import { DdRum } from '../DdRum';
18
18
  import type { ActionEventMapper } from '../eventMappers/actionEventMapper';
@@ -1444,7 +1444,7 @@ describe('DdRum', () => {
1444
1444
  test('does not call the native SDK when startAction has not been called before and using old API', async () => {
1445
1445
  await DdRum.stopAction({ user: 'me' }, 789);
1446
1446
  expect(NativeModules.DdRum.stopAction).not.toHaveBeenCalled();
1447
- expect(NativeDdSdk.telemetryDebug).not.toHaveBeenCalled();
1447
+ expect(NativeDdSdkSpec.telemetryDebug).not.toHaveBeenCalled();
1448
1448
  });
1449
1449
 
1450
1450
  test('calls the native SDK when called with old API', async () => {
@@ -1456,7 +1456,7 @@ describe('DdRum', () => {
1456
1456
  { user: 'me' },
1457
1457
  789
1458
1458
  );
1459
- expect(NativeDdSdk.telemetryDebug).toHaveBeenCalledWith(
1459
+ expect(NativeDdSdkSpec.telemetryDebug).toHaveBeenCalledWith(
1460
1460
  'DDdRum.stopAction called with the old signature'
1461
1461
  );
1462
1462
  });
@@ -1470,7 +1470,7 @@ describe('DdRum', () => {
1470
1470
  {},
1471
1471
  456
1472
1472
  );
1473
- expect(NativeDdSdk.telemetryDebug).toHaveBeenCalledWith(
1473
+ expect(NativeDdSdkSpec.telemetryDebug).toHaveBeenCalledWith(
1474
1474
  'DDdRum.stopAction called with the old signature'
1475
1475
  );
1476
1476
  });
@@ -9,7 +9,7 @@ import React from 'react';
9
9
  import { InternalLog } from '../../../InternalLog';
10
10
  import { SdkVerbosity } from '../../../config/types/SdkVerbosity';
11
11
  import { getErrorMessage } from '../../../sdk/AttributesEncoding/errorUtils';
12
- import { NativeDdSdk } from '../../../sdk/DdSdkInternal';
12
+ import { DdSdk } from '../../../sdk/DdSdk';
13
13
  import { BABEL_PLUGIN_TELEMETRY } from '../../constants';
14
14
 
15
15
  import { DdBabelInteractionTracking } from './DdBabelInteractionTracking';
@@ -82,7 +82,7 @@ export class DdRumUserInteractionTracking {
82
82
  return;
83
83
  }
84
84
 
85
- NativeDdSdk?.sendTelemetryLog(
85
+ DdSdk?.sendTelemetryLog(
86
86
  BABEL_PLUGIN_TELEMETRY,
87
87
  DdBabelInteractionTracking.getTelemetryConfig(),
88
88
  { onlyOnce: true }
@@ -126,7 +126,7 @@ export class DdRumUserInteractionTracking {
126
126
  };
127
127
  }
128
128
  } catch (e) {
129
- NativeDdSdk.telemetryDebug(getErrorMessage(e));
129
+ DdSdk.telemetryDebug(getErrorMessage(e));
130
130
  }
131
131
 
132
132
  const originalMemo = React.memo;
@@ -41,6 +41,31 @@ describe('encodeAttributes', () => {
41
41
  expect(warn).toHaveBeenCalled();
42
42
  });
43
43
 
44
+ it('drops a null-prototype object without throwing', () => {
45
+ expect(() =>
46
+ encodeAttributes({ bad: Object.create(null) })
47
+ ).not.toThrow();
48
+ expect(warn).toHaveBeenCalled();
49
+ });
50
+
51
+ it('drops a value whose toString throws without throwing', () => {
52
+ const bad = {
53
+ toString() {
54
+ throw new Error('boom');
55
+ }
56
+ };
57
+ Object.setPrototypeOf(bad, null);
58
+ expect(() => encodeAttributes({ bad })).not.toThrow();
59
+ expect(warn).toHaveBeenCalled();
60
+ });
61
+
62
+ it('drops a null-prototype object nested in an array without throwing', () => {
63
+ expect(() =>
64
+ encodeAttributes({ bad: [Object.create(null)] })
65
+ ).not.toThrow();
66
+ expect(warn).toHaveBeenCalled();
67
+ });
68
+
44
69
  it('drops unsupported root function', () => {
45
70
  const result = encodeAttributes(() => {});
46
71
  expect(result).toEqual({});
@@ -16,7 +16,7 @@ import {
16
16
  } from './errorUtils';
17
17
  import { encodeAttributesInPlace, sanitizeForJson } from './helpers';
18
18
  import type { AttributeEncoder, Encodable } from './types';
19
- import { warn } from './utils';
19
+ import { safeToString, warn } from './utils';
20
20
 
21
21
  /** Primitives: keep them explicit so the full pipeline is used uniformly. */
22
22
  export const stringEncoder: AttributeEncoder<string> = {
@@ -165,7 +165,11 @@ export const mapEncoder: AttributeEncoder<Map<unknown, unknown>> = {
165
165
  value: sanitizeForJson(v, allEncoders)
166
166
  });
167
167
  } catch (err) {
168
- warn(`Failed to encode Map key: ${k}. ERROR: ${String(err)}`);
168
+ warn(
169
+ `Failed to encode Map key: ${safeToString(
170
+ k
171
+ )}. ERROR: ${safeToString(err)}`
172
+ );
169
173
  }
170
174
  }
171
175
 
@@ -5,7 +5,7 @@
5
5
  */
6
6
 
7
7
  import type { AttributeEncoder, Encodable } from './types';
8
- import { formatPathForLog, isPlainObject, warn } from './utils';
8
+ import { formatPathForLog, isPlainObject, safeToString, warn } from './utils';
9
9
 
10
10
  const MAX_ATTRIBUTES = 256;
11
11
 
@@ -69,7 +69,7 @@ export function encodeAttributesInPlace(
69
69
  warn(
70
70
  `Dropped unsupported value in array at '${formatPathForLog(
71
71
  path
72
- )}': ${String(v)}`
72
+ )}': ${safeToString(v)}`
73
73
  );
74
74
  return undefined;
75
75
  };
@@ -94,9 +94,9 @@ export function encodeAttributesInPlace(
94
94
 
95
95
  // Unsupported
96
96
  warn(
97
- `Dropped unsupported value at '${formatPathForLog(path)}': ${String(
98
- value
99
- )}`
97
+ `Dropped unsupported value at '${formatPathForLog(
98
+ path
99
+ )}': ${safeToString(value)}`
100
100
  );
101
101
  }
102
102
 
@@ -138,7 +138,7 @@ export function applyEncoders(
138
138
  return enc.encode(value as never);
139
139
  }
140
140
  } catch (err) {
141
- warn(`Encoder error: ${String(err)}`);
141
+ warn(`Encoder error: ${safeToString(err)}`);
142
142
  return undefined;
143
143
  }
144
144
  }
@@ -11,6 +11,14 @@ export function warn(text: string) {
11
11
  InternalLog.log(`[ATTRIBUTES] ${text}`, SdkVerbosity.WARN);
12
12
  }
13
13
 
14
+ export function safeToString(value: unknown): string {
15
+ try {
16
+ return String(value);
17
+ } catch {
18
+ return Object.prototype.toString.call(value);
19
+ }
20
+ }
21
+
14
22
  export function isPlainObject(v: unknown): v is Record<string, unknown> {
15
23
  return !!v && typeof v === 'object' && (v as any).constructor === Object;
16
24
  }
@@ -7,7 +7,7 @@
7
7
  import { InternalLog } from '../../../InternalLog';
8
8
  import { SdkVerbosity } from '../../../config/types/SdkVerbosity';
9
9
  import { getErrorStackTrace } from '../../AttributesEncoding/errorUtils';
10
- import { NativeDdSdk } from '../../DdSdkInternal';
10
+ import { DdSdk } from '../../DdSdk';
11
11
 
12
12
  import { DatadogBuffer } from './DatadogBuffer';
13
13
 
@@ -206,7 +206,7 @@ export class BoundedBuffer extends DatadogBuffer {
206
206
  private drainTelemetry = () => {
207
207
  Object.values(this.telemetryBuffer).forEach(
208
208
  ({ message, stack, kind, occurrences }) => {
209
- NativeDdSdk.telemetryError(
209
+ DdSdk.telemetryError(
210
210
  `${message} happened ${occurrences} times.`,
211
211
  stack,
212
212
  kind
@@ -5,7 +5,7 @@
5
5
  */
6
6
 
7
7
  import { InternalLog } from '../../../../InternalLog';
8
- import { NativeDdSdk } from '../../../DdSdkInternal';
8
+ import NativeDdSdkSpec from '../../../../specs/NativeDdSdk';
9
9
  import { BoundedBuffer } from '../BoundedBuffer';
10
10
 
11
11
  describe('BoundedBuffer', () => {
@@ -126,7 +126,7 @@ describe('BoundedBuffer', () => {
126
126
  await buffer.drain();
127
127
  expect(callbackWithId).toHaveBeenCalledTimes(1);
128
128
  expect(callbackWithId).toHaveBeenNthCalledWith(1, 'callbackId1');
129
- expect(NativeDdSdk.telemetryError).toHaveBeenCalledWith(
129
+ expect(NativeDdSdkSpec.telemetryError).toHaveBeenCalledWith(
130
130
  'Could not generate enough random numbers happened 2 times.',
131
131
  '',
132
132
  'RandomIdGenerationError'
@@ -146,7 +146,7 @@ describe('BoundedBuffer', () => {
146
146
 
147
147
  await buffer.drain();
148
148
  expect(fakeCallback).toHaveBeenCalledTimes(3);
149
- expect(NativeDdSdk.telemetryError).toHaveBeenCalledWith(
149
+ expect(NativeDdSdkSpec.telemetryError).toHaveBeenCalledWith(
150
150
  'Buffer overflow happened 1 times.',
151
151
  '',
152
152
  'BufferOverflow'
@@ -171,7 +171,7 @@ describe('BoundedBuffer', () => {
171
171
  expect(fakeCallback).toHaveBeenCalledTimes(1);
172
172
  expect(callbackReturningId).not.toHaveBeenCalled();
173
173
  expect(callbackWithId).not.toHaveBeenCalled();
174
- expect(NativeDdSdk.telemetryError).toHaveBeenCalledWith(
174
+ expect(NativeDdSdkSpec.telemetryError).toHaveBeenCalledWith(
175
175
  'Buffer overflow happened 2 times.',
176
176
  '',
177
177
  'BufferOverflow'
@@ -196,7 +196,7 @@ describe('BoundedBuffer', () => {
196
196
  expect(fakeCallback).toHaveBeenCalledTimes(1);
197
197
  expect(callbackReturningId).toHaveBeenCalledTimes(1);
198
198
  expect(callbackWithId).toHaveBeenCalledTimes(1);
199
- expect(NativeDdSdk.telemetryError).not.toHaveBeenCalled();
199
+ expect(NativeDdSdkSpec.telemetryError).not.toHaveBeenCalled();
200
200
  });
201
201
  });
202
202
  });
@@ -10,16 +10,11 @@ import type { DdNativeSdkType } from '../nativeModulesTypes';
10
10
  import type { AttributeEncoder } from './AttributesEncoding/types';
11
11
 
12
12
  // eslint-disable-next-line global-require, @typescript-eslint/no-var-requires
13
- const NativeDdSdk: DdNativeSdkType = require('../specs/NativeDdSdk').default;
13
+ const NativeDdSdkSpec: DdNativeSdkType = require('../specs/NativeDdSdk')
14
+ .default;
14
15
 
15
- export type DdSdkType = {
16
+ export type DdSdkType = DdNativeSdkType & {
16
17
  readonly attributeEncoders: AttributeEncoder<any>[];
17
-
18
- /**
19
- * Initializes Datadog's features.
20
- * @param configuration: The configuration to use.
21
- */
22
- initialize(configuration: DdSdkNativeConfiguration): Promise<void>;
23
18
  };
24
19
 
25
20
  export class DdSdkWrapper implements DdNativeSdkType {
@@ -30,49 +25,49 @@ export class DdSdkWrapper implements DdNativeSdkType {
30
25
 
31
26
  initialize(configuration: DdSdkNativeConfiguration): Promise<void> {
32
27
  this._attributeEncoders = [...configuration.attributeEncoders];
33
- return NativeDdSdk.initialize(configuration);
28
+ return NativeDdSdkSpec.initialize(configuration);
34
29
  }
35
30
 
36
31
  getConstants() {
37
- return NativeDdSdk.getConstants();
32
+ return NativeDdSdkSpec.getConstants();
38
33
  }
39
34
 
40
35
  setUserInfo(user: object): Promise<object> {
41
- return NativeDdSdk.setUserInfo(user);
36
+ return NativeDdSdkSpec.setUserInfo(user);
42
37
  }
43
38
 
44
39
  clearUserInfo(): Promise<void> {
45
- return NativeDdSdk.clearUserInfo();
40
+ return NativeDdSdkSpec.clearUserInfo();
46
41
  }
47
42
 
48
43
  addUserExtraInfo(extraInfo: object): Promise<object> {
49
- return NativeDdSdk.addUserExtraInfo(extraInfo);
44
+ return NativeDdSdkSpec.addUserExtraInfo(extraInfo);
50
45
  }
51
46
 
52
47
  addAttribute(key: string, value: object): Promise<void> {
53
- return NativeDdSdk.addAttribute(key, value);
48
+ return NativeDdSdkSpec.addAttribute(key, value);
54
49
  }
55
50
  removeAttribute(key: string): Promise<void> {
56
- return NativeDdSdk.removeAttribute(key);
51
+ return NativeDdSdkSpec.removeAttribute(key);
57
52
  }
58
53
  addAttributes(attributes: object): Promise<void> {
59
- return NativeDdSdk.addAttributes(attributes);
54
+ return NativeDdSdkSpec.addAttributes(attributes);
60
55
  }
61
56
  removeAttributes(keys: string[]): Promise<void> {
62
- return NativeDdSdk.removeAttributes(keys);
57
+ return NativeDdSdkSpec.removeAttributes(keys);
63
58
  }
64
59
  setAccountInfo(account: object): Promise<object> {
65
- return NativeDdSdk.setAccountInfo(account);
60
+ return NativeDdSdkSpec.setAccountInfo(account);
66
61
  }
67
62
  clearAccountInfo(): Promise<void> {
68
- return NativeDdSdk.clearAccountInfo();
63
+ return NativeDdSdkSpec.clearAccountInfo();
69
64
  }
70
65
  addAccountExtraInfo(extraInfo: object): Promise<object> {
71
- return NativeDdSdk.addAccountExtraInfo(extraInfo);
66
+ return NativeDdSdkSpec.addAccountExtraInfo(extraInfo);
72
67
  }
73
68
 
74
69
  setTrackingConsent(trackingConsent: string): Promise<void> {
75
- return NativeDdSdk.setTrackingConsent(trackingConsent);
70
+ return NativeDdSdkSpec.setTrackingConsent(trackingConsent);
76
71
  }
77
72
 
78
73
  sendTelemetryLog(
@@ -80,11 +75,11 @@ export class DdSdkWrapper implements DdNativeSdkType {
80
75
  attributes: object,
81
76
  config: object
82
77
  ): Promise<void> {
83
- return NativeDdSdk.sendTelemetryLog(message, attributes, config);
78
+ return NativeDdSdkSpec.sendTelemetryLog(message, attributes, config);
84
79
  }
85
80
 
86
81
  telemetryDebug(message: string): Promise<void> {
87
- return NativeDdSdk.telemetryDebug(message);
82
+ return NativeDdSdkSpec.telemetryDebug(message);
88
83
  }
89
84
 
90
85
  telemetryError(
@@ -92,23 +87,23 @@ export class DdSdkWrapper implements DdNativeSdkType {
92
87
  stack: string,
93
88
  kind: string
94
89
  ): Promise<void> {
95
- return NativeDdSdk.telemetryError(message, stack, kind);
90
+ return NativeDdSdkSpec.telemetryError(message, stack, kind);
96
91
  }
97
92
 
98
93
  consumeWebviewEvent(message: string): Promise<void> {
99
- return NativeDdSdk.consumeWebviewEvent(message);
94
+ return NativeDdSdkSpec.consumeWebviewEvent(message);
100
95
  }
101
96
 
102
97
  clearAllData(): Promise<void> {
103
- return NativeDdSdk.clearAllData();
98
+ return NativeDdSdkSpec.clearAllData();
104
99
  }
105
100
 
106
101
  addListener(eventType: string): void {
107
- return NativeDdSdk.addListener(eventType);
102
+ return NativeDdSdkSpec.addListener(eventType);
108
103
  }
109
104
 
110
105
  removeListeners(count: number): void {
111
- return NativeDdSdk.removeListeners(count);
106
+ return NativeDdSdkSpec.removeListeners(count);
112
107
  }
113
108
 
114
109
  _setAttributeEncodersForTesting(
@@ -117,5 +112,3 @@ export class DdSdkWrapper implements DdNativeSdkType {
117
112
  this._attributeEncoders = [...attributeEncoders];
118
113
  }
119
114
  }
120
-
121
- export { NativeDdSdk };