@datadog/mobile-react-native 1.1.5 → 1.2.0-beta2

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 (160) hide show
  1. package/DatadogSDKReactNative.podspec +2 -2
  2. package/README.md +18 -14
  3. package/android/build.gradle +28 -3
  4. package/android/detekt.yml +572 -0
  5. package/android/src/main/kotlin/com/datadog/reactnative/DatadogSDKWrapper.kt +12 -0
  6. package/android/src/main/kotlin/com/datadog/reactnative/DatadogWrapper.kt +15 -0
  7. package/android/src/main/kotlin/com/datadog/reactnative/DdSdk.kt +143 -8
  8. package/android/src/main/kotlin/com/datadog/reactnative/DdSdkConfiguration.kt +25 -1
  9. package/android/src/main/kotlin/com/datadog/reactnative/DdSdkConfigurationExt.kt +31 -1
  10. package/android/src/main/kotlin/com/datadog/reactnative/VitalFrameCallback.kt +41 -0
  11. package/android/src/test/kotlin/com/datadog/reactnative/DdRumTest.kt +7 -2
  12. package/android/src/test/kotlin/com/datadog/reactnative/DdSdkTest.kt +429 -27
  13. package/android/src/test/kotlin/com/datadog/reactnative/DdTraceTest.kt +5 -1
  14. package/android/src/test/kotlin/com/datadog/tools/unit/DdSdkConfigurationExt.kt +40 -1
  15. package/android/src/test/kotlin/com/datadog/tools/unit/GenericAssert.kt +21 -1
  16. package/android/src/test/kotlin/com/datadog/tools/unit/MapExt.kt +1 -1
  17. package/android/src/test/kotlin/com/datadog/tools/unit/forge/BaseConfigurator.kt +1 -0
  18. package/android/src/test/kotlin/com/datadog/tools/unit/forge/DdSdkConfigurationForgeryFactory.kt +22 -2
  19. package/android/src/test/kotlin/com/datadog/tools/unit/forge/PackageInfoForgeryFactory.kt +2 -3
  20. package/android/src/test/kotlin/com/datadog/tools/unit/forge/TelemetryConfigurationEventForgeryFactory.kt +94 -0
  21. package/datadog-sourcemaps.gradle +85 -28
  22. package/ios/Sources/Attributes.swift +0 -4
  23. package/ios/Sources/DdSdk.m +10 -0
  24. package/ios/Sources/DdSdk.swift +113 -10
  25. package/ios/Sources/DdSdkConfiguration.swift +38 -1
  26. package/ios/Sources/JSRefreshRateListener.swift +86 -0
  27. package/ios/Sources/QueueHolder.swift +7 -0
  28. package/ios/Sources/RNDdSdkConfiguration.swift +25 -1
  29. package/lib/commonjs/DatadogProvider/Buffer/BoundedBuffer.js +173 -0
  30. package/lib/commonjs/DatadogProvider/Buffer/BoundedBuffer.js.map +1 -0
  31. package/lib/commonjs/DatadogProvider/Buffer/BufferSingleton.js +32 -0
  32. package/lib/commonjs/DatadogProvider/Buffer/BufferSingleton.js.map +1 -0
  33. package/lib/commonjs/DatadogProvider/Buffer/DatadogBuffer.js +29 -0
  34. package/lib/commonjs/DatadogProvider/Buffer/DatadogBuffer.js.map +1 -0
  35. package/lib/commonjs/DatadogProvider/Buffer/PassThroughBuffer.js +28 -0
  36. package/lib/commonjs/DatadogProvider/Buffer/PassThroughBuffer.js.map +1 -0
  37. package/lib/commonjs/DatadogProvider/Buffer/bufferNativeCall.js +32 -0
  38. package/lib/commonjs/DatadogProvider/Buffer/bufferNativeCall.js.map +1 -0
  39. package/lib/commonjs/DatadogProvider/DatadogProvider.js +101 -0
  40. package/lib/commonjs/DatadogProvider/DatadogProvider.js.map +1 -0
  41. package/lib/commonjs/DdSdkReactNative.js +140 -59
  42. package/lib/commonjs/DdSdkReactNative.js.map +1 -1
  43. package/lib/commonjs/DdSdkReactNativeConfiguration.js +166 -9
  44. package/lib/commonjs/DdSdkReactNativeConfiguration.js.map +1 -1
  45. package/lib/commonjs/errorUtils.js +69 -0
  46. package/lib/commonjs/errorUtils.js.map +1 -0
  47. package/lib/commonjs/foundation.js +19 -12
  48. package/lib/commonjs/foundation.js.map +1 -1
  49. package/lib/commonjs/index.js +20 -0
  50. package/lib/commonjs/index.js.map +1 -1
  51. package/lib/commonjs/longTasksUtils.js +40 -0
  52. package/lib/commonjs/longTasksUtils.js.map +1 -0
  53. package/lib/commonjs/nativeModulesTypes.js.map +1 -1
  54. package/lib/commonjs/rum/instrumentation/DdRumErrorTracking.js +8 -45
  55. package/lib/commonjs/rum/instrumentation/DdRumErrorTracking.js.map +1 -1
  56. package/lib/commonjs/rum/instrumentation/DdRumUserInteractionTracking.js +16 -1
  57. package/lib/commonjs/rum/instrumentation/DdRumUserInteractionTracking.js.map +1 -1
  58. package/lib/commonjs/rum/instrumentation/getJsxRuntime.js +1 -1
  59. package/lib/commonjs/rum/instrumentation/getJsxRuntime.js.map +1 -1
  60. package/lib/commonjs/rum/instrumentation/resourceTracking/domain/distributedTracing.js +2 -1
  61. package/lib/commonjs/rum/instrumentation/resourceTracking/domain/distributedTracing.js.map +1 -1
  62. package/lib/commonjs/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/ResourceReporter.js +2 -1
  63. package/lib/commonjs/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/ResourceReporter.js.map +1 -1
  64. package/lib/commonjs/types.js +6 -1
  65. package/lib/commonjs/types.js.map +1 -1
  66. package/lib/commonjs/version.js +1 -1
  67. package/lib/commonjs/version.js.map +1 -1
  68. package/lib/module/DatadogProvider/Buffer/BoundedBuffer.js +163 -0
  69. package/lib/module/DatadogProvider/Buffer/BoundedBuffer.js.map +1 -0
  70. package/lib/module/DatadogProvider/Buffer/BufferSingleton.js +26 -0
  71. package/lib/module/DatadogProvider/Buffer/BufferSingleton.js.map +1 -0
  72. package/lib/module/DatadogProvider/Buffer/DatadogBuffer.js +20 -0
  73. package/lib/module/DatadogProvider/Buffer/DatadogBuffer.js.map +1 -0
  74. package/lib/module/DatadogProvider/Buffer/PassThroughBuffer.js +23 -0
  75. package/lib/module/DatadogProvider/Buffer/PassThroughBuffer.js.map +1 -0
  76. package/lib/module/DatadogProvider/Buffer/bufferNativeCall.js +16 -0
  77. package/lib/module/DatadogProvider/Buffer/bufferNativeCall.js.map +1 -0
  78. package/lib/module/DatadogProvider/DatadogProvider.js +82 -0
  79. package/lib/module/DatadogProvider/DatadogProvider.js.map +1 -0
  80. package/lib/module/DdSdkReactNative.js +132 -57
  81. package/lib/module/DdSdkReactNative.js.map +1 -1
  82. package/lib/module/DdSdkReactNativeConfiguration.js +154 -8
  83. package/lib/module/DdSdkReactNativeConfiguration.js.map +1 -1
  84. package/lib/module/errorUtils.js +54 -0
  85. package/lib/module/errorUtils.js.map +1 -0
  86. package/lib/module/foundation.js +18 -12
  87. package/lib/module/foundation.js.map +1 -1
  88. package/lib/module/index.js +3 -2
  89. package/lib/module/index.js.map +1 -1
  90. package/lib/module/longTasksUtils.js +31 -0
  91. package/lib/module/longTasksUtils.js.map +1 -0
  92. package/lib/module/nativeModulesTypes.js.map +1 -1
  93. package/lib/module/rum/instrumentation/DdRumErrorTracking.js +5 -42
  94. package/lib/module/rum/instrumentation/DdRumErrorTracking.js.map +1 -1
  95. package/lib/module/rum/instrumentation/DdRumUserInteractionTracking.js +14 -1
  96. package/lib/module/rum/instrumentation/DdRumUserInteractionTracking.js.map +1 -1
  97. package/lib/module/rum/instrumentation/getJsxRuntime.js +1 -1
  98. package/lib/module/rum/instrumentation/getJsxRuntime.js.map +1 -1
  99. package/lib/module/rum/instrumentation/resourceTracking/domain/distributedTracing.js +2 -1
  100. package/lib/module/rum/instrumentation/resourceTracking/domain/distributedTracing.js.map +1 -1
  101. package/lib/module/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/ResourceReporter.js +2 -1
  102. package/lib/module/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/ResourceReporter.js.map +1 -1
  103. package/lib/module/types.js +6 -1
  104. package/lib/module/types.js.map +1 -1
  105. package/lib/module/version.js +1 -1
  106. package/lib/module/version.js.map +1 -1
  107. package/lib/typescript/DatadogProvider/Buffer/BoundedBuffer.d.ts +15 -0
  108. package/lib/typescript/DatadogProvider/Buffer/BufferSingleton.d.ts +7 -0
  109. package/lib/typescript/DatadogProvider/Buffer/DatadogBuffer.d.ts +20 -0
  110. package/lib/typescript/DatadogProvider/Buffer/PassThroughBuffer.d.ts +7 -0
  111. package/lib/typescript/DatadogProvider/Buffer/bufferNativeCall.d.ts +3 -0
  112. package/lib/typescript/DatadogProvider/DatadogProvider.d.ts +26 -0
  113. package/lib/typescript/DdSdkReactNative.d.ts +18 -3
  114. package/lib/typescript/DdSdkReactNativeConfiguration.d.ts +114 -0
  115. package/lib/typescript/errorUtils.d.ts +12 -0
  116. package/lib/typescript/index.d.ts +3 -2
  117. package/lib/typescript/longTasksUtils.d.ts +6 -0
  118. package/lib/typescript/nativeModulesTypes.d.ts +12 -0
  119. package/lib/typescript/rum/instrumentation/DdRumErrorTracking.d.ts +0 -2
  120. package/lib/typescript/rum/instrumentation/DdRumUserInteractionTracking.d.ts +3 -0
  121. package/lib/typescript/rum/instrumentation/resourceTracking/domain/distributedTracing.d.ts +1 -0
  122. package/lib/typescript/rum/instrumentation/resourceTracking/domain/interfaces/RumResource.d.ts +1 -1
  123. package/lib/typescript/types.d.ts +16 -1
  124. package/lib/typescript/version.d.ts +1 -1
  125. package/package.json +3 -2
  126. package/src/DatadogProvider/Buffer/BoundedBuffer.ts +209 -0
  127. package/src/DatadogProvider/Buffer/BufferSingleton.ts +26 -0
  128. package/src/DatadogProvider/Buffer/DatadogBuffer.ts +34 -0
  129. package/src/DatadogProvider/Buffer/PassThroughBuffer.ts +16 -0
  130. package/src/DatadogProvider/Buffer/__tests__/BoundedBuffer.test.ts +202 -0
  131. package/src/DatadogProvider/Buffer/__tests__/BufferSingleton.test.ts +50 -0
  132. package/src/DatadogProvider/Buffer/bufferNativeCall.ts +24 -0
  133. package/src/DatadogProvider/DatadogProvider.tsx +122 -0
  134. package/src/DatadogProvider/__tests__/__utils__/renderWithProvider.tsx +111 -0
  135. package/src/DatadogProvider/__tests__/initialization.test.tsx +182 -0
  136. package/src/DatadogProvider/__tests__/initializationModes.test.tsx +174 -0
  137. package/src/DdSdkReactNative.tsx +206 -109
  138. package/src/DdSdkReactNativeConfiguration.tsx +225 -8
  139. package/src/__tests__/DdRumWrapper.test.tsx +3 -27
  140. package/src/__tests__/DdSdkReactNative.test.tsx +57 -13
  141. package/src/__tests__/DdSdkReactNativeConfiguration.test.ts +181 -0
  142. package/src/__tests__/foundation.test.ts +11 -2
  143. package/src/__tests__/longTasksUtils.ts +23 -0
  144. package/src/__tests__/rum/instrumentation/DdRumUserInteractionTracking.test.tsx +18 -4
  145. package/src/errorUtils.ts +58 -0
  146. package/src/foundation.tsx +15 -12
  147. package/src/index.tsx +9 -1
  148. package/src/longTasksUtils.ts +30 -0
  149. package/src/nativeModulesTypes.ts +14 -0
  150. package/src/rum/instrumentation/DdRumErrorTracking.tsx +9 -46
  151. package/src/rum/instrumentation/DdRumUserInteractionTracking.tsx +11 -1
  152. package/src/rum/instrumentation/getJsxRuntime.ts +1 -1
  153. package/src/rum/instrumentation/resourceTracking/__tests__/DdRumResourceTracking.test.ts +2 -0
  154. package/src/rum/instrumentation/resourceTracking/domain/distributedTracing.tsx +3 -1
  155. package/src/rum/instrumentation/resourceTracking/domain/interfaces/RumResource.ts +1 -1
  156. package/src/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/ResourceReporter.ts +2 -1
  157. package/src/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/__tests__/ResourceReporter.test.ts +2 -0
  158. package/src/rum/instrumentation/resourceTracking/implementation/__tests__/XHRProxy.test.ts +12 -47
  159. package/src/types.tsx +11 -1
  160. package/src/version.ts +1 -1
@@ -8,12 +8,38 @@ import type { ProxyConfiguration } from './ProxyConfiguration';
8
8
  import type { SdkVerbosity } from './SdkVerbosity';
9
9
  import { TrackingConsent } from './TrackingConsent';
10
10
 
11
+ export enum VitalsUpdateFrequency {
12
+ FREQUENT = 'FREQUENT',
13
+ AVERAGE = 'AVERAGE',
14
+ RARE = 'RARE',
15
+ NEVER = 'NEVER'
16
+ }
17
+
18
+ const DEFAULTS = {
19
+ nativeCrashReportEnabled: false,
20
+ sessionSamplingRate: 100.0,
21
+ resourceTracingSamplingRate: 20.0,
22
+ site: 'US1',
23
+ longTaskThresholdMs: 0,
24
+ nativeLongTaskThresholdMs: 200,
25
+ nativeViewTracking: false,
26
+ getFirstPartyHosts: () => [],
27
+ getAdditionalConfig: () => ({}),
28
+ trackingConsent: TrackingConsent.GRANTED,
29
+ telemetrySampleRate: 20.0,
30
+ vitalsUpdateFrequency: VitalsUpdateFrequency.AVERAGE
31
+ };
32
+
11
33
  /**
12
34
  * The SDK configuration class.
13
35
  * It will be used to configure the SDK functionality at initialization.
14
36
  */
15
37
  export class DdSdkReactNativeConfiguration {
16
- public nativeCrashReportEnabled: boolean = false;
38
+ /**
39
+ * Enables crash reporting for native plaforms (iOS, Android). Default `false`.
40
+ */
41
+ public nativeCrashReportEnabled: boolean =
42
+ DEFAULTS.nativeCrashReportEnabled;
17
43
  /**
18
44
  * @deprecated `sampleRate` has been replaced by `sessionSamplingRate` to avoid confusion with `resourceTracingSamplingRate` and will be removed in a future release.
19
45
  */
@@ -21,17 +47,32 @@ export class DdSdkReactNativeConfiguration {
21
47
  /**
22
48
  * Percentage of sampled RUM sessions. Range `0`-`100`.
23
49
  */
24
- public sessionSamplingRate: number = 100.0;
50
+ public sessionSamplingRate: number = DEFAULTS.sessionSamplingRate;
25
51
  /**
26
52
  * Percentage of tracing integrations for network calls between your app and your backend. Range `0`-`100`.
27
53
  */
28
- public resourceTracingSamplingRate: number = 20.0;
29
- public site: string = 'US';
54
+ public resourceTracingSamplingRate: number =
55
+ DEFAULTS.resourceTracingSamplingRate;
56
+ public site: string = DEFAULTS.site;
57
+ /**
58
+ * Verbosity for internal SDK logging.
59
+ * Set to `SdkVerbosity.DEBUG` to debug your SDK implementation.
60
+ */
30
61
  public verbosity: SdkVerbosity | undefined = undefined;
31
- public nativeViewTracking: boolean = false;
62
+ /**
63
+ * Enables native views tracking.
64
+ * Set to `true` if you use a custom navigation system relying on native views.
65
+ */
66
+ public nativeViewTracking: boolean = DEFAULTS.nativeViewTracking;
32
67
  public proxyConfig?: ProxyConfiguration = undefined;
33
68
  public serviceName?: string = undefined;
34
- public firstPartyHosts: string[] = [];
69
+ /**
70
+ * List of your backends hosts to enable tracing with.
71
+ * Regular expressions are NOT supported.
72
+ *
73
+ * Matches domains and subdomains, e.g. `['example.com']` matches `example.com` and `api.example.com`.
74
+ */
75
+ public firstPartyHosts: string[] = DEFAULTS.getFirstPartyHosts();
35
76
  /**
36
77
  * Overrides the reported version of the app.
37
78
  * Accepted characters are alphanumerics and `_`, `-`, `:`, `.`, `/`.
@@ -53,7 +94,49 @@ export class DdSdkReactNativeConfiguration {
53
94
  */
54
95
  public versionSuffix?: string;
55
96
 
56
- public additionalConfig: { [k: string]: any } = {};
97
+ /**
98
+ * The sampling rate for Internal Telemetry (info related to the work of the
99
+ * SDK internals).
100
+ *
101
+ * The sampling rate must be a value between 0 and 100. A value of 0 means no
102
+ * telemetry will be sent, 100 means all telemetry will be sent. When
103
+ * `telemetrySampleRate` is not set, the default value from the iOS and
104
+ * Android SDK is used, which is 20.
105
+ */
106
+ public telemetrySampleRate: number = DEFAULTS.telemetrySampleRate;
107
+
108
+ /**
109
+ * The threshold for native long tasks reporting in milliseconds.
110
+ *
111
+ * - Setting it to `0` or `false` disables native long task reporting.
112
+ * - Values below `100` will be raised to `100`.
113
+ * - Values above `5000` will be lowered to `5000`.
114
+ *
115
+ * Default value is `200`.
116
+ */
117
+ public nativeLongTaskThresholdMs: number | false =
118
+ DEFAULTS.nativeLongTaskThresholdMs;
119
+
120
+ /**
121
+ * The threshold for javascript long tasks reporting in milliseconds.
122
+ *
123
+ * - Setting it to `0` or `false` disables javascript long task reporting.
124
+ * - Values below `100` will be raised to `100`.
125
+ * - Values above `5000` will be lowered to `5000`.
126
+ *
127
+ * Default value is `0`
128
+ */
129
+ public longTaskThresholdMs: number | false = DEFAULTS.longTaskThresholdMs;
130
+
131
+ /**
132
+ * Sets the preferred frequency for collecting mobile vitals.
133
+ */
134
+ public vitalsUpdateFrequency: VitalsUpdateFrequency =
135
+ DEFAULTS.vitalsUpdateFrequency;
136
+
137
+ public additionalConfig: {
138
+ [k: string]: any;
139
+ } = DEFAULTS.getAdditionalConfig();
57
140
 
58
141
  constructor(
59
142
  readonly clientToken: string,
@@ -62,6 +145,140 @@ export class DdSdkReactNativeConfiguration {
62
145
  readonly trackInteractions: boolean = false,
63
146
  readonly trackResources: boolean = false,
64
147
  readonly trackErrors: boolean = false,
65
- readonly trackingConsent: TrackingConsent = TrackingConsent.GRANTED
148
+ readonly trackingConsent: TrackingConsent = DEFAULTS.trackingConsent
66
149
  ) {}
67
150
  }
151
+
152
+ /**
153
+ * Auto Instrumentation configuration passed to DatadogProvider.
154
+ * Does not include default values.
155
+ */
156
+ export type AutoInstrumentationConfiguration = {
157
+ readonly trackInteractions: boolean;
158
+ readonly trackResources: boolean;
159
+ readonly firstPartyHosts?: string[];
160
+ readonly resourceTracingSamplingRate?: number;
161
+ readonly trackErrors: boolean;
162
+ };
163
+
164
+ /**
165
+ * Parameters needed to start auto instrumentation. Includes default values.
166
+ */
167
+ export type AutoInstrumentationParameters = {
168
+ readonly trackInteractions: boolean;
169
+ readonly trackResources: boolean;
170
+ readonly firstPartyHosts: string[];
171
+ readonly resourceTracingSamplingRate: number;
172
+ readonly trackErrors: boolean;
173
+ };
174
+
175
+ /**
176
+ * We could use `Proxy` instead of this function, but `Proxy` is not available on
177
+ * the older android jsc that can still be used.
178
+ */
179
+ export const addDefaultValuesToAutoInstrumentationConfiguration = (
180
+ features: AutoInstrumentationConfiguration
181
+ ): AutoInstrumentationParameters => {
182
+ return {
183
+ ...features,
184
+ firstPartyHosts:
185
+ features.firstPartyHosts || DEFAULTS.getFirstPartyHosts(),
186
+ resourceTracingSamplingRate:
187
+ features.resourceTracingSamplingRate ||
188
+ DEFAULTS.resourceTracingSamplingRate
189
+ };
190
+ };
191
+
192
+ export type PartialInitializationConfiguration = {
193
+ readonly clientToken: string;
194
+ readonly env: string;
195
+ readonly applicationId: string;
196
+ readonly sessionSamplingRate?: number;
197
+ readonly site?: string;
198
+ readonly verbosity?: SdkVerbosity | undefined;
199
+ readonly nativeViewTracking?: boolean;
200
+ readonly proxyConfig?: ProxyConfiguration;
201
+ readonly serviceName?: string;
202
+ readonly version?: string;
203
+ versionSuffix?: string;
204
+ readonly additionalConfig?: { [k: string]: any };
205
+ readonly trackingConsent?: TrackingConsent;
206
+ readonly longTaskThresholdMs?: number | false;
207
+ readonly nativeLongTaskThresholdMs?: number | false;
208
+ readonly nativeCrashReportEnabled?: boolean;
209
+ readonly telemetrySampleRate?: number;
210
+ readonly vitalsUpdateFrequency?: VitalsUpdateFrequency;
211
+ };
212
+
213
+ const setConfigurationAttribute = <
214
+ AttributeName extends keyof DdSdkReactNativeConfiguration
215
+ >(
216
+ attribute: {
217
+ value?: DdSdkReactNativeConfiguration[AttributeName];
218
+ name: AttributeName;
219
+ },
220
+ configuration: DdSdkReactNativeConfiguration
221
+ ) => {
222
+ if (attribute.value !== undefined) {
223
+ configuration[attribute.name] = attribute.value;
224
+ }
225
+ };
226
+
227
+ export const buildConfigurationFromPartialConfiguration = (
228
+ features: AutoInstrumentationConfiguration,
229
+ configuration: PartialInitializationConfiguration
230
+ ): DdSdkReactNativeConfiguration => {
231
+ const {
232
+ clientToken,
233
+ env,
234
+ applicationId,
235
+ ...remainingConfiguration
236
+ } = configuration;
237
+ const SdkConfiguration = new DdSdkReactNativeConfiguration(
238
+ clientToken,
239
+ env,
240
+ applicationId,
241
+ features.trackInteractions,
242
+ features.trackResources,
243
+ features.trackErrors,
244
+ configuration.trackingConsent
245
+ );
246
+
247
+ (Object.keys(
248
+ remainingConfiguration
249
+ ) as (keyof typeof remainingConfiguration)[]).forEach(name => {
250
+ setConfigurationAttribute(
251
+ { value: remainingConfiguration[name], name },
252
+ SdkConfiguration
253
+ );
254
+ });
255
+
256
+ setConfigurationAttribute(
257
+ {
258
+ name: 'resourceTracingSamplingRate',
259
+ value: features.resourceTracingSamplingRate
260
+ },
261
+ SdkConfiguration
262
+ );
263
+ setConfigurationAttribute(
264
+ { name: 'firstPartyHosts', value: features.firstPartyHosts },
265
+ SdkConfiguration
266
+ );
267
+
268
+ return SdkConfiguration;
269
+ };
270
+
271
+ export class DatadogProviderConfiguration extends DdSdkReactNativeConfiguration {
272
+ public initializationMode: InitializationMode = InitializationMode.SYNC;
273
+ }
274
+
275
+ export enum InitializationMode {
276
+ SYNC = 'SYNC',
277
+ ASYNC = 'ASYNC'
278
+ }
279
+
280
+ export type InitializationModeForTelemetry =
281
+ | 'LEGACY'
282
+ | 'SYNC'
283
+ | 'ASYNC'
284
+ | 'PARTIAL';
@@ -6,36 +6,12 @@
6
6
 
7
7
  import { NativeModules } from 'react-native';
8
8
 
9
+ import { BufferSingleton } from '../DatadogProvider/Buffer/BufferSingleton';
9
10
  import { DdRum } from '../foundation';
10
11
 
11
- jest.mock('react-native', () => {
12
- return {
13
- NativeModules: {
14
- DdRum: {
15
- startView: jest.fn().mockImplementation(() => {}),
16
- stopView: jest.fn().mockImplementation(() => {}),
17
- startAction: jest.fn().mockImplementation(() => {}),
18
- stopAction: jest.fn().mockImplementation(() => {}),
19
- addAction: jest.fn().mockImplementation(() => {}),
20
- startResource: jest.fn().mockImplementation(() => {}),
21
- stopResource: jest.fn().mockImplementation(() => {}),
22
- addError: jest.fn().mockImplementation(() => {}),
23
- addTiming: jest.fn().mockImplementation(() => {})
24
- }
25
- }
26
- };
27
- });
28
-
29
12
  beforeEach(async () => {
30
- NativeModules.DdRum.startView.mockClear();
31
- NativeModules.DdRum.stopView.mockClear();
32
- NativeModules.DdRum.startAction.mockClear();
33
- NativeModules.DdRum.stopAction.mockClear();
34
- NativeModules.DdRum.addAction.mockClear();
35
- NativeModules.DdRum.startResource.mockClear();
36
- NativeModules.DdRum.stopResource.mockClear();
37
- NativeModules.DdRum.addError.mockClear();
38
- NativeModules.DdRum.addTiming.mockClear();
13
+ jest.clearAllMocks();
14
+ BufferSingleton.onInitialization();
39
15
  });
40
16
 
41
17
  it('M add error source type W addError()', async () => {
@@ -49,6 +49,7 @@ jest.mock('../rum/instrumentation/DdRumErrorTracking', () => {
49
49
 
50
50
  beforeEach(async () => {
51
51
  DdSdkReactNative['wasInitialized'] = false;
52
+ DdSdkReactNative['wasAutoInstrumented'] = false;
52
53
  NativeModules.DdSdk.initialize.mockClear();
53
54
  NativeModules.DdSdk.setAttributes.mockClear();
54
55
  NativeModules.DdSdk.setUser.mockClear();
@@ -97,7 +98,6 @@ describe('DdSdkReactNative', () => {
97
98
  '_dd.source': 'react-native',
98
99
  '_dd.sdk_version': sdkVersion,
99
100
  '_dd.native_view_tracking': false,
100
- '_dd.long_task.threshold': 200,
101
101
  '_dd.first_party_hosts': []
102
102
  });
103
103
  });
@@ -134,7 +134,6 @@ describe('DdSdkReactNative', () => {
134
134
  '_dd.source': 'react-native',
135
135
  '_dd.sdk_version': sdkVersion,
136
136
  '_dd.native_view_tracking': false,
137
- '_dd.long_task.threshold': 200,
138
137
  '_dd.first_party_hosts': []
139
138
  });
140
139
 
@@ -179,7 +178,6 @@ describe('DdSdkReactNative', () => {
179
178
  '_dd.source': 'react-native',
180
179
  '_dd.sdk_version': sdkVersion,
181
180
  '_dd.native_view_tracking': false,
182
- '_dd.long_task.threshold': 200,
183
181
  '_dd.first_party_hosts': []
184
182
  });
185
183
  });
@@ -214,7 +212,6 @@ describe('DdSdkReactNative', () => {
214
212
  '_dd.source': 'react-native',
215
213
  '_dd.sdk_version': sdkVersion,
216
214
  '_dd.native_view_tracking': false,
217
- '_dd.long_task.threshold': 200,
218
215
  '_dd.first_party_hosts': []
219
216
  });
220
217
  });
@@ -271,7 +268,6 @@ describe('DdSdkReactNative', () => {
271
268
  '_dd.proxy.type': proxyType,
272
269
  '_dd.proxy.address': proxyAddress,
273
270
  '_dd.proxy.port': proxyPort,
274
- '_dd.long_task.threshold': 200,
275
271
  '_dd.first_party_hosts': []
276
272
  });
277
273
  expect(spyConsoleWarn).toHaveBeenCalledTimes(1);
@@ -454,7 +450,6 @@ describe('DdSdkReactNative', () => {
454
450
  '_dd.source': 'react-native',
455
451
  '_dd.sdk_version': sdkVersion,
456
452
  '_dd.native_view_tracking': false,
457
- '_dd.long_task.threshold': 200,
458
453
  '_dd.first_party_hosts': []
459
454
  });
460
455
  expect(
@@ -493,7 +488,6 @@ describe('DdSdkReactNative', () => {
493
488
  '_dd.source': 'react-native',
494
489
  '_dd.sdk_version': sdkVersion,
495
490
  '_dd.native_view_tracking': false,
496
- '_dd.long_task.threshold': 200,
497
491
  '_dd.first_party_hosts': ['api.example.com']
498
492
  });
499
493
  expect(DdRumResourceTracking.startTracking).toHaveBeenCalledTimes(
@@ -536,7 +530,6 @@ describe('DdSdkReactNative', () => {
536
530
  '_dd.source': 'react-native',
537
531
  '_dd.sdk_version': sdkVersion,
538
532
  '_dd.native_view_tracking': false,
539
- '_dd.long_task.threshold': 200,
540
533
  '_dd.first_party_hosts': []
541
534
  });
542
535
  expect(DdRumErrorTracking.startTracking).toHaveBeenCalledTimes(1);
@@ -575,7 +568,6 @@ describe('DdSdkReactNative', () => {
575
568
  '_dd.sdk_version': sdkVersion,
576
569
  '_dd.service_name': fakeServiceName,
577
570
  '_dd.native_view_tracking': false,
578
- '_dd.long_task.threshold': 200,
579
571
  '_dd.first_party_hosts': []
580
572
  });
581
573
  expect(DdRumErrorTracking.startTracking).toHaveBeenCalledTimes(1);
@@ -613,7 +605,6 @@ describe('DdSdkReactNative', () => {
613
605
  '_dd.sdk_version': sdkVersion,
614
606
  '_dd.sdk_verbosity': SdkVerbosity.DEBUG,
615
607
  '_dd.native_view_tracking': false,
616
- '_dd.long_task.threshold': 200,
617
608
  '_dd.first_party_hosts': []
618
609
  });
619
610
  expect(DdRumErrorTracking.startTracking).toHaveBeenCalledTimes(1);
@@ -650,11 +641,66 @@ describe('DdSdkReactNative', () => {
650
641
  '_dd.source': 'react-native',
651
642
  '_dd.sdk_version': sdkVersion,
652
643
  '_dd.native_view_tracking': true,
653
- '_dd.long_task.threshold': 200,
654
644
  '_dd.first_party_hosts': []
655
645
  });
656
646
  expect(DdRumErrorTracking.startTracking).toHaveBeenCalledTimes(1);
657
647
  });
648
+
649
+ it('enables long task tracking when initialize { native and javascript long task custom threshold }', async () => {
650
+ // GIVEN
651
+ const fakeAppId = '1';
652
+ const fakeClientToken = '2';
653
+ const fakeEnvName = 'env';
654
+ const configuration = new DdSdkReactNativeConfiguration(
655
+ fakeClientToken,
656
+ fakeEnvName,
657
+ fakeAppId,
658
+ false,
659
+ false,
660
+ true
661
+ );
662
+ configuration.nativeLongTaskThresholdMs = 234;
663
+ configuration.longTaskThresholdMs = 456;
664
+
665
+ NativeModules.DdSdk.initialize.mockResolvedValue(null);
666
+
667
+ // WHEN
668
+ await DdSdkReactNative.initialize(configuration);
669
+
670
+ // THEN
671
+ const ddSdkConfiguration = NativeModules.DdSdk.initialize.mock
672
+ .calls[0][0] as DdSdkConfiguration;
673
+ expect(ddSdkConfiguration.nativeLongTaskThresholdMs).toBe(234);
674
+ expect(ddSdkConfiguration.longTaskThresholdMs).toBe(456);
675
+ });
676
+
677
+ it('enables long task tracking when initialize { native and javascript long task false threshold }', async () => {
678
+ // GIVEN
679
+ const fakeAppId = '1';
680
+ const fakeClientToken = '2';
681
+ const fakeEnvName = 'env';
682
+ const configuration = new DdSdkReactNativeConfiguration(
683
+ fakeClientToken,
684
+ fakeEnvName,
685
+ fakeAppId,
686
+ false,
687
+ false,
688
+ true
689
+ );
690
+ configuration.nativeLongTaskThresholdMs = false;
691
+ configuration.longTaskThresholdMs = false;
692
+
693
+ NativeModules.DdSdk.initialize.mockResolvedValue(null);
694
+
695
+ // WHEN
696
+ await DdSdkReactNative.initialize(configuration);
697
+
698
+ // THEN
699
+ const ddSdkConfiguration = NativeModules.DdSdk.initialize.mock
700
+ .calls[0][0] as DdSdkConfiguration;
701
+ expect(ddSdkConfiguration.nativeLongTaskThresholdMs).toBe(0);
702
+ expect(ddSdkConfiguration.longTaskThresholdMs).toBe(0);
703
+ });
658
704
  });
659
705
 
660
706
  describe('setAttributes', () => {
@@ -749,7 +795,6 @@ describe('DdSdkReactNative', () => {
749
795
  '_dd.proxy.type': proxyType,
750
796
  '_dd.proxy.address': proxyAddress,
751
797
  '_dd.proxy.port': proxyPort,
752
- '_dd.long_task.threshold': 200,
753
798
  '_dd.first_party_hosts': []
754
799
  });
755
800
  });
@@ -810,7 +855,6 @@ describe('DdSdkReactNative', () => {
810
855
  '_dd.proxy.port': proxyPort,
811
856
  '_dd.proxy.username': proxyUsername,
812
857
  '_dd.proxy.password': proxyPassword,
813
- '_dd.long_task.threshold': 200,
814
858
  '_dd.first_party_hosts': []
815
859
  });
816
860
  });
@@ -0,0 +1,181 @@
1
+ /*
2
+ * Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
3
+ * This product includes software developed at Datadog (https://www.datadoghq.com/).
4
+ * Copyright 2016-Present Datadog, Inc.
5
+ */
6
+
7
+ import { buildConfigurationFromPartialConfiguration } from '../DdSdkReactNativeConfiguration';
8
+ import { ProxyConfiguration, ProxyType } from '../ProxyConfiguration';
9
+ import { SdkVerbosity } from '../SdkVerbosity';
10
+ import { TrackingConsent } from '../TrackingConsent';
11
+
12
+ describe('DdSdkReactNativeConfiguration', () => {
13
+ describe('buildConfigurationFromPartialConfiguration', () => {
14
+ it('builds the SDK configuration when minimal configuration is passed', () => {
15
+ expect(
16
+ buildConfigurationFromPartialConfiguration(
17
+ {
18
+ trackErrors: false,
19
+ trackInteractions: false,
20
+ trackResources: false
21
+ },
22
+ {
23
+ applicationId: 'fake-app-id',
24
+ clientToken: 'fake-client-token',
25
+ env: 'fake-env'
26
+ }
27
+ )
28
+ ).toMatchInlineSnapshot(`
29
+ DdSdkReactNativeConfiguration {
30
+ "additionalConfig": Object {},
31
+ "applicationId": "fake-app-id",
32
+ "clientToken": "fake-client-token",
33
+ "env": "fake-env",
34
+ "firstPartyHosts": Array [],
35
+ "longTaskThresholdMs": 0,
36
+ "nativeCrashReportEnabled": false,
37
+ "nativeLongTaskThresholdMs": 200,
38
+ "nativeViewTracking": false,
39
+ "proxyConfig": undefined,
40
+ "resourceTracingSamplingRate": 20,
41
+ "serviceName": undefined,
42
+ "sessionSamplingRate": 100,
43
+ "site": "US1",
44
+ "telemetrySampleRate": 20,
45
+ "trackErrors": false,
46
+ "trackInteractions": false,
47
+ "trackResources": false,
48
+ "trackingConsent": "granted",
49
+ "verbosity": undefined,
50
+ "vitalsUpdateFrequency": "AVERAGE",
51
+ }
52
+ `);
53
+ });
54
+
55
+ it('builds the SDK configuration when every configuration attibute is set', () => {
56
+ expect(
57
+ buildConfigurationFromPartialConfiguration(
58
+ {
59
+ trackErrors: true,
60
+ trackInteractions: true,
61
+ trackResources: true,
62
+ firstPartyHosts: ['api.com'],
63
+ resourceTracingSamplingRate: 100
64
+ },
65
+ {
66
+ applicationId: 'fake-app-id',
67
+ clientToken: 'fake-client-token',
68
+ env: 'fake-env',
69
+ sessionSamplingRate: 80,
70
+ site: 'EU',
71
+ verbosity: SdkVerbosity.DEBUG,
72
+ nativeViewTracking: true,
73
+ proxyConfig: new ProxyConfiguration(
74
+ ProxyType.HTTPS,
75
+ 'api.com',
76
+ 443
77
+ ),
78
+ serviceName: 'com.test.app',
79
+ version: '1.4.5',
80
+ versionSuffix: 'codepush-3',
81
+ additionalConfig: { additionalField: 'fake-value' },
82
+ trackingConsent: TrackingConsent.PENDING,
83
+ nativeCrashReportEnabled: true,
84
+ nativeLongTaskThresholdMs: 345,
85
+ longTaskThresholdMs: 567
86
+ }
87
+ )
88
+ ).toMatchInlineSnapshot(`
89
+ DdSdkReactNativeConfiguration {
90
+ "additionalConfig": Object {
91
+ "additionalField": "fake-value",
92
+ },
93
+ "applicationId": "fake-app-id",
94
+ "clientToken": "fake-client-token",
95
+ "env": "fake-env",
96
+ "firstPartyHosts": Array [
97
+ "api.com",
98
+ ],
99
+ "longTaskThresholdMs": 567,
100
+ "nativeCrashReportEnabled": true,
101
+ "nativeLongTaskThresholdMs": 345,
102
+ "nativeViewTracking": true,
103
+ "proxyConfig": ProxyConfiguration {
104
+ "address": "api.com",
105
+ "password": undefined,
106
+ "port": 443,
107
+ "type": "https",
108
+ "username": undefined,
109
+ },
110
+ "resourceTracingSamplingRate": 100,
111
+ "serviceName": "com.test.app",
112
+ "sessionSamplingRate": 80,
113
+ "site": "EU",
114
+ "telemetrySampleRate": 20,
115
+ "trackErrors": true,
116
+ "trackInteractions": true,
117
+ "trackResources": true,
118
+ "trackingConsent": "pending",
119
+ "verbosity": "debug",
120
+ "version": "1.4.5",
121
+ "versionSuffix": "codepush-3",
122
+ "vitalsUpdateFrequency": "AVERAGE",
123
+ }
124
+ `);
125
+ });
126
+
127
+ it('builds the SDK configuration when falsy values are passed', () => {
128
+ expect(
129
+ buildConfigurationFromPartialConfiguration(
130
+ {
131
+ trackErrors: false,
132
+ trackInteractions: false,
133
+ trackResources: false,
134
+ resourceTracingSamplingRate: 0
135
+ },
136
+ {
137
+ applicationId: '',
138
+ clientToken: '',
139
+ env: '',
140
+ sessionSamplingRate: 0,
141
+ site: '',
142
+ nativeViewTracking: false,
143
+ serviceName: '',
144
+ version: '',
145
+ versionSuffix: '',
146
+ additionalConfig: {},
147
+ nativeCrashReportEnabled: false,
148
+ nativeLongTaskThresholdMs: false,
149
+ longTaskThresholdMs: false
150
+ }
151
+ )
152
+ ).toMatchInlineSnapshot(`
153
+ DdSdkReactNativeConfiguration {
154
+ "additionalConfig": Object {},
155
+ "applicationId": "",
156
+ "clientToken": "",
157
+ "env": "",
158
+ "firstPartyHosts": Array [],
159
+ "longTaskThresholdMs": false,
160
+ "nativeCrashReportEnabled": false,
161
+ "nativeLongTaskThresholdMs": false,
162
+ "nativeViewTracking": false,
163
+ "proxyConfig": undefined,
164
+ "resourceTracingSamplingRate": 0,
165
+ "serviceName": "",
166
+ "sessionSamplingRate": 0,
167
+ "site": "",
168
+ "telemetrySampleRate": 20,
169
+ "trackErrors": false,
170
+ "trackInteractions": false,
171
+ "trackResources": false,
172
+ "trackingConsent": "granted",
173
+ "verbosity": undefined,
174
+ "version": "",
175
+ "versionSuffix": "",
176
+ "vitalsUpdateFrequency": "AVERAGE",
177
+ }
178
+ `);
179
+ });
180
+ });
181
+ });