@datadog/mobile-react-native 1.3.0 → 1.4.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 (99) hide show
  1. package/DatadogSDKReactNative.podspec +2 -2
  2. package/android/build.gradle +58 -64
  3. package/android/src/main/kotlin/com/datadog/reactnative/DdSdk.kt +36 -2
  4. package/android/src/main/kotlin/com/datadog/reactnative/DdSdkConfigurationExt.kt +14 -0
  5. package/android/src/test/kotlin/com/datadog/reactnative/DdSdkTest.kt +162 -16
  6. package/android/src/test/kotlin/com/datadog/tools/unit/MapExt.kt +7 -0
  7. package/ios/Sources/DdSdk.swift +2 -2
  8. package/ios/Sources/RNDdSdkConfiguration.swift +42 -0
  9. package/lib/commonjs/DdSdkReactNative.js +2 -2
  10. package/lib/commonjs/DdSdkReactNative.js.map +1 -1
  11. package/lib/commonjs/DdSdkReactNativeConfiguration.js +26 -1
  12. package/lib/commonjs/DdSdkReactNativeConfiguration.js.map +1 -1
  13. package/lib/commonjs/index.js +12 -0
  14. package/lib/commonjs/index.js.map +1 -1
  15. package/lib/commonjs/rum/instrumentation/interactionTracking/DdRumUserInteractionTracking.js +9 -0
  16. package/lib/commonjs/rum/instrumentation/interactionTracking/DdRumUserInteractionTracking.js.map +1 -1
  17. package/lib/commonjs/rum/instrumentation/resourceTracking/DdRumResourceTracking.js +1 -1
  18. package/lib/commonjs/rum/instrumentation/resourceTracking/DdRumResourceTracking.js.map +1 -1
  19. package/lib/commonjs/rum/instrumentation/resourceTracking/domain/distributedTracing.js +59 -41
  20. package/lib/commonjs/rum/instrumentation/resourceTracking/domain/distributedTracing.js.map +1 -1
  21. package/lib/commonjs/rum/instrumentation/resourceTracking/domain/distributedTracingHeaders.js +136 -0
  22. package/lib/commonjs/rum/instrumentation/resourceTracking/domain/distributedTracingHeaders.js.map +1 -0
  23. package/lib/commonjs/rum/instrumentation/resourceTracking/domain/firstPartyHosts.js +39 -6
  24. package/lib/commonjs/rum/instrumentation/resourceTracking/domain/firstPartyHosts.js.map +1 -1
  25. package/lib/commonjs/rum/instrumentation/resourceTracking/domain/interfaces/RequestProxy.js.map +1 -1
  26. package/lib/commonjs/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/ResourceReporter.js +3 -3
  27. package/lib/commonjs/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/ResourceReporter.js.map +1 -1
  28. package/lib/commonjs/rum/instrumentation/resourceTracking/implementation/XHRProxy.js +12 -21
  29. package/lib/commonjs/rum/instrumentation/resourceTracking/implementation/XHRProxy.js.map +1 -1
  30. package/lib/commonjs/rum/types.js +19 -1
  31. package/lib/commonjs/rum/types.js.map +1 -1
  32. package/lib/commonjs/version.js +1 -1
  33. package/lib/commonjs/version.js.map +1 -1
  34. package/lib/module/DdSdkReactNative.js +3 -3
  35. package/lib/module/DdSdkReactNative.js.map +1 -1
  36. package/lib/module/DdSdkReactNativeConfiguration.js +22 -0
  37. package/lib/module/DdSdkReactNativeConfiguration.js.map +1 -1
  38. package/lib/module/index.js +3 -3
  39. package/lib/module/index.js.map +1 -1
  40. package/lib/module/rum/instrumentation/interactionTracking/DdRumUserInteractionTracking.js +9 -0
  41. package/lib/module/rum/instrumentation/interactionTracking/DdRumUserInteractionTracking.js.map +1 -1
  42. package/lib/module/rum/instrumentation/resourceTracking/DdRumResourceTracking.js +2 -2
  43. package/lib/module/rum/instrumentation/resourceTracking/DdRumResourceTracking.js.map +1 -1
  44. package/lib/module/rum/instrumentation/resourceTracking/domain/distributedTracing.js +57 -35
  45. package/lib/module/rum/instrumentation/resourceTracking/domain/distributedTracing.js.map +1 -1
  46. package/lib/module/rum/instrumentation/resourceTracking/domain/distributedTracingHeaders.js +115 -0
  47. package/lib/module/rum/instrumentation/resourceTracking/domain/distributedTracingHeaders.js.map +1 -0
  48. package/lib/module/rum/instrumentation/resourceTracking/domain/firstPartyHosts.js +37 -3
  49. package/lib/module/rum/instrumentation/resourceTracking/domain/firstPartyHosts.js.map +1 -1
  50. package/lib/module/rum/instrumentation/resourceTracking/domain/interfaces/RequestProxy.js.map +1 -1
  51. package/lib/module/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/ResourceReporter.js +3 -3
  52. package/lib/module/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/ResourceReporter.js.map +1 -1
  53. package/lib/module/rum/instrumentation/resourceTracking/implementation/XHRProxy.js +10 -15
  54. package/lib/module/rum/instrumentation/resourceTracking/implementation/XHRProxy.js.map +1 -1
  55. package/lib/module/rum/types.js +16 -0
  56. package/lib/module/rum/types.js.map +1 -1
  57. package/lib/module/version.js +1 -1
  58. package/lib/module/version.js.map +1 -1
  59. package/lib/typescript/DdSdkReactNativeConfiguration.d.ts +11 -3
  60. package/lib/typescript/index.d.ts +3 -3
  61. package/lib/typescript/rum/eventMappers/resourceEventMapper.d.ts +0 -1
  62. package/lib/typescript/rum/instrumentation/interactionTracking/DdRumUserInteractionTracking.d.ts +1 -0
  63. package/lib/typescript/rum/instrumentation/resourceTracking/DdRumResourceTracking.d.ts +2 -1
  64. package/lib/typescript/rum/instrumentation/resourceTracking/domain/distributedTracing.d.ts +32 -6
  65. package/lib/typescript/rum/instrumentation/resourceTracking/domain/distributedTracingHeaders.d.ts +21 -0
  66. package/lib/typescript/rum/instrumentation/resourceTracking/domain/firstPartyHosts.d.ts +4 -2
  67. package/lib/typescript/rum/instrumentation/resourceTracking/domain/interfaces/RequestProxy.d.ts +6 -1
  68. package/lib/typescript/rum/instrumentation/resourceTracking/domain/interfaces/RumResource.d.ts +0 -1
  69. package/lib/typescript/rum/instrumentation/resourceTracking/implementation/XHRProxy.d.ts +0 -6
  70. package/lib/typescript/rum/instrumentation/resourceTracking/implementation/responseSize.d.ts +0 -1
  71. package/lib/typescript/rum/types.d.ts +17 -0
  72. package/lib/typescript/version.d.ts +1 -1
  73. package/package.json +2 -2
  74. package/src/DdSdkReactNative.tsx +8 -4
  75. package/src/DdSdkReactNativeConfiguration.tsx +36 -3
  76. package/src/__tests__/DdSdkReactNative.test.tsx +16 -4
  77. package/src/__tests__/DdSdkReactNativeConfiguration.test.ts +7 -6
  78. package/src/__tests__/rum/instrumentation/DdRumErrorTracking.test.tsx +2 -1
  79. package/src/__tests__/rum/instrumentation/DdRumUserInteractionTracking.test.tsx +130 -114
  80. package/src/index.tsx +6 -3
  81. package/src/rum/__tests__/DdRum.test.ts +17 -1
  82. package/src/rum/instrumentation/interactionTracking/DdRumUserInteractionTracking.tsx +8 -0
  83. package/src/rum/instrumentation/resourceTracking/DdRumResourceTracking.tsx +6 -3
  84. package/src/rum/instrumentation/resourceTracking/__tests__/DdRumResourceTracking.test.ts +15 -3
  85. package/src/rum/instrumentation/resourceTracking/domain/__tests__/distributedTracing.test.ts +64 -24
  86. package/src/rum/instrumentation/resourceTracking/domain/__tests__/firstPartyHosts.test.ts +19 -7
  87. package/src/rum/instrumentation/resourceTracking/domain/distributedTracing.tsx +82 -40
  88. package/src/rum/instrumentation/resourceTracking/domain/distributedTracingHeaders.ts +141 -0
  89. package/src/rum/instrumentation/resourceTracking/domain/firstPartyHosts.ts +43 -7
  90. package/src/rum/instrumentation/resourceTracking/domain/interfaces/RequestProxy.ts +8 -1
  91. package/src/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/ResourceReporter.ts +4 -4
  92. package/src/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/__tests__/ResourceReporter.test.ts +2 -1
  93. package/src/rum/instrumentation/resourceTracking/implementation/XHRProxy.ts +8 -23
  94. package/src/rum/instrumentation/resourceTracking/implementation/__tests__/XHRProxy.test.ts +257 -74
  95. package/src/rum/types.ts +19 -0
  96. package/src/sdk/DatadogProvider/Buffer/__tests__/BufferSingleton.test.ts +2 -1
  97. package/src/sdk/DatadogProvider/__tests__/initialization.test.tsx +5 -4
  98. package/src/sdk/DatadogProvider/__tests__/initializationModes.test.tsx +6 -2
  99. package/src/version.ts +1 -1
@@ -1,6 +1,8 @@
1
+ import type { FirstPartyHost, PropagatorType } from '../../../types';
2
+ import type { RegexMap } from './interfaces/RequestProxy';
1
3
  export declare type Hostname = {
2
4
  _type: 'Hostname';
3
5
  } & string;
4
6
  export declare const NO_MATCH_REGEX: RegExp;
5
- export declare const firstPartyHostsRegexBuilder: (firstPartyHosts: string[]) => RegExp;
6
- export declare const isHostFirstParty: (hostname: Hostname, firstPartyHostsRegex: RegExp) => boolean;
7
+ export declare const firstPartyHostsRegexMapBuilder: (firstPartyHosts: FirstPartyHost[]) => RegexMap;
8
+ export declare const getPropagatorsForHost: (hostname: Hostname, firstPartyHostsRegexMap: RegexMap) => PropagatorType[] | null;
@@ -1,7 +1,12 @@
1
+ import type { PropagatorType } from '../../../../types';
1
2
  export interface RequestProxyOptions {
2
3
  tracingSamplingRate: number;
3
- firstPartyHostsRegex: RegExp;
4
+ firstPartyHostsRegexMap: RegexMap;
4
5
  }
6
+ export declare type RegexMap = {
7
+ regex: RegExp;
8
+ propagatorType: PropagatorType;
9
+ }[];
5
10
  export declare abstract class RequestProxy {
6
11
  abstract onTrackingStart: (context: RequestProxyOptions) => void;
7
12
  abstract onTrackingStop: () => void;
@@ -1,4 +1,3 @@
1
- /// <reference types="react-native" />
2
1
  import type { ResourceKind } from '../../../../types';
3
2
  import type { DdRumResourceTracingAttributes } from '../distributedTracing';
4
3
  export interface RUMResource {
@@ -1,12 +1,6 @@
1
- /// <reference types="react-native" />
2
1
  import type { RequestProxyOptions } from '../domain/interfaces/RequestProxy';
3
2
  import { RequestProxy } from '../domain/interfaces/RequestProxy';
4
3
  import type { ResourceReporter } from './DatadogRumResource/ResourceReporter';
5
- export declare const TRACE_ID_HEADER_KEY = "x-datadog-trace-id";
6
- export declare const PARENT_ID_HEADER_KEY = "x-datadog-parent-id";
7
- export declare const ORIGIN_HEADER_KEY = "x-datadog-origin";
8
- export declare const SAMPLING_PRIORITY_HEADER_KEY = "x-datadog-sampling-priority";
9
- export declare const ORIGIN_RUM = "rum";
10
4
  interface XHRProxyProviders {
11
5
  xhrType: typeof XMLHttpRequest;
12
6
  resourceReporter: ResourceReporter;
@@ -1,3 +1,2 @@
1
- /// <reference types="react-native" />
2
1
  export declare const RESOURCE_SIZE_ERROR_MESSAGE = "Couldn't get resource size, because an error occured: ";
3
2
  export declare function calculateResponseSize(xhr: XMLHttpRequest): number;
@@ -108,3 +108,20 @@ export declare enum ErrorSource {
108
108
  WEBVIEW = "WEBVIEW",
109
109
  CUSTOM = "CUSTOM"
110
110
  }
111
+ /**
112
+ * Type of instrumentation on the host.
113
+ * - DATADOG: Datadog’s propagator (`x-datadog-*`)
114
+ * - TRACECONTEXT: W3C Trace Context (`traceparent`)
115
+ * - B3: B3 single header (`b3`)
116
+ * - B3MULTI: B3 multiple headers (`X-B3-*`)
117
+ */
118
+ export declare enum PropagatorType {
119
+ DATADOG = "datadog",
120
+ TRACECONTEXT = "tracecontext",
121
+ B3 = "b3",
122
+ B3MULTI = "b3multi"
123
+ }
124
+ export declare type FirstPartyHost = {
125
+ match: string;
126
+ propagatorTypes: PropagatorType[];
127
+ };
@@ -1 +1 @@
1
- export declare const version = "1.3.0";
1
+ export declare const version = "1.4.0";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@datadog/mobile-react-native",
3
- "version": "1.3.0",
3
+ "version": "1.4.0",
4
4
  "description": "A client-side React Native module to interact with Datadog",
5
5
  "keywords": [
6
6
  "datadog",
@@ -77,5 +77,5 @@
77
77
  ]
78
78
  ]
79
79
  },
80
- "gitHead": "16a9d318f9882dc85339b9b59045157d1bc62e7b"
80
+ "gitHead": "cc9c7937cecfd48720ec46852c24965f4a00bab4"
81
81
  }
@@ -10,7 +10,8 @@ import {
10
10
  DdSdkReactNativeConfiguration,
11
11
  buildConfigurationFromPartialConfiguration,
12
12
  addDefaultValuesToAutoInstrumentationConfiguration,
13
- InitializationMode
13
+ InitializationMode,
14
+ formatFirstPartyHosts
14
15
  } from './DdSdkReactNativeConfiguration';
15
16
  import type {
16
17
  AutoInstrumentationParameters,
@@ -301,8 +302,9 @@ export class DdSdkReactNative {
301
302
  ] = `-${configuration.versionSuffix}`;
302
303
  }
303
304
 
304
- configuration.additionalConfig['_dd.first_party_hosts'] =
305
- configuration.firstPartyHosts;
305
+ configuration.additionalConfig[
306
+ '_dd.first_party_hosts'
307
+ ] = formatFirstPartyHosts(configuration.firstPartyHosts);
306
308
  };
307
309
 
308
310
  private static enableFeatures(
@@ -322,7 +324,9 @@ export class DdSdkReactNative {
322
324
  if (configuration.trackResources) {
323
325
  DdRumResourceTracking.startTracking({
324
326
  tracingSamplingRate: configuration.resourceTracingSamplingRate,
325
- firstPartyHosts: configuration.firstPartyHosts
327
+ firstPartyHosts: formatFirstPartyHosts(
328
+ configuration.firstPartyHosts
329
+ )
326
330
  });
327
331
  }
328
332
 
@@ -11,6 +11,8 @@ import type { LogEventMapper } from './logs/types';
11
11
  import type { ActionEventMapper } from './rum/eventMappers/actionEventMapper';
12
12
  import type { ErrorEventMapper } from './rum/eventMappers/errorEventMapper';
13
13
  import type { ResourceEventMapper } from './rum/eventMappers/resourceEventMapper';
14
+ import type { FirstPartyHost } from './rum/types';
15
+ import { PropagatorType } from './rum/types';
14
16
 
15
17
  export enum VitalsUpdateFrequency {
16
18
  FREQUENT = 'FREQUENT',
@@ -19,6 +21,37 @@ export enum VitalsUpdateFrequency {
19
21
  NEVER = 'NEVER'
20
22
  }
21
23
 
24
+ export type FirstPartyHostsConfiguration = (
25
+ | FirstPartyHost
26
+ | LegacyFirstPartyHost
27
+ )[];
28
+
29
+ export type LegacyFirstPartyHost = string;
30
+
31
+ const isLegacyFirstPartyHost = (
32
+ firstPartyHost: FirstPartyHost | LegacyFirstPartyHost
33
+ ): firstPartyHost is LegacyFirstPartyHost => {
34
+ return typeof firstPartyHost === 'string';
35
+ };
36
+
37
+ /**
38
+ * Defaults legacy first party hosts format to Datadog first party hosts to keep
39
+ * retro-compatibility before OTel support was introduced.
40
+ */
41
+ export const formatFirstPartyHosts = (
42
+ firstPartyHosts: FirstPartyHostsConfiguration
43
+ ): FirstPartyHost[] => {
44
+ return firstPartyHosts.map(host => {
45
+ if (isLegacyFirstPartyHost(host)) {
46
+ return {
47
+ match: host,
48
+ propagatorTypes: [PropagatorType.DATADOG]
49
+ };
50
+ }
51
+ return host;
52
+ });
53
+ };
54
+
22
55
  const DEFAULTS = {
23
56
  nativeCrashReportEnabled: false,
24
57
  sessionSamplingRate: 100.0,
@@ -87,7 +120,7 @@ export class DdSdkReactNativeConfiguration {
87
120
  *
88
121
  * Matches domains and subdomains, e.g. `['example.com']` matches `example.com` and `api.example.com`.
89
122
  */
90
- public firstPartyHosts: string[] = DEFAULTS.getFirstPartyHosts();
123
+ public firstPartyHosts: FirstPartyHostsConfiguration = DEFAULTS.getFirstPartyHosts();
91
124
  /**
92
125
  * Overrides the reported version of the app.
93
126
  * Accepted characters are alphanumerics and `_`, `-`, `:`, `.`, `/`.
@@ -182,7 +215,7 @@ export class DdSdkReactNativeConfiguration {
182
215
  export type AutoInstrumentationConfiguration = {
183
216
  readonly trackInteractions: boolean;
184
217
  readonly trackResources: boolean;
185
- readonly firstPartyHosts?: string[];
218
+ readonly firstPartyHosts?: FirstPartyHostsConfiguration;
186
219
  readonly resourceTracingSamplingRate?: number;
187
220
  readonly trackErrors: boolean;
188
221
  readonly logEventMapper?: LogEventMapper | null;
@@ -197,7 +230,7 @@ export type AutoInstrumentationConfiguration = {
197
230
  export type AutoInstrumentationParameters = {
198
231
  readonly trackInteractions: boolean;
199
232
  readonly trackResources: boolean;
200
- readonly firstPartyHosts: string[];
233
+ readonly firstPartyHosts: FirstPartyHostsConfiguration;
201
234
  readonly resourceTracingSamplingRate: number;
202
235
  readonly trackErrors: boolean;
203
236
  readonly logEventMapper: LogEventMapper | null;
@@ -17,7 +17,7 @@ import { DdRum } from '../rum/DdRum';
17
17
  import { DdRumErrorTracking } from '../rum/instrumentation/DdRumErrorTracking';
18
18
  import { DdRumUserInteractionTracking } from '../rum/instrumentation/interactionTracking/DdRumUserInteractionTracking';
19
19
  import { DdRumResourceTracking } from '../rum/instrumentation/resourceTracking/DdRumResourceTracking';
20
- import { ErrorSource, RumActionType } from '../rum/types';
20
+ import { ErrorSource, PropagatorType, RumActionType } from '../rum/types';
21
21
  import { AttributesSingleton } from '../sdk/AttributesSingleton/AttributesSingleton';
22
22
  import { UserInfoSingleton } from '../sdk/UserInfoSingleton/UserInfoSingleton';
23
23
  import type { DdSdkConfiguration } from '../types';
@@ -488,7 +488,13 @@ describe('DdSdkReactNative', () => {
488
488
  true
489
489
  );
490
490
  configuration.resourceTracingSamplingRate = 42;
491
- configuration.firstPartyHosts = ['api.example.com'];
491
+ configuration.firstPartyHosts = [
492
+ 'api.example.com',
493
+ {
494
+ match: 'something.fr',
495
+ propagatorTypes: [PropagatorType.DATADOG]
496
+ }
497
+ ];
492
498
 
493
499
  NativeModules.DdSdk.initialize.mockResolvedValue(null);
494
500
 
@@ -507,14 +513,20 @@ describe('DdSdkReactNative', () => {
507
513
  '_dd.sdk_version': sdkVersion,
508
514
  '_dd.native_view_tracking': false,
509
515
  '_dd.native_interaction_tracking': false,
510
- '_dd.first_party_hosts': ['api.example.com']
516
+ '_dd.first_party_hosts': [
517
+ { match: 'api.example.com', propagatorTypes: ['datadog'] },
518
+ { match: 'something.fr', propagatorTypes: ['datadog'] }
519
+ ]
511
520
  });
512
521
  expect(DdRumResourceTracking.startTracking).toHaveBeenCalledTimes(
513
522
  1
514
523
  );
515
524
  expect(DdRumResourceTracking.startTracking).toHaveBeenCalledWith({
516
525
  tracingSamplingRate: 42,
517
- firstPartyHosts: ['api.example.com']
526
+ firstPartyHosts: [
527
+ { match: 'api.example.com', propagatorTypes: ['datadog'] },
528
+ { match: 'something.fr', propagatorTypes: ['datadog'] }
529
+ ]
518
530
  });
519
531
  });
520
532
 
@@ -28,12 +28,12 @@ describe('DdSdkReactNativeConfiguration', () => {
28
28
  ).toMatchInlineSnapshot(`
29
29
  DdSdkReactNativeConfiguration {
30
30
  "actionEventMapper": null,
31
- "additionalConfig": Object {},
31
+ "additionalConfig": {},
32
32
  "applicationId": "fake-app-id",
33
33
  "clientToken": "fake-client-token",
34
34
  "env": "fake-env",
35
35
  "errorEventMapper": null,
36
- "firstPartyHosts": Array [],
36
+ "firstPartyHosts": [],
37
37
  "logEventMapper": null,
38
38
  "longTaskThresholdMs": 0,
39
39
  "nativeCrashReportEnabled": false,
@@ -85,6 +85,7 @@ describe('DdSdkReactNativeConfiguration', () => {
85
85
  'api.com',
86
86
  443
87
87
  ),
88
+
88
89
  serviceName: 'com.test.app',
89
90
  version: '1.4.5',
90
91
  versionSuffix: 'codepush-3',
@@ -98,14 +99,14 @@ describe('DdSdkReactNativeConfiguration', () => {
98
99
  ).toMatchInlineSnapshot(`
99
100
  DdSdkReactNativeConfiguration {
100
101
  "actionEventMapper": [Function],
101
- "additionalConfig": Object {
102
+ "additionalConfig": {
102
103
  "additionalField": "fake-value",
103
104
  },
104
105
  "applicationId": "fake-app-id",
105
106
  "clientToken": "fake-client-token",
106
107
  "env": "fake-env",
107
108
  "errorEventMapper": [Function],
108
- "firstPartyHosts": Array [
109
+ "firstPartyHosts": [
109
110
  "api.com",
110
111
  ],
111
112
  "logEventMapper": [Function],
@@ -168,12 +169,12 @@ describe('DdSdkReactNativeConfiguration', () => {
168
169
  ).toMatchInlineSnapshot(`
169
170
  DdSdkReactNativeConfiguration {
170
171
  "actionEventMapper": null,
171
- "additionalConfig": Object {},
172
+ "additionalConfig": {},
172
173
  "applicationId": "",
173
174
  "clientToken": "",
174
175
  "env": "",
175
176
  "errorEventMapper": null,
176
- "firstPartyHosts": Array [],
177
+ "firstPartyHosts": [],
177
178
  "logEventMapper": null,
178
179
  "longTaskThresholdMs": false,
179
180
  "nativeCrashReportEnabled": false,
@@ -32,7 +32,8 @@ const baseConsoleError = (...params: unknown) => {
32
32
  };
33
33
  let originalConsoleError;
34
34
 
35
- const flushPromises = () => new Promise(setImmediate);
35
+ const flushPromises = () =>
36
+ new Promise(jest.requireActual('timers').setImmediate);
36
37
 
37
38
  beforeEach(() => {
38
39
  DdRum.addError.mockClear();
@@ -35,19 +35,14 @@ jest.mock(
35
35
 
36
36
  // Silence the warning https://github.com/facebook/react-native/issues/11094#issuecomment-263240420
37
37
  jest.mock('react-native/Libraries/Animated/NativeAnimatedHelper');
38
- jest.useFakeTimers();
39
-
40
- let originalMethod: typeof React.createElement;
41
38
 
42
39
  beforeEach(() => {
43
- originalMethod = React.createElement;
44
40
  jest.setTimeout(20000);
45
41
  jest.clearAllMocks();
46
42
  });
47
43
 
48
44
  afterEach(() => {
49
- DdRumUserInteractionTracking['isTracking'] = false;
50
- React.createElement = originalMethod;
45
+ DdRumUserInteractionTracking.stopTracking();
51
46
  });
52
47
 
53
48
  // Because the way RN decouples the component we cannot assert how many times the `interceptOnPress` function was called.
@@ -219,130 +214,151 @@ it('M intercept and send a RUM event W onPress { TouchableWithoutFeedback compon
219
214
  expect(mockedInterceptOnPressFunction).toBeCalled();
220
215
  });
221
216
 
222
- it('M keep memoization working for elements W an onPress prop is passed', async () => {
223
- // GIVEN
224
- DdRumUserInteractionTracking.startTracking();
225
- let rendersCount = 0;
226
- const DummyComponent = props => {
227
- rendersCount++;
228
- return (
229
- <TouchableWithoutFeedback onPress={props.onPress}>
230
- <View style={styles.button}>
231
- <Text style={styles.button}>Click me</Text>
232
- </View>
233
- </TouchableWithoutFeedback>
234
- );
235
- };
236
- const stableOnPress = () => {};
237
- const MemoizedComponent = React.memo(DummyComponent);
238
- const { rerender } = render(<MemoizedComponent onPress={stableOnPress} />);
239
- expect(rendersCount).toBe(1);
240
-
241
- // WHEN
242
- rerender(<MemoizedComponent onPress={stableOnPress} />);
243
- // THEN
244
- expect(rendersCount).toBe(1);
217
+ describe('startTracking memoization', () => {
218
+ beforeEach(() => {
219
+ jest.setTimeout(20000);
220
+ jest.clearAllMocks();
221
+ });
245
222
 
246
- // WHEN
247
- rerender(<MemoizedComponent onPress={() => {}} />);
248
- // THEN
249
- expect(rendersCount).toBe(2);
250
- });
223
+ afterEach(() => {
224
+ DdRumUserInteractionTracking.stopTracking();
225
+ });
251
226
 
252
- it('M keep memoization working for elements W no onPress prop is passed', async () => {
253
- // GIVEN
254
- DdRumUserInteractionTracking.startTracking();
255
- let rendersCount = 0;
256
- const DummyComponent = props => {
257
- rendersCount++;
258
- return (
259
- <View style={styles.button}>
260
- <Text style={styles.button}>{props.title}</Text>
261
- </View>
227
+ it('M keep memoization working for elements W an onPress prop is passed', async () => {
228
+ // GIVEN
229
+ DdRumUserInteractionTracking.startTracking();
230
+ let rendersCount = 0;
231
+ const DummyComponent = props => {
232
+ rendersCount++;
233
+ return (
234
+ <TouchableWithoutFeedback onPress={props.onPress}>
235
+ <View style={styles.button}>
236
+ <Text style={styles.button}>Click me</Text>
237
+ </View>
238
+ </TouchableWithoutFeedback>
239
+ );
240
+ };
241
+ const stableOnPress = () => {};
242
+ const MemoizedComponent = React.memo(DummyComponent);
243
+ const { rerender } = render(
244
+ <MemoizedComponent onPress={stableOnPress} />
262
245
  );
263
- };
264
- const MemoizedComponent = React.memo(DummyComponent);
265
- const { rerender } = render(<MemoizedComponent title={'Click me'} />);
266
- expect(rendersCount).toBe(1);
246
+ expect(rendersCount).toBe(1);
267
247
 
268
- // WHEN
269
- rerender(<MemoizedComponent title={'Click me'} />);
270
- // THEN
271
- expect(rendersCount).toBe(1);
248
+ // WHEN
249
+ rerender(<MemoizedComponent onPress={stableOnPress} />);
250
+ // THEN
251
+ expect(rendersCount).toBe(1);
272
252
 
273
- // WHEN
274
- rerender(<MemoizedComponent title={'New title'} />);
275
- // THEN
276
- expect(rendersCount).toBe(2);
277
- });
253
+ // WHEN
254
+ rerender(<MemoizedComponent onPress={() => {}} />);
255
+ // THEN
256
+ expect(rendersCount).toBe(2);
257
+ });
278
258
 
279
- it('M keep memoization working for elements W an onPress prop is passed and custom arePropsEqual specified', async () => {
280
- // GIVEN
281
- DdRumUserInteractionTracking.startTracking();
282
- let rendersCount = 0;
283
- const DummyComponent = props => {
284
- rendersCount++;
285
- return (
286
- <TouchableWithoutFeedback onPress={props.onPress}>
259
+ it('M keep memoization working for elements W no onPress prop is passed', async () => {
260
+ // GIVEN
261
+ DdRumUserInteractionTracking.startTracking();
262
+ let rendersCount = 0;
263
+ const DummyComponent = props => {
264
+ rendersCount++;
265
+ return (
287
266
  <View style={styles.button}>
288
267
  <Text style={styles.button}>{props.title}</Text>
289
268
  </View>
290
- </TouchableWithoutFeedback>
269
+ );
270
+ };
271
+ const MemoizedComponent = React.memo(DummyComponent);
272
+ const { rerender } = render(<MemoizedComponent title={'Click me'} />);
273
+ expect(rendersCount).toBe(1);
274
+
275
+ // WHEN
276
+ rerender(<MemoizedComponent title={'Click me'} />);
277
+ // THEN
278
+ expect(rendersCount).toBe(1);
279
+
280
+ // WHEN
281
+ rerender(<MemoizedComponent title={'New title'} />);
282
+ // THEN
283
+ expect(rendersCount).toBe(2);
284
+ });
285
+
286
+ it('M keep memoization working for elements W an onPress prop is passed and custom arePropsEqual specified', async () => {
287
+ // GIVEN
288
+ DdRumUserInteractionTracking.startTracking();
289
+ let rendersCount = 0;
290
+ const DummyComponent = props => {
291
+ rendersCount++;
292
+ return (
293
+ <TouchableWithoutFeedback onPress={props.onPress}>
294
+ <View style={styles.button}>
295
+ <Text style={styles.button}>{props.title}</Text>
296
+ </View>
297
+ </TouchableWithoutFeedback>
298
+ );
299
+ };
300
+ const stableOnPress = () => {};
301
+ const MemoizedComponent = React.memo(
302
+ DummyComponent,
303
+ (previousProps, nextProps) =>
304
+ previousProps.title === nextProps.title
291
305
  );
292
- };
293
- const stableOnPress = () => {};
294
- const MemoizedComponent = React.memo(
295
- DummyComponent,
296
- (previousProps, nextProps) => previousProps.title === nextProps.title
297
- );
298
- const { rerender } = render(
299
- <MemoizedComponent onPress={stableOnPress} title={'Click me'} />
300
- );
301
- expect(rendersCount).toBe(1);
306
+ const { rerender } = render(
307
+ <MemoizedComponent onPress={stableOnPress} title={'Click me'} />
308
+ );
309
+ expect(rendersCount).toBe(1);
302
310
 
303
- // WHEN
304
- rerender(<MemoizedComponent onPress={stableOnPress} title={'Click me'} />);
305
- // THEN
306
- expect(rendersCount).toBe(1);
311
+ // WHEN
312
+ rerender(
313
+ <MemoizedComponent onPress={stableOnPress} title={'Click me'} />
314
+ );
315
+ // THEN
316
+ expect(rendersCount).toBe(1);
307
317
 
308
- // WHEN
309
- rerender(<MemoizedComponent onPress={stableOnPress} title={'New title'} />);
310
- // THEN
311
- expect(rendersCount).toBe(2);
312
- });
318
+ // WHEN
319
+ rerender(
320
+ <MemoizedComponent onPress={stableOnPress} title={'New title'} />
321
+ );
322
+ // THEN
323
+ expect(rendersCount).toBe(2);
324
+ });
313
325
 
314
- it('M keep memoization working for elements W an onPress prop is passed and custom arePropsEqual specified including onPress check', async () => {
315
- // GIVEN
316
- DdRumUserInteractionTracking.startTracking();
317
- let rendersCount = 0;
318
- const DummyComponent = props => {
319
- rendersCount++;
320
- return (
321
- <TouchableWithoutFeedback onPress={props.onPress}>
322
- <View style={styles.button}>
323
- <Text style={styles.button}>Click me</Text>
324
- </View>
325
- </TouchableWithoutFeedback>
326
+ it('M keep memoization working for elements W an onPress prop is passed and custom arePropsEqual specified including onPress check', async () => {
327
+ // GIVEN
328
+ DdRumUserInteractionTracking.startTracking();
329
+ let rendersCount = 0;
330
+ const DummyComponent = props => {
331
+ rendersCount++;
332
+ return (
333
+ <TouchableWithoutFeedback onPress={props.onPress}>
334
+ <View style={styles.button}>
335
+ <Text style={styles.button}>Click me</Text>
336
+ </View>
337
+ </TouchableWithoutFeedback>
338
+ );
339
+ };
340
+ function stableOnPress() {}
341
+ function newOnPress() {}
342
+ const MemoizedComponent = React.memo(
343
+ DummyComponent,
344
+ (previousProps, nextProps) =>
345
+ previousProps.onPress === nextProps.onPress
326
346
  );
327
- };
328
- const stableOnPress = () => {};
329
- const MemoizedComponent = React.memo(
330
- DummyComponent,
331
- (previousProps, nextProps) =>
332
- previousProps.onPress === nextProps.onPress
333
- );
334
- const { rerender } = render(<MemoizedComponent onPress={stableOnPress} />);
335
- expect(rendersCount).toBe(1);
347
+ const { rerender } = render(
348
+ <MemoizedComponent onPress={stableOnPress} />
349
+ );
350
+ expect(rendersCount).toBe(1);
336
351
 
337
- // WHEN
338
- rerender(<MemoizedComponent onPress={stableOnPress} />);
339
- // THEN
340
- expect(rendersCount).toBe(1);
352
+ // WHEN
353
+ rerender(<MemoizedComponent onPress={stableOnPress} />);
354
+ // THEN
355
+ expect(rendersCount).toBe(1);
341
356
 
342
- // WHEN
343
- rerender(<MemoizedComponent onPress={() => {}} />);
344
- // THEN
345
- expect(rendersCount).toBe(2);
357
+ // WHEN
358
+ rerender(<MemoizedComponent onPress={newOnPress} />);
359
+ // THEN
360
+ expect(rendersCount).toBe(2);
361
+ });
346
362
  });
347
363
 
348
364
  describe('startTracking', () => {
package/src/index.tsx CHANGED
@@ -7,7 +7,8 @@
7
7
  import {
8
8
  DatadogProviderConfiguration,
9
9
  DdSdkReactNativeConfiguration,
10
- InitializationMode
10
+ InitializationMode,
11
+ VitalsUpdateFrequency
11
12
  } from './DdSdkReactNativeConfiguration';
12
13
  import { DdSdkReactNative } from './DdSdkReactNative';
13
14
  import { InternalLog } from './InternalLog';
@@ -17,7 +18,7 @@ import { TrackingConsent } from './TrackingConsent';
17
18
  import { DdTrace } from './foundation';
18
19
  import { DdLogs } from './logs/DdLogs';
19
20
  import { DdRum } from './rum/DdRum';
20
- import { RumActionType, ErrorSource } from './rum/types';
21
+ import { RumActionType, ErrorSource, PropagatorType } from './rum/types';
21
22
  import { DatadogProvider } from './sdk/DatadogProvider/DatadogProvider';
22
23
 
23
24
  export {
@@ -35,5 +36,7 @@ export {
35
36
  ProxyConfiguration,
36
37
  ProxyType,
37
38
  TrackingConsent,
38
- SdkVerbosity
39
+ SdkVerbosity,
40
+ VitalsUpdateFrequency,
41
+ PropagatorType
39
42
  };
@@ -13,7 +13,7 @@ import { DdRum } from '../DdRum';
13
13
  import type { ActionEventMapper } from '../eventMappers/actionEventMapper';
14
14
  import type { ErrorEventMapper } from '../eventMappers/errorEventMapper';
15
15
  import type { ResourceEventMapper } from '../eventMappers/resourceEventMapper';
16
- import { ErrorSource, RumActionType } from '../types';
16
+ import { ErrorSource, PropagatorType, RumActionType } from '../types';
17
17
 
18
18
  jest.mock('../../TimeProvider', () => {
19
19
  return {
@@ -383,4 +383,20 @@ describe('DdRum', () => {
383
383
  );
384
384
  });
385
385
  });
386
+
387
+ describe('PropagatorTypes', () => {
388
+ it('matches with the native name of propagators', () => {
389
+ /**
390
+ * If you break this test by changing the value of the enum,
391
+ * be sure to update the native implementation of
392
+ * - ReadableArray.asTracingHeaderTypes (Android)
393
+ * - asTracingHeaderType (iOS)
394
+ * so that it uses the new values
395
+ */
396
+ expect(PropagatorType.DATADOG).toBe('datadog');
397
+ expect(PropagatorType.B3).toBe('b3');
398
+ expect(PropagatorType.B3MULTI).toBe('b3multi');
399
+ expect(PropagatorType.TRACECONTEXT).toBe('tracecontext');
400
+ });
401
+ });
386
402
  });