@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
@@ -6,7 +6,8 @@
6
6
 
7
7
  import { NativeModules } from 'react-native';
8
8
 
9
- import { DdRum } from '../foundation';
9
+ import { BufferSingleton } from '../DatadogProvider/Buffer/BufferSingleton';
10
+ import { DdRum, DdSdk } from '../foundation';
10
11
 
11
12
  jest.mock('../TimeProvider', () => {
12
13
  return {
@@ -20,6 +21,7 @@ describe('foundation', () => {
20
21
  describe('DdRum.stopAction', () => {
21
22
  beforeEach(() => {
22
23
  jest.clearAllMocks();
24
+ BufferSingleton.onInitialization();
23
25
  });
24
26
 
25
27
  test('calls the native SDK when called with new API', async () => {
@@ -42,9 +44,10 @@ describe('foundation', () => {
42
44
  );
43
45
  });
44
46
 
45
- test('does not call the native SDK when sartAction has not been called before and using old API', async () => {
47
+ test('does not call the native SDK when startAction has not been called before and using old API', async () => {
46
48
  await DdRum.stopAction({ user: 'me' }, 789);
47
49
  expect(NativeModules.DdRum.stopAction).not.toHaveBeenCalled();
50
+ expect(DdSdk.telemetryDebug).not.toHaveBeenCalled();
48
51
  });
49
52
 
50
53
  test('calls the native SDK when called with old API', async () => {
@@ -56,6 +59,9 @@ describe('foundation', () => {
56
59
  { user: 'me' },
57
60
  789
58
61
  );
62
+ expect(DdSdk.telemetryDebug).toHaveBeenCalledWith(
63
+ 'DDdRum.stopAction called with the old signature'
64
+ );
59
65
  });
60
66
 
61
67
  test('calls the native SDK when called with old API with default values', async () => {
@@ -67,6 +73,9 @@ describe('foundation', () => {
67
73
  {},
68
74
  456
69
75
  );
76
+ expect(DdSdk.telemetryDebug).toHaveBeenCalledWith(
77
+ 'DDdRum.stopAction called with the old signature'
78
+ );
70
79
  });
71
80
 
72
81
  test('cleans the action data when stopAction is called', async () => {
@@ -0,0 +1,23 @@
1
+ import { adaptLongTaskThreshold } from '../longTasksUtils';
2
+
3
+ describe('adaptLongTaskThreshold', () => {
4
+ it('returns 0 if false is given', () => {
5
+ expect(adaptLongTaskThreshold(false)).toBe(0);
6
+ });
7
+ it('returns 0 if 0 is given', () => {
8
+ expect(adaptLongTaskThreshold(0)).toBe(0);
9
+ });
10
+ it('returns 100 if positive below 100 is given', () => {
11
+ expect(adaptLongTaskThreshold(42)).toBe(100);
12
+ });
13
+ it('returns 100 if negative is given', () => {
14
+ expect(adaptLongTaskThreshold(-1)).toBe(100);
15
+ });
16
+ it('returns the value if an acceptable value is given', () => {
17
+ expect(adaptLongTaskThreshold(700)).toBe(700);
18
+ expect(adaptLongTaskThreshold(2000)).toBe(2000);
19
+ });
20
+ it('returns 5000 if a value too high is given', () => {
21
+ expect(adaptLongTaskThreshold(7000)).toBe(5000);
22
+ });
23
+ });
@@ -17,6 +17,7 @@ import {
17
17
  } from 'react-native';
18
18
  import React from 'react';
19
19
 
20
+ import { DdSdk } from '../../../foundation';
20
21
  import { DdEventsInterceptor } from '../../../rum/instrumentation/DdEventsInterceptor';
21
22
  import { DdRumUserInteractionTracking } from '../../../rum/instrumentation/DdRumUserInteractionTracking';
22
23
 
@@ -39,6 +40,7 @@ let originalMethod: typeof React.createElement;
39
40
  beforeEach(() => {
40
41
  originalMethod = React.createElement;
41
42
  jest.setTimeout(20000);
43
+ jest.clearAllMocks();
42
44
  });
43
45
 
44
46
  afterEach(() => {
@@ -342,16 +344,28 @@ it('M keep memoization working for elements W an onPress prop is passed and cust
342
344
  });
343
345
 
344
346
  describe('startTracking', () => {
345
- it('does not crash if jsx-runtime is not exported from react', () => {
347
+ /**
348
+ * WARNING: Because of caching in the require, the following 2 tests need
349
+ * to be run in this order
350
+ */
351
+ it('does not crash if jsx-runtime does not contain jsx', () => {
346
352
  expect(DdRumUserInteractionTracking['isTracking']).toBe(false);
347
- jest.setMock('react/jsx-runtime', null);
353
+ jest.setMock('react/jsx-runtime', {});
354
+
348
355
  DdRumUserInteractionTracking.startTracking();
349
356
  expect(DdRumUserInteractionTracking['isTracking']).toBe(true);
357
+ expect(DdSdk.telemetryDebug).toBeCalledWith(
358
+ 'React jsx runtime does not export new jsx transform'
359
+ );
350
360
  });
351
- it('does not crash if jsx-runtime does not contain jsx', () => {
361
+ it('does not crash if jsx-runtime is not exported from react', () => {
352
362
  expect(DdRumUserInteractionTracking['isTracking']).toBe(false);
353
- jest.setMock('react/jsx-runtime', {});
363
+ jest.setMock('react/package.json', { version: '16.13.0' });
364
+
354
365
  DdRumUserInteractionTracking.startTracking();
355
366
  expect(DdRumUserInteractionTracking['isTracking']).toBe(true);
367
+ expect(DdSdk.telemetryDebug).toBeCalledWith(
368
+ 'React version does not support new jsx transform'
369
+ );
356
370
  });
357
371
  });
@@ -0,0 +1,58 @@
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
+ export const EMPTY_MESSAGE = 'Unknown Error';
8
+ export const EMPTY_STACK_TRACE = '';
9
+
10
+ export const getErrorMessage = (error: any | undefined): string => {
11
+ let message = EMPTY_MESSAGE;
12
+ if (error === undefined || error === null) {
13
+ message = EMPTY_MESSAGE;
14
+ } else if (typeof error === 'object' && 'message' in error) {
15
+ message = String(error.message);
16
+ } else {
17
+ message = String(error);
18
+ }
19
+
20
+ return message;
21
+ };
22
+
23
+ /**
24
+ * Will extract the stack from the error, taking the first key found among:
25
+ * `stacktrace`, `stack`, `componentStack` (component tree for component errors,
26
+ * which contains only native components names in production).
27
+ *
28
+ * In last resort and if `sourceURL`, `line` and `column` are present, it will
29
+ * generate a stack from this information.
30
+ */
31
+ export const getErrorStackTrace = (error: any | undefined): string => {
32
+ let stack = EMPTY_STACK_TRACE;
33
+
34
+ try {
35
+ if (error === undefined || error === null) {
36
+ stack = EMPTY_STACK_TRACE;
37
+ } else if (typeof error === 'string') {
38
+ stack = EMPTY_STACK_TRACE;
39
+ } else if (typeof error === 'object') {
40
+ if ('stacktrace' in error) {
41
+ stack = String(error.stacktrace);
42
+ } else if ('stack' in error) {
43
+ stack = String(error.stack);
44
+ } else if ('componentStack' in error) {
45
+ stack = String(error.componentStack);
46
+ } else if (
47
+ 'sourceURL' in error &&
48
+ 'line' in error &&
49
+ 'column' in error
50
+ ) {
51
+ stack = `at ${error.sourceURL}:${error.line}:${error.column}`;
52
+ }
53
+ }
54
+ } catch (e) {
55
+ // Do nothing
56
+ }
57
+ return stack;
58
+ };
@@ -10,6 +10,7 @@ import {InternalLog} from "./InternalLog"
10
10
  import {SdkVerbosity} from "./SdkVerbosity";
11
11
  import {TimeProvider} from "./TimeProvider";
12
12
  import type { DdNativeLogsType, DdNativeRumType, DdNativeSdkType, DdNativeTraceType } from './nativeModulesTypes';
13
+ import { bufferNativeCallReturningId, bufferNativeCallWithId, bufferVoidNativeCall } from './DatadogProvider/Buffer/bufferNativeCall';
13
14
 
14
15
  const timeProvider = new TimeProvider();
15
16
 
@@ -44,14 +45,14 @@ class DdTraceWrapper implements DdTraceType {
44
45
  private nativeTrace: DdNativeTraceType = NativeModules.DdTrace;
45
46
 
46
47
  startSpan(operation: string, context: object = {}, timestampMs: number = timeProvider.now()): Promise<string> {
47
- let spanId = this.nativeTrace.startSpan(operation, context, timestampMs);
48
+ let spanId = bufferNativeCallReturningId(() =>this.nativeTrace.startSpan(operation, context, timestampMs));
48
49
  InternalLog.log("Starting span “" + operation + "” #" + spanId, SdkVerbosity.DEBUG);
49
50
  return spanId
50
51
  }
51
52
 
52
53
  finishSpan(spanId: string, context: object = {}, timestampMs: number = timeProvider.now()): Promise<void> {
53
54
  InternalLog.log("Finishing span #" + spanId, SdkVerbosity.DEBUG);
54
- return this.nativeTrace.finishSpan(spanId, context, timestampMs);
55
+ return bufferNativeCallWithId((id) => this.nativeTrace.finishSpan(id, context, timestampMs), spanId);
55
56
  }
56
57
  }
57
58
 
@@ -70,18 +71,18 @@ class DdRumWrapper implements DdRumType {
70
71
 
71
72
  startView(key: string, name: string, context: object = {}, timestampMs: number = timeProvider.now()): Promise<void> {
72
73
  InternalLog.log("Starting RUM View “" + name + "” #" + key, SdkVerbosity.DEBUG);
73
- return this.nativeRum.startView(key, name, context, timestampMs);
74
+ return bufferVoidNativeCall(() => this.nativeRum.startView(key, name, context, timestampMs));
74
75
  }
75
76
 
76
77
  stopView(key: string, context: object = {}, timestampMs: number = timeProvider.now()): Promise<void> {
77
78
  InternalLog.log("Stopping RUM View #" + key, SdkVerbosity.DEBUG);
78
- return this.nativeRum.stopView(key, context, timestampMs);
79
+ return bufferVoidNativeCall(() => this.nativeRum.stopView(key, context, timestampMs));
79
80
  }
80
81
 
81
82
  startAction(type: RumActionType, name: string, context: object = {}, timestampMs: number = timeProvider.now()): Promise<void> {
82
83
  InternalLog.log("Starting RUM Action “" + name + "” (" + type + ")", SdkVerbosity.DEBUG);
83
84
  this.lastActionData={type, name}
84
- return this.nativeRum.startAction(type, name, context, timestampMs);
85
+ return bufferVoidNativeCall(() => this.nativeRum.startAction(type, name, context, timestampMs));
85
86
  }
86
87
 
87
88
  stopAction(...args: [type: RumActionType, name: string, context?: object, timestampMs?: number] | [context?: object, timestampMs?: number]): Promise<void> {
@@ -93,11 +94,13 @@ class DdRumWrapper implements DdRumType {
93
94
 
94
95
  private getStopActionNativeCall = (args: [type: RumActionType, name: string, context?: object, timestampMs?: number] | [context?: object, timestampMs?: number]): Promise<void> => {
95
96
  if (isNewStopActionAPI(args)) {
96
- return this.nativeRum.stopAction(args[0], args[1], args[2] || {}, args[3] || timeProvider.now())
97
+ return bufferVoidNativeCall(() => this.nativeRum.stopAction(args[0], args[1], args[2] || {}, args[3] || timeProvider.now()))
97
98
  }
98
99
  if (isOldStopActionAPI(args)) {
99
100
  if (this.lastActionData) {
100
- return this.nativeRum.stopAction(this.lastActionData.type, this.lastActionData.name, args[0] || {}, args[1] || timeProvider.now());
101
+ DdSdk.telemetryDebug('DDdRum.stopAction called with the old signature')
102
+ const {type, name} = this.lastActionData;
103
+ return bufferVoidNativeCall(() => this.nativeRum.stopAction(type, name, args[0] || {}, args[1] || timeProvider.now()));
101
104
  }
102
105
  InternalLog.log("DdRum.startAction needs to be called before DdRum.stopAction", SdkVerbosity.WARN);
103
106
  } else {
@@ -109,29 +112,29 @@ class DdRumWrapper implements DdRumType {
109
112
 
110
113
  addAction(type: RumActionType, name: string, context: object = {}, timestampMs: number = timeProvider.now()): Promise<void> {
111
114
  InternalLog.log("Adding RUM Action “" + name + "” (" + type + ")", SdkVerbosity.DEBUG);
112
- return this.nativeRum.addAction(type, name, context, timestampMs);
115
+ return bufferVoidNativeCall(() => this.nativeRum.addAction(type, name, context, timestampMs));
113
116
  }
114
117
 
115
118
  startResource(key: string, method: string, url: string, context: object = {}, timestampMs: number = timeProvider.now()): Promise<void> {
116
119
  InternalLog.log("Starting RUM Resource #" + key + " " + method + ": " + url, SdkVerbosity.DEBUG);
117
- return this.nativeRum.startResource(key, method, url, context, timestampMs);
120
+ return bufferVoidNativeCall(() => this.nativeRum.startResource(key, method, url, context, timestampMs));
118
121
  }
119
122
 
120
123
  stopResource(key: string, statusCode: number, kind: ResourceKind, size: number = -1, context: object = {}, timestampMs: number = timeProvider.now()): Promise<void> {
121
124
  InternalLog.log("Stopping RUM Resource #" + key + " status:" + statusCode, SdkVerbosity.DEBUG);
122
- return this.nativeRum.stopResource(key, statusCode, kind, size, context, timestampMs);
125
+ return bufferVoidNativeCall(() => this.nativeRum.stopResource(key, statusCode, kind, size, context, timestampMs));
123
126
  }
124
127
 
125
128
  addError(message: string, source: ErrorSource, stacktrace: string, context: object = {}, timestampMs: number = timeProvider.now()): Promise<void> {
126
129
  InternalLog.log("Adding RUM Error “" + message + "”", SdkVerbosity.DEBUG);
127
130
  let updatedContext: any = context;
128
131
  updatedContext["_dd.error.source_type"] = "react-native";
129
- return this.nativeRum.addError(message, source, stacktrace, updatedContext, timestampMs);
132
+ return bufferVoidNativeCall(() => this.nativeRum.addError(message, source, stacktrace, updatedContext, timestampMs));
130
133
  }
131
134
 
132
135
  addTiming(name: string): Promise<void> {
133
136
  InternalLog.log("Adding timing “" + name + "” to RUM View", SdkVerbosity.DEBUG);
134
- return this.nativeRum.addTiming(name);
137
+ return bufferVoidNativeCall(() => this.nativeRum.addTiming(name));
135
138
  }
136
139
  }
137
140
 
package/src/index.tsx CHANGED
@@ -4,7 +4,12 @@
4
4
  * Copyright 2016-Present Datadog, Inc.
5
5
  */
6
6
 
7
- import { DdSdkReactNativeConfiguration } from './DdSdkReactNativeConfiguration';
7
+ import { DatadogProvider } from './DatadogProvider/DatadogProvider';
8
+ import {
9
+ DatadogProviderConfiguration,
10
+ DdSdkReactNativeConfiguration,
11
+ InitializationMode
12
+ } from './DdSdkReactNativeConfiguration';
8
13
  import { DdSdkReactNative } from './DdSdkReactNative';
9
14
  import { InternalLog } from './InternalLog';
10
15
  import { ProxyConfiguration, ProxyType } from './ProxyConfiguration';
@@ -14,6 +19,9 @@ import { DdLogs, DdTrace, DdRum } from './foundation';
14
19
  import { RumActionType, ErrorSource } from './types';
15
20
 
16
21
  export {
22
+ DatadogProvider,
23
+ DatadogProviderConfiguration,
24
+ InitializationMode,
17
25
  DdLogs,
18
26
  DdTrace,
19
27
  DdRum,
@@ -0,0 +1,30 @@
1
+ /**
2
+ * 100ms is the lower bound for a noticeable long task event.
3
+ */
4
+ const MIN_LONG_TASK_THRESHOLD_MS = 100;
5
+
6
+ /**
7
+ * 5000ms is considered an Application Not Responding (ANR) event.
8
+ */
9
+ const MAX_LONG_TASK_THRESHOLD_MS = 5000;
10
+
11
+ /**
12
+ * Makes sure the long task threshold value is above 100 and below 5000.
13
+ * Also makes sure it is a number, passing `0` if it is `false`, as the React Native
14
+ * bridge cannot handle values with dual types.
15
+ */
16
+ export const adaptLongTaskThreshold = (
17
+ longTaskThreshold: number | false
18
+ ): number => {
19
+ if (!longTaskThreshold) {
20
+ return 0;
21
+ }
22
+ if (longTaskThreshold < MIN_LONG_TASK_THRESHOLD_MS) {
23
+ return MIN_LONG_TASK_THRESHOLD_MS;
24
+ }
25
+ if (longTaskThreshold > MAX_LONG_TASK_THRESHOLD_MS) {
26
+ return MAX_LONG_TASK_THRESHOLD_MS;
27
+ }
28
+
29
+ return longTaskThreshold;
30
+ };
@@ -47,6 +47,20 @@ export type DdNativeSdkType = {
47
47
  * @param trackingConsent: Consent, which can take one of the following values: 'pending', 'granted', 'not_granted'.
48
48
  */
49
49
  setTrackingConsent(trackingConsent: string): Promise<void>;
50
+
51
+ /**
52
+ * Sends internal telemetry debug message
53
+ * @param message debug message
54
+ */
55
+ telemetryDebug(message: string): Promise<void>;
56
+
57
+ /**
58
+ * Sends internal telemetry error
59
+ * @param message error message
60
+ * @param stack error stack
61
+ * @param kind error kind
62
+ */
63
+ telemetryError(message: string, stack: string, kind: string): Promise<void>;
50
64
  };
51
65
 
52
66
  /**
@@ -8,12 +8,14 @@ import type { ErrorHandlerCallback } from 'react-native';
8
8
 
9
9
  import { InternalLog } from '../../InternalLog';
10
10
  import { SdkVerbosity } from '../../SdkVerbosity';
11
+ import {
12
+ getErrorMessage,
13
+ getErrorStackTrace,
14
+ EMPTY_STACK_TRACE
15
+ } from '../../errorUtils';
11
16
  import { DdRum } from '../../foundation';
12
17
  import { ErrorSource } from '../../types';
13
18
 
14
- const EMPTY_MESSAGE = 'Unknown Error';
15
- const EMPTY_STACK_TRACE = '';
16
-
17
19
  /**
18
20
  * Provides RUM auto-instrumentation feature to track errors as RUM events.
19
21
  */
@@ -63,8 +65,8 @@ export class DdRumErrorTracking {
63
65
 
64
66
  // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
65
67
  static onGlobalError(error: any, isFatal?: boolean): void {
66
- const message = DdRumErrorTracking.getErrorMessage(error);
67
- const stacktrace = DdRumErrorTracking.getErrorStackTrace(error);
68
+ const message = getErrorMessage(error);
69
+ const stacktrace = getErrorStackTrace(error);
68
70
  DdRum.addError(message, ErrorSource.SOURCE, stacktrace, {
69
71
  '_dd.error.is_crash': isFatal,
70
72
  '_dd.error.raw': error
@@ -86,7 +88,7 @@ export class DdRumErrorTracking {
86
88
  let stack: string = EMPTY_STACK_TRACE;
87
89
  for (let i = 0; i < params.length; i += 1) {
88
90
  const param = params[i];
89
- const paramStack = DdRumErrorTracking.getErrorStackTrace(param);
91
+ const paramStack = getErrorStackTrace(param);
90
92
  if (paramStack !== EMPTY_STACK_TRACE) {
91
93
  stack = paramStack;
92
94
  break;
@@ -98,7 +100,7 @@ export class DdRumErrorTracking {
98
100
  if (typeof param === 'string') {
99
101
  return param;
100
102
  } else {
101
- return DdRumErrorTracking.getErrorMessage(param);
103
+ return getErrorMessage(param);
102
104
  }
103
105
  })
104
106
  .join(' ');
@@ -107,43 +109,4 @@ export class DdRumErrorTracking {
107
109
  DdRumErrorTracking.defaultConsoleError.apply(console, params);
108
110
  });
109
111
  }
110
-
111
- private static getErrorMessage(error: any | undefined): string {
112
- let message = EMPTY_MESSAGE;
113
- if (error === undefined || error === null) {
114
- message = EMPTY_MESSAGE;
115
- } else if (typeof error === 'object' && 'message' in error) {
116
- message = String(error.message);
117
- } else {
118
- message = String(error);
119
- }
120
-
121
- return message;
122
- }
123
-
124
- private static getErrorStackTrace(error: any | undefined): string {
125
- let stack = EMPTY_STACK_TRACE;
126
-
127
- if (error === undefined || error === null) {
128
- stack = EMPTY_STACK_TRACE;
129
- } else if (typeof error === 'string') {
130
- stack = EMPTY_STACK_TRACE;
131
- } else if (typeof error === 'object') {
132
- if ('componentStack' in error) {
133
- stack = String(error.componentStack);
134
- } else if ('stacktrace' in error) {
135
- stack = String(error.stacktrace);
136
- } else if ('stack' in error) {
137
- stack = String(error.stack);
138
- } else if (
139
- 'sourceURL' in error &&
140
- 'line' in error &&
141
- 'column' in error
142
- ) {
143
- stack = `at ${error.sourceURL}:${error.line}:${error.column}`;
144
- }
145
- }
146
-
147
- return stack;
148
- }
149
112
  }
@@ -8,6 +8,8 @@ import React from 'react';
8
8
 
9
9
  import { InternalLog } from '../../InternalLog';
10
10
  import { SdkVerbosity } from '../../SdkVerbosity';
11
+ import { getErrorMessage } from '../../errorUtils';
12
+ import { DdSdk } from '../../foundation';
11
13
 
12
14
  import { DdEventsInterceptor } from './DdEventsInterceptor';
13
15
  import type EventsInterceptor from './EventsInterceptor';
@@ -22,6 +24,8 @@ import { getJsxRuntime } from './getJsxRuntime';
22
24
  export class DdRumUserInteractionTracking {
23
25
  private static isTracking = false;
24
26
  private static eventsInterceptor: EventsInterceptor = new NoOpEventsInterceptor();
27
+ private static originalCreateElement = React.createElement;
28
+ private static originalMemo = React.memo;
25
29
 
26
30
  private static patchCreateElementFunction = (
27
31
  originalFunction: typeof React.createElement,
@@ -80,7 +84,7 @@ export class DdRumUserInteractionTracking {
80
84
  return this.patchCreateElementFunction(originaljsx, args);
81
85
  };
82
86
  } catch (e) {
83
- // TODO: Add telemetry
87
+ DdSdk.telemetryDebug(getErrorMessage(e));
84
88
  }
85
89
 
86
90
  const originalMemo = React.memo;
@@ -120,4 +124,10 @@ export class DdRumUserInteractionTracking {
120
124
  SdkVerbosity.INFO
121
125
  );
122
126
  }
127
+
128
+ static stopTracking() {
129
+ React.createElement = this.originalCreateElement;
130
+ React.memo = this.originalMemo;
131
+ DdRumUserInteractionTracking.isTracking = false;
132
+ }
123
133
  }
@@ -24,7 +24,7 @@ export const getJsxRuntime = () => {
24
24
  // eslint-disable-next-line global-require, @typescript-eslint/no-var-requires
25
25
  const jsxRuntime = require('react/jsx-runtime');
26
26
  if (!jsxRuntime.jsx) {
27
- throw new Error('React version does not support new jsx transform');
27
+ throw new Error('React jsx runtime does not export new jsx transform');
28
28
  }
29
29
  return jsxRuntime;
30
30
  };
@@ -6,6 +6,7 @@
6
6
 
7
7
  import { NativeModules } from 'react-native';
8
8
 
9
+ import { BufferSingleton } from '../../../../DatadogProvider/Buffer/BufferSingleton';
9
10
  import { DdRumResourceTracking } from '../DdRumResourceTracking';
10
11
 
11
12
  import { XMLHttpRequestMock } from './__utils__/XMLHttpRequestMock';
@@ -17,6 +18,7 @@ const flushPromises = () => new Promise(setImmediate);
17
18
  beforeEach(() => {
18
19
  DdRum.startResource.mockClear();
19
20
  DdRum.stopResource.mockClear();
21
+ BufferSingleton.onInitialization();
20
22
  global.XMLHttpRequest = XMLHttpRequestMock;
21
23
  });
22
24
 
@@ -13,6 +13,7 @@ export type DdRumResourceTracingAttributes =
13
13
  traceId: string;
14
14
  spanId: string;
15
15
  samplingPriorityHeader: '1';
16
+ rulePsr: number;
16
17
  }
17
18
  | {
18
19
  tracingStrategy: 'DISCARD';
@@ -52,7 +53,8 @@ const generateTracingAttributesWithSampling = (
52
53
  traceId: generateTraceId(),
53
54
  spanId: generateTraceId(),
54
55
  samplingPriorityHeader: '1',
55
- tracingStrategy: 'KEEP'
56
+ tracingStrategy: 'KEEP',
57
+ rulePsr: tracingSamplingRate / 100
56
58
  };
57
59
  }
58
60
  return DISCARDED_TRACE_ATTRIBUTES;
@@ -4,7 +4,7 @@
4
4
  * Copyright 2016-Present Datadog, Inc.
5
5
  */
6
6
 
7
- import type { ResourceKind } from '../../../../../../../core/src/types';
7
+ import type { ResourceKind } from '../../../../../../src/types';
8
8
  import type { DdRumResourceTracingAttributes } from '../distributedTracing';
9
9
 
10
10
  export interface RUMResource {
@@ -39,7 +39,8 @@ const formatResourceStartContext = (
39
39
  ? undefined
40
40
  : {
41
41
  '_dd.span_id': tracingAttributes.spanId,
42
- '_dd.trace_id': tracingAttributes.traceId
42
+ '_dd.trace_id': tracingAttributes.traceId,
43
+ '_dd.rule_psr': tracingAttributes.rulePsr
43
44
  };
44
45
  };
45
46
 
@@ -6,6 +6,7 @@
6
6
 
7
7
  import { NativeModules } from 'react-native';
8
8
 
9
+ import { BufferSingleton } from '../../../../../../DatadogProvider/Buffer/BufferSingleton';
9
10
  import type { RUMResource } from '../../../domain/interfaces/RumResource';
10
11
  import { ResourceReporter } from '../ResourceReporter';
11
12
 
@@ -18,6 +19,7 @@ const flushPromises = () => new Promise(setImmediate);
18
19
  beforeEach(() => {
19
20
  DdRum.startResource.mockClear();
20
21
  DdRum.stopResource.mockClear();
22
+ BufferSingleton.onInitialization();
21
23
  });
22
24
 
23
25
  describe('Resource reporter', () => {