@datadog/mobile-react-native 1.1.4 → 1.2.0-beta1

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 (125) hide show
  1. package/README.md +18 -14
  2. package/android/src/main/kotlin/com/datadog/reactnative/DatadogSDKWrapper.kt +8 -0
  3. package/android/src/main/kotlin/com/datadog/reactnative/DatadogWrapper.kt +10 -0
  4. package/android/src/main/kotlin/com/datadog/reactnative/DdSdk.kt +25 -0
  5. package/android/src/main/kotlin/com/datadog/reactnative/DdSdkConfiguration.kt +2 -0
  6. package/android/src/main/kotlin/com/datadog/reactnative/DdSdkConfigurationExt.kt +2 -0
  7. package/android/src/test/kotlin/com/datadog/reactnative/DdSdkTest.kt +52 -0
  8. package/android/src/test/kotlin/com/datadog/tools/unit/DdSdkConfigurationExt.kt +7 -0
  9. package/android/src/test/kotlin/com/datadog/tools/unit/forge/DdSdkConfigurationForgeryFactory.kt +1 -0
  10. package/ios/Sources/DdSdk.m +10 -0
  11. package/ios/Sources/DdSdk.swift +17 -0
  12. package/ios/Sources/DdSdkConfiguration.swift +4 -0
  13. package/ios/Sources/RNDdSdkConfiguration.swift +2 -0
  14. package/lib/commonjs/DatadogProvider/Buffer/BoundedBuffer.js +173 -0
  15. package/lib/commonjs/DatadogProvider/Buffer/BoundedBuffer.js.map +1 -0
  16. package/lib/commonjs/DatadogProvider/Buffer/BufferSingleton.js +32 -0
  17. package/lib/commonjs/DatadogProvider/Buffer/BufferSingleton.js.map +1 -0
  18. package/lib/commonjs/DatadogProvider/Buffer/DatadogBuffer.js +29 -0
  19. package/lib/commonjs/DatadogProvider/Buffer/DatadogBuffer.js.map +1 -0
  20. package/lib/commonjs/DatadogProvider/Buffer/PassThroughBuffer.js +28 -0
  21. package/lib/commonjs/DatadogProvider/Buffer/PassThroughBuffer.js.map +1 -0
  22. package/lib/commonjs/DatadogProvider/Buffer/bufferNativeCall.js +32 -0
  23. package/lib/commonjs/DatadogProvider/Buffer/bufferNativeCall.js.map +1 -0
  24. package/lib/commonjs/DatadogProvider/DatadogProvider.js +101 -0
  25. package/lib/commonjs/DatadogProvider/DatadogProvider.js.map +1 -0
  26. package/lib/commonjs/DdSdkReactNative.js +138 -56
  27. package/lib/commonjs/DdSdkReactNative.js.map +1 -1
  28. package/lib/commonjs/DdSdkReactNativeConfiguration.js +102 -9
  29. package/lib/commonjs/DdSdkReactNativeConfiguration.js.map +1 -1
  30. package/lib/commonjs/errorUtils.js +60 -0
  31. package/lib/commonjs/errorUtils.js.map +1 -0
  32. package/lib/commonjs/foundation.js +19 -12
  33. package/lib/commonjs/foundation.js.map +1 -1
  34. package/lib/commonjs/index.js +20 -0
  35. package/lib/commonjs/index.js.map +1 -1
  36. package/lib/commonjs/nativeModulesTypes.js.map +1 -1
  37. package/lib/commonjs/rum/instrumentation/DdRumErrorTracking.js +8 -45
  38. package/lib/commonjs/rum/instrumentation/DdRumErrorTracking.js.map +1 -1
  39. package/lib/commonjs/rum/instrumentation/DdRumUserInteractionTracking.js +16 -1
  40. package/lib/commonjs/rum/instrumentation/DdRumUserInteractionTracking.js.map +1 -1
  41. package/lib/commonjs/rum/instrumentation/getJsxRuntime.js +1 -1
  42. package/lib/commonjs/rum/instrumentation/getJsxRuntime.js.map +1 -1
  43. package/lib/commonjs/types.js +2 -1
  44. package/lib/commonjs/types.js.map +1 -1
  45. package/lib/commonjs/version.js +1 -1
  46. package/lib/commonjs/version.js.map +1 -1
  47. package/lib/module/DatadogProvider/Buffer/BoundedBuffer.js +163 -0
  48. package/lib/module/DatadogProvider/Buffer/BoundedBuffer.js.map +1 -0
  49. package/lib/module/DatadogProvider/Buffer/BufferSingleton.js +26 -0
  50. package/lib/module/DatadogProvider/Buffer/BufferSingleton.js.map +1 -0
  51. package/lib/module/DatadogProvider/Buffer/DatadogBuffer.js +20 -0
  52. package/lib/module/DatadogProvider/Buffer/DatadogBuffer.js.map +1 -0
  53. package/lib/module/DatadogProvider/Buffer/PassThroughBuffer.js +23 -0
  54. package/lib/module/DatadogProvider/Buffer/PassThroughBuffer.js.map +1 -0
  55. package/lib/module/DatadogProvider/Buffer/bufferNativeCall.js +16 -0
  56. package/lib/module/DatadogProvider/Buffer/bufferNativeCall.js.map +1 -0
  57. package/lib/module/DatadogProvider/DatadogProvider.js +82 -0
  58. package/lib/module/DatadogProvider/DatadogProvider.js.map +1 -0
  59. package/lib/module/DdSdkReactNative.js +130 -54
  60. package/lib/module/DdSdkReactNative.js.map +1 -1
  61. package/lib/module/DdSdkReactNativeConfiguration.js +91 -8
  62. package/lib/module/DdSdkReactNativeConfiguration.js.map +1 -1
  63. package/lib/module/errorUtils.js +45 -0
  64. package/lib/module/errorUtils.js.map +1 -0
  65. package/lib/module/foundation.js +18 -12
  66. package/lib/module/foundation.js.map +1 -1
  67. package/lib/module/index.js +3 -2
  68. package/lib/module/index.js.map +1 -1
  69. package/lib/module/nativeModulesTypes.js.map +1 -1
  70. package/lib/module/rum/instrumentation/DdRumErrorTracking.js +5 -42
  71. package/lib/module/rum/instrumentation/DdRumErrorTracking.js.map +1 -1
  72. package/lib/module/rum/instrumentation/DdRumUserInteractionTracking.js +14 -1
  73. package/lib/module/rum/instrumentation/DdRumUserInteractionTracking.js.map +1 -1
  74. package/lib/module/rum/instrumentation/getJsxRuntime.js +1 -1
  75. package/lib/module/rum/instrumentation/getJsxRuntime.js.map +1 -1
  76. package/lib/module/types.js +2 -1
  77. package/lib/module/types.js.map +1 -1
  78. package/lib/module/version.js +1 -1
  79. package/lib/module/version.js.map +1 -1
  80. package/lib/typescript/DatadogProvider/Buffer/BoundedBuffer.d.ts +15 -0
  81. package/lib/typescript/DatadogProvider/Buffer/BufferSingleton.d.ts +7 -0
  82. package/lib/typescript/DatadogProvider/Buffer/DatadogBuffer.d.ts +20 -0
  83. package/lib/typescript/DatadogProvider/Buffer/PassThroughBuffer.d.ts +7 -0
  84. package/lib/typescript/DatadogProvider/Buffer/bufferNativeCall.d.ts +3 -0
  85. package/lib/typescript/DatadogProvider/DatadogProvider.d.ts +26 -0
  86. package/lib/typescript/DdSdkReactNative.d.ts +23 -1
  87. package/lib/typescript/DdSdkReactNativeConfiguration.d.ts +63 -0
  88. package/lib/typescript/errorUtils.d.ts +4 -0
  89. package/lib/typescript/index.d.ts +3 -2
  90. package/lib/typescript/nativeModulesTypes.d.ts +12 -0
  91. package/lib/typescript/rum/instrumentation/DdRumErrorTracking.d.ts +0 -2
  92. package/lib/typescript/rum/instrumentation/DdRumUserInteractionTracking.d.ts +3 -0
  93. package/lib/typescript/types.d.ts +2 -1
  94. package/lib/typescript/version.d.ts +1 -1
  95. package/package.json +2 -2
  96. package/src/DatadogProvider/Buffer/BoundedBuffer.ts +209 -0
  97. package/src/DatadogProvider/Buffer/BufferSingleton.ts +26 -0
  98. package/src/DatadogProvider/Buffer/DatadogBuffer.ts +34 -0
  99. package/src/DatadogProvider/Buffer/PassThroughBuffer.ts +16 -0
  100. package/src/DatadogProvider/Buffer/__tests__/BoundedBuffer.test.ts +202 -0
  101. package/src/DatadogProvider/Buffer/__tests__/BufferSingleton.test.ts +50 -0
  102. package/src/DatadogProvider/Buffer/bufferNativeCall.ts +24 -0
  103. package/src/DatadogProvider/DatadogProvider.tsx +122 -0
  104. package/src/DatadogProvider/__tests__/__utils__/renderWithProvider.tsx +111 -0
  105. package/src/DatadogProvider/__tests__/initialization.test.tsx +174 -0
  106. package/src/DatadogProvider/__tests__/initializationModes.test.tsx +174 -0
  107. package/src/DdSdkReactNative.tsx +205 -105
  108. package/src/DdSdkReactNativeConfiguration.tsx +160 -8
  109. package/src/__tests__/DdRumWrapper.test.tsx +3 -27
  110. package/src/__tests__/DdSdkReactNative.test.tsx +1 -0
  111. package/src/__tests__/DdSdkReactNativeConfiguration.test.ts +168 -0
  112. package/src/__tests__/foundation.test.ts +11 -2
  113. package/src/__tests__/rum/instrumentation/DdRumUserInteractionTracking.test.tsx +18 -4
  114. package/src/errorUtils.ts +50 -0
  115. package/src/foundation.tsx +15 -12
  116. package/src/index.tsx +9 -1
  117. package/src/nativeModulesTypes.ts +14 -0
  118. package/src/rum/instrumentation/DdRumErrorTracking.tsx +9 -46
  119. package/src/rum/instrumentation/DdRumUserInteractionTracking.tsx +11 -1
  120. package/src/rum/instrumentation/getJsxRuntime.ts +1 -1
  121. package/src/rum/instrumentation/resourceTracking/__tests__/DdRumResourceTracking.test.ts +2 -0
  122. package/src/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/__tests__/ResourceReporter.test.ts +2 -0
  123. package/src/rum/instrumentation/resourceTracking/implementation/__tests__/XHRProxy.test.ts +3 -0
  124. package/src/types.tsx +2 -1
  125. package/src/version.ts +1 -1
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,
@@ -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, import/no-dynamic-require
25
25
  const jsxRuntime = require(jsxRuntimePackage);
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.jsx;
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
 
@@ -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', () => {
@@ -6,6 +6,7 @@
6
6
 
7
7
  import { Platform, NativeModules } from 'react-native';
8
8
 
9
+ import { BufferSingleton } from '../../../../../DatadogProvider/Buffer/BufferSingleton';
9
10
  import { InternalLog } from '../../../../../InternalLog';
10
11
  import { SdkVerbosity } from '../../../../../SdkVerbosity';
11
12
  import { XMLHttpRequestMock } from '../../__tests__/__utils__/XMLHttpRequestMock';
@@ -43,6 +44,8 @@ let xhrProxy;
43
44
  beforeEach(() => {
44
45
  DdRum.startResource.mockClear();
45
46
  DdRum.stopResource.mockClear();
47
+ BufferSingleton.onInitialization();
48
+
46
49
  xhrProxy = new XHRProxy({
47
50
  xhrType: XMLHttpRequestMock,
48
51
  resourceReporter: new ResourceReporter([])
package/src/types.tsx CHANGED
@@ -16,7 +16,8 @@ export class DdSdkConfiguration {
16
16
  readonly sampleRate: number,
17
17
  readonly site: string,
18
18
  readonly trackingConsent: string,
19
- readonly additionalConfig: object
19
+ readonly additionalConfig: object,
20
+ readonly telemetrySampleRate: number
20
21
  ) {}
21
22
  }
22
23
 
package/src/version.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  // generated by genversion
2
- export const version = '1.1.4';
2
+ export const version = '1.2.0-beta1';