@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
@@ -10,7 +10,7 @@ import { AccountInfoSingleton } from '../AccountInfoSingleton/AccountInfoSinglet
10
10
  import type { AccountInfo } from '../AccountInfoSingleton/types';
11
11
  import { AttributesSingleton } from '../AttributesSingleton/AttributesSingleton';
12
12
  import type { Attributes } from '../AttributesSingleton/types';
13
- import { NativeDdSdk } from '../DdSdkInternal';
13
+ import { DdSdk } from '../DdSdk';
14
14
  import { UserInfoSingleton } from '../UserInfoSingleton/UserInfoSingleton';
15
15
  import type { UserInfo } from '../UserInfoSingleton/types';
16
16
 
@@ -92,7 +92,7 @@ export class EventMapper<RawEvent, MapperEvent, NativeEvent> {
92
92
  )}: ${error}`,
93
93
  SdkVerbosity.WARN
94
94
  );
95
- NativeDdSdk.telemetryDebug('Error while running the event mapper');
95
+ DdSdk.telemetryDebug('Error while running the event mapper');
96
96
  return this.formatMapperEventForNative(backupEvent, backupEvent);
97
97
  }
98
98
  };
@@ -4,7 +4,7 @@
4
4
  * Copyright 2016-Present Datadog, Inc.
5
5
  */
6
6
 
7
- import { NativeDdSdk } from '../../DdSdkInternal';
7
+ import NativeDdSdkSpec from '../../../specs/NativeDdSdk';
8
8
  import { EventMapper } from '../EventMapper';
9
9
 
10
10
  describe('EventMapper', () => {
@@ -26,7 +26,7 @@ describe('EventMapper', () => {
26
26
  ).toEqual({
27
27
  someData: 'some data'
28
28
  });
29
- expect(NativeDdSdk.telemetryDebug).toHaveBeenCalledWith(
29
+ expect(NativeDdSdkSpec.telemetryDebug).toHaveBeenCalledWith(
30
30
  'Error while running the event mapper'
31
31
  );
32
32
  });
@@ -63,6 +63,55 @@ it('M use unix time W reactNative time unavailable', () => {
63
63
  expect(now).toBe(1000);
64
64
  });
65
65
 
66
+ it('M keep the offset W unix time drifts within the tolerance', () => {
67
+ // GIVEN
68
+ const timeProvider = new MockTimeProvider(1000, 100);
69
+ timeProvider.now();
70
+
71
+ // WHEN
72
+ timeProvider.unixMockedTime = 2000 + 999;
73
+ timeProvider.reactNativeMockedTime = 1100.5;
74
+ const now = timeProvider.now();
75
+
76
+ // THEN
77
+ expect(now).toBe(2000.5);
78
+ });
79
+
80
+ it('M re-sync the offset W unix time moves forward beyond the tolerance', () => {
81
+ // GIVEN
82
+ const timeProvider = new MockTimeProvider(1000, 100);
83
+ timeProvider.now();
84
+
85
+ // WHEN
86
+ const clockChangeMs = 20 * 60 * 1000;
87
+ timeProvider.unixMockedTime = 2000 + clockChangeMs;
88
+ timeProvider.reactNativeMockedTime = 1100;
89
+ const now = timeProvider.now();
90
+
91
+ timeProvider.unixMockedTime = 2010 + clockChangeMs;
92
+ timeProvider.reactNativeMockedTime = 1110.5;
93
+ const nextNow = timeProvider.now();
94
+
95
+ // THEN
96
+ expect(now).toBe(2000 + clockChangeMs);
97
+ expect(nextNow).toBe(2010.5 + clockChangeMs);
98
+ });
99
+
100
+ it('M re-sync the offset W unix time moves backward beyond the tolerance', () => {
101
+ // GIVEN
102
+ const timeProvider = new MockTimeProvider(1_000_000_000, 100);
103
+ timeProvider.now();
104
+
105
+ // WHEN
106
+ const clockChangeMs = -20 * 60 * 1000;
107
+ timeProvider.unixMockedTime = 1_000_001_000 + clockChangeMs;
108
+ timeProvider.reactNativeMockedTime = 1100;
109
+ const now = timeProvider.now();
110
+
111
+ // THEN
112
+ expect(now).toBe(1_000_001_000 + clockChangeMs);
113
+ });
114
+
66
115
  it('M ignore performance W global.performance unavailable', () => {
67
116
  // GIVEN
68
117
  // @ts-expect-error performance is not supposed to be null, but we treat it as such for testing purposes
@@ -4,6 +4,8 @@
4
4
  * Copyright 2016-Present Datadog, Inc.
5
5
  */
6
6
 
7
+ const MAX_DRIFT_MS = 1000;
8
+
7
9
  /**
8
10
  * A Timestamp structure holding the
9
11
  */
@@ -37,7 +39,14 @@ export abstract class TimeProvider {
37
39
  now(): number {
38
40
  const timestamp = this.getTimestamp();
39
41
 
40
- if (timestamp.reactNative != null && this.baseOffset === 0) {
42
+ if (
43
+ timestamp.reactNative != null &&
44
+ (this.baseOffset === 0 ||
45
+ Math.abs(
46
+ timestamp.unix - (this.baseOffset + timestamp.reactNative)
47
+ ) > MAX_DRIFT_MS)
48
+ ) {
49
+ // sync the offset on first use, or when the device clock changed since the last sync
41
50
  this.baseOffset = timestamp.unix - timestamp.reactNative;
42
51
  }
43
52
 
package/src/version.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  // generated by genversion
2
- export const version = '3.8.0';
2
+ export const version = '3.9.0';