@datadog/mobile-react-native 1.0.0-rc8 → 1.1.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 (192) hide show
  1. package/DatadogSDKReactNative.podspec +2 -1
  2. package/android/build.gradle +73 -3
  3. package/android/gradle.properties +1 -0
  4. package/android/src/main/kotlin/com/datadog/reactnative/DatadogSDKWrapper.kt +54 -0
  5. package/android/src/main/kotlin/com/datadog/reactnative/DatadogWrapper.kt +86 -0
  6. package/android/src/main/{java → kotlin}/com/datadog/reactnative/DdLogs.kt +27 -11
  7. package/android/src/main/kotlin/com/datadog/reactnative/DdRum.kt +305 -0
  8. package/android/src/main/kotlin/com/datadog/reactnative/DdSdk.kt +280 -0
  9. package/android/src/main/{java → kotlin}/com/datadog/reactnative/DdSdkBridgeExt.kt +2 -2
  10. package/android/src/main/kotlin/com/datadog/reactnative/DdSdkConfiguration.kt +29 -0
  11. package/android/src/main/{java → kotlin}/com/datadog/reactnative/DdSdkConfigurationExt.kt +2 -4
  12. package/android/src/main/{java → kotlin}/com/datadog/reactnative/DdSdkReactNativePackage.kt +3 -0
  13. package/android/src/main/kotlin/com/datadog/reactnative/DdTrace.kt +86 -0
  14. package/android/src/main/kotlin/com/datadog/reactnative/GlobalState.kt +32 -0
  15. package/android/src/main/kotlin/com/datadog/reactnative/NoOpViewTrackingStrategy.kt +23 -0
  16. package/android/src/main/kotlin/com/datadog/reactnative/ProxyAuthenticator.kt +60 -0
  17. package/android/src/test/kotlin/com/datadog/reactnative/DdLogsTest.kt +170 -0
  18. package/android/src/test/kotlin/com/datadog/reactnative/DdRumTest.kt +408 -0
  19. package/android/src/test/kotlin/com/datadog/reactnative/DdSdkTest.kt +1547 -0
  20. package/android/src/test/kotlin/com/datadog/reactnative/DdTraceTest.kt +306 -0
  21. package/android/src/test/kotlin/com/datadog/reactnative/GlobalStateTest.kt +118 -0
  22. package/android/src/test/kotlin/com/datadog/reactnative/ProxyAuthenticatorTest.kt +123 -0
  23. package/android/src/test/kotlin/com/datadog/tools/unit/DdSdkConfigurationExt.kt +33 -0
  24. package/android/src/test/kotlin/com/datadog/tools/unit/GenericAssert.kt +43 -0
  25. package/android/src/test/kotlin/com/datadog/tools/unit/MapExt.kt +22 -0
  26. package/android/src/test/kotlin/com/datadog/tools/unit/ReflectUtils.kt +267 -0
  27. package/android/src/test/kotlin/com/datadog/tools/unit/forge/BaseConfigurator.kt +26 -0
  28. package/android/src/test/kotlin/com/datadog/tools/unit/forge/DdSdkConfigurationForgeryFactory.kt +33 -0
  29. package/android/src/test/kotlin/com/datadog/tools/unit/forge/PackageInfoForgeryFactory.kt +20 -0
  30. package/android/src/test/kotlin/com/datadog/tools/unit/forge/Throwable.kt +31 -0
  31. package/android/src/test/kotlin/com/datadog/tools/unit/forge/ThrowableForgeryFactory.kt +21 -0
  32. package/android/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker +1 -0
  33. package/datadog-sourcemaps.gradle +137 -0
  34. package/ios/Sources/AnyEncodable.swift +138 -0
  35. package/ios/Sources/Attributes.swift +101 -0
  36. package/ios/Sources/DdLogs.swift +35 -11
  37. package/ios/Sources/DdRum.m +3 -1
  38. package/ios/Sources/DdRum.swift +184 -22
  39. package/ios/Sources/DdSdk.swift +190 -10
  40. package/ios/Sources/DdSdkConfiguration.swift +51 -0
  41. package/ios/Sources/DdTrace.swift +41 -6
  42. package/ios/Sources/GlobalState.swift +28 -0
  43. package/ios/Sources/QueueHolder.swift +10 -0
  44. package/ios/Sources/RNDdSdkConfiguration.swift +5 -6
  45. package/lib/commonjs/DdSdkReactNative.js +16 -2
  46. package/lib/commonjs/DdSdkReactNative.js.map +1 -1
  47. package/lib/commonjs/DdSdkReactNativeConfiguration.js +24 -0
  48. package/lib/commonjs/DdSdkReactNativeConfiguration.js.map +1 -1
  49. package/lib/commonjs/foundation.js +36 -2
  50. package/lib/commonjs/foundation.js.map +1 -1
  51. package/lib/commonjs/nativeModulesTypes.js +36 -0
  52. package/lib/commonjs/nativeModulesTypes.js.map +1 -0
  53. package/lib/commonjs/rum/instrumentation/DdEventsInterceptor.js +4 -17
  54. package/lib/commonjs/rum/instrumentation/DdEventsInterceptor.js.map +1 -1
  55. package/lib/commonjs/rum/instrumentation/DdRumErrorTracking.js +4 -4
  56. package/lib/commonjs/rum/instrumentation/DdRumErrorTracking.js.map +1 -1
  57. package/lib/commonjs/rum/instrumentation/resourceTracking/DdRumResourceTracking.js +73 -0
  58. package/lib/commonjs/rum/instrumentation/resourceTracking/DdRumResourceTracking.js.map +1 -0
  59. package/lib/commonjs/rum/instrumentation/{TraceIdentifier.js → resourceTracking/domain/distributedTracing.js} +40 -1
  60. package/lib/commonjs/rum/instrumentation/resourceTracking/domain/distributedTracing.js.map +1 -0
  61. package/lib/commonjs/rum/instrumentation/resourceTracking/domain/firstPartyHosts.js +51 -0
  62. package/lib/commonjs/rum/instrumentation/resourceTracking/domain/firstPartyHosts.js.map +1 -0
  63. package/lib/commonjs/rum/instrumentation/resourceTracking/domain/interfaces/RequestProxy.js +25 -0
  64. package/lib/commonjs/rum/instrumentation/resourceTracking/domain/interfaces/RequestProxy.js.map +1 -0
  65. package/lib/commonjs/rum/instrumentation/resourceTracking/domain/interfaces/RumResource.js +2 -0
  66. package/lib/commonjs/rum/instrumentation/{DdRumXhr.js.map → resourceTracking/domain/interfaces/RumResource.js.map} +0 -0
  67. package/lib/commonjs/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/ResourceReporter.js +57 -0
  68. package/lib/commonjs/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/ResourceReporter.js.map +1 -0
  69. package/lib/commonjs/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/internalDevResourceBlocklist.js +49 -0
  70. package/lib/commonjs/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/internalDevResourceBlocklist.js.map +1 -0
  71. package/lib/commonjs/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/resourceTiming.js +45 -0
  72. package/lib/commonjs/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/resourceTiming.js.map +1 -0
  73. package/lib/commonjs/rum/instrumentation/{URLHostParser.js → resourceTracking/implementation/URLHostParser.js} +16 -7
  74. package/lib/commonjs/rum/instrumentation/resourceTracking/implementation/URLHostParser.js.map +1 -0
  75. package/lib/commonjs/rum/instrumentation/resourceTracking/implementation/XHRProxy.js +167 -0
  76. package/lib/commonjs/rum/instrumentation/resourceTracking/implementation/XHRProxy.js.map +1 -0
  77. package/lib/commonjs/rum/instrumentation/resourceTracking/implementation/responseSize.js +97 -0
  78. package/lib/commonjs/rum/instrumentation/resourceTracking/implementation/responseSize.js.map +1 -0
  79. package/lib/commonjs/types.js +26 -1
  80. package/lib/commonjs/types.js.map +1 -1
  81. package/lib/commonjs/version.js +1 -1
  82. package/lib/commonjs/version.js.map +1 -1
  83. package/lib/module/DdSdkReactNative.js +15 -1
  84. package/lib/module/DdSdkReactNative.js.map +1 -1
  85. package/lib/module/DdSdkReactNativeConfiguration.js +24 -0
  86. package/lib/module/DdSdkReactNativeConfiguration.js.map +1 -1
  87. package/lib/module/foundation.js +36 -2
  88. package/lib/module/foundation.js.map +1 -1
  89. package/lib/module/nativeModulesTypes.js +26 -0
  90. package/lib/module/nativeModulesTypes.js.map +1 -0
  91. package/lib/module/rum/instrumentation/DdEventsInterceptor.js +2 -14
  92. package/lib/module/rum/instrumentation/DdEventsInterceptor.js.map +1 -1
  93. package/lib/module/rum/instrumentation/DdRumErrorTracking.js +3 -4
  94. package/lib/module/rum/instrumentation/DdRumErrorTracking.js.map +1 -1
  95. package/lib/module/rum/instrumentation/resourceTracking/DdRumResourceTracking.js +61 -0
  96. package/lib/module/rum/instrumentation/resourceTracking/DdRumResourceTracking.js.map +1 -0
  97. package/lib/module/rum/instrumentation/{TraceIdentifier.js → resourceTracking/domain/distributedTracing.js} +35 -1
  98. package/lib/module/rum/instrumentation/resourceTracking/domain/distributedTracing.js.map +1 -0
  99. package/lib/module/rum/instrumentation/resourceTracking/domain/firstPartyHosts.js +34 -0
  100. package/lib/module/rum/instrumentation/resourceTracking/domain/firstPartyHosts.js.map +1 -0
  101. package/lib/module/rum/instrumentation/resourceTracking/domain/interfaces/RequestProxy.js +16 -0
  102. package/lib/module/rum/instrumentation/resourceTracking/domain/interfaces/RequestProxy.js.map +1 -0
  103. package/lib/module/rum/instrumentation/resourceTracking/domain/interfaces/RumResource.js +2 -0
  104. package/lib/module/rum/instrumentation/{DdRumXhr.js.map → resourceTracking/domain/interfaces/RumResource.js.map} +0 -0
  105. package/lib/module/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/ResourceReporter.js +50 -0
  106. package/lib/module/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/ResourceReporter.js.map +1 -0
  107. package/lib/module/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/internalDevResourceBlocklist.js +40 -0
  108. package/lib/module/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/internalDevResourceBlocklist.js.map +1 -0
  109. package/lib/module/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/resourceTiming.js +36 -0
  110. package/lib/module/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/resourceTiming.js.map +1 -0
  111. package/{src/rum/instrumentation/URLHostParser.ts → lib/module/rum/instrumentation/resourceTracking/implementation/URLHostParser.js} +15 -8
  112. package/lib/module/rum/instrumentation/resourceTracking/implementation/URLHostParser.js.map +1 -0
  113. package/lib/module/rum/instrumentation/resourceTracking/implementation/XHRProxy.js +151 -0
  114. package/lib/module/rum/instrumentation/resourceTracking/implementation/XHRProxy.js.map +1 -0
  115. package/lib/module/rum/instrumentation/resourceTracking/implementation/responseSize.js +86 -0
  116. package/lib/module/rum/instrumentation/resourceTracking/implementation/responseSize.js.map +1 -0
  117. package/lib/module/types.js +23 -0
  118. package/lib/module/types.js.map +1 -1
  119. package/lib/module/version.js +1 -1
  120. package/lib/module/version.js.map +1 -1
  121. package/lib/typescript/DdSdkReactNative.d.ts +2 -0
  122. package/lib/typescript/DdSdkReactNativeConfiguration.d.ts +20 -0
  123. package/lib/typescript/foundation.d.ts +3 -2
  124. package/lib/typescript/nativeModulesTypes.d.ts +168 -0
  125. package/lib/typescript/rum/instrumentation/DdEventsInterceptor.d.ts +0 -15
  126. package/lib/typescript/rum/instrumentation/resourceTracking/DdRumResourceTracking.d.ts +15 -0
  127. package/lib/typescript/rum/instrumentation/resourceTracking/domain/distributedTracing.d.ts +18 -0
  128. package/lib/typescript/rum/instrumentation/resourceTracking/domain/firstPartyHosts.d.ts +6 -0
  129. package/lib/typescript/rum/instrumentation/resourceTracking/domain/interfaces/RequestProxy.d.ts +8 -0
  130. package/lib/typescript/rum/instrumentation/resourceTracking/domain/interfaces/RumResource.d.ts +20 -0
  131. package/lib/typescript/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/ResourceReporter.d.ts +8 -0
  132. package/lib/typescript/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/internalDevResourceBlocklist.d.ts +6 -0
  133. package/lib/typescript/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/resourceTiming.d.ts +17 -0
  134. package/lib/typescript/rum/instrumentation/resourceTracking/implementation/URLHostParser.d.ts +6 -0
  135. package/lib/typescript/rum/instrumentation/resourceTracking/implementation/XHRProxy.d.ts +25 -0
  136. package/lib/typescript/rum/instrumentation/resourceTracking/implementation/responseSize.d.ts +3 -0
  137. package/lib/typescript/types.d.ts +42 -7
  138. package/lib/typescript/version.d.ts +1 -1
  139. package/package.json +7 -5
  140. package/src/DdSdkReactNative.tsx +21 -1
  141. package/src/DdSdkReactNativeConfiguration.tsx +20 -0
  142. package/src/__tests__/DdSdkReactNative.test.tsx +87 -8
  143. package/src/__tests__/foundation.test.ts +79 -0
  144. package/src/__tests__/rum/instrumentation/DdEventsInterceptor.test.tsx +9 -9
  145. package/src/__tests__/rum/instrumentation/DdRumUserInteractionTracking.test.tsx +1 -1
  146. package/src/foundation.tsx +40 -11
  147. package/src/nativeModulesTypes.ts +258 -0
  148. package/src/rum/instrumentation/DdEventsInterceptor.tsx +2 -17
  149. package/src/rum/instrumentation/DdRumErrorTracking.tsx +3 -4
  150. package/src/rum/instrumentation/resourceTracking/DdRumResourceTracking.tsx +67 -0
  151. package/src/rum/instrumentation/resourceTracking/__tests__/DdRumResourceTracking.test.ts +79 -0
  152. package/src/{__tests__/rum/instrumentation → rum/instrumentation/resourceTracking/__tests__}/__utils__/XMLHttpRequestMock.ts +0 -0
  153. package/src/{__tests__/rum/instrumentation/TraceIdentifier.test.tsx → rum/instrumentation/resourceTracking/domain/__tests__/distributedTracing.test.ts} +1 -1
  154. package/src/rum/instrumentation/resourceTracking/domain/__tests__/firstPartyHosts.test.ts +22 -0
  155. package/src/rum/instrumentation/resourceTracking/domain/distributedTracing.tsx +87 -0
  156. package/src/rum/instrumentation/resourceTracking/domain/firstPartyHosts.ts +52 -0
  157. package/src/rum/instrumentation/resourceTracking/domain/interfaces/RequestProxy.ts +15 -0
  158. package/src/rum/instrumentation/resourceTracking/domain/interfaces/RumResource.ts +27 -0
  159. package/src/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/ResourceReporter.ts +78 -0
  160. package/src/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/__tests__/ResourceReporter.test.ts +83 -0
  161. package/src/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/__tests__/__utils__/ResourceMockFactory.ts +45 -0
  162. package/src/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/__tests__/internalDevResourceBlocklist.test.ts +69 -0
  163. package/src/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/internalDevResourceBlocklist.ts +50 -0
  164. package/src/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/resourceTiming.ts +70 -0
  165. package/src/rum/instrumentation/resourceTracking/implementation/URLHostParser.ts +30 -0
  166. package/src/rum/instrumentation/resourceTracking/implementation/XHRProxy.ts +197 -0
  167. package/src/{__tests__/rum/instrumentation → rum/instrumentation/resourceTracking/implementation/__tests__}/URLHostParser.test.ts +3 -3
  168. package/src/{__tests__/rum/instrumentation/DdRumResourceTracking.test.tsx → rum/instrumentation/resourceTracking/implementation/__tests__/XHRProxy.test.ts} +83 -49
  169. package/src/rum/instrumentation/resourceTracking/implementation/responseSize.ts +83 -0
  170. package/src/types.tsx +62 -7
  171. package/src/version.ts +1 -1
  172. package/android/src/main/java/com/datadog/reactnative/DdRum.kt +0 -142
  173. package/android/src/main/java/com/datadog/reactnative/DdSdk.kt +0 -67
  174. package/android/src/main/java/com/datadog/reactnative/DdTrace.kt +0 -51
  175. package/lib/commonjs/rum/instrumentation/DdRumResourceTracking.js +0 -356
  176. package/lib/commonjs/rum/instrumentation/DdRumResourceTracking.js.map +0 -1
  177. package/lib/commonjs/rum/instrumentation/DdRumXhr.js +0 -2
  178. package/lib/commonjs/rum/instrumentation/TraceIdentifier.js.map +0 -1
  179. package/lib/commonjs/rum/instrumentation/URLHostParser.js.map +0 -1
  180. package/lib/module/rum/instrumentation/DdRumResourceTracking.js +0 -331
  181. package/lib/module/rum/instrumentation/DdRumResourceTracking.js.map +0 -1
  182. package/lib/module/rum/instrumentation/DdRumXhr.js +0 -2
  183. package/lib/module/rum/instrumentation/TraceIdentifier.js.map +0 -1
  184. package/lib/module/rum/instrumentation/URLHostParser.js +0 -24
  185. package/lib/module/rum/instrumentation/URLHostParser.js.map +0 -1
  186. package/lib/typescript/rum/instrumentation/DdRumResourceTracking.d.ts +0 -40
  187. package/lib/typescript/rum/instrumentation/DdRumXhr.d.ts +0 -23
  188. package/lib/typescript/rum/instrumentation/TraceIdentifier.d.ts +0 -1
  189. package/lib/typescript/rum/instrumentation/URLHostParser.d.ts +0 -6
  190. package/src/rum/instrumentation/DdRumResourceTracking.tsx +0 -426
  191. package/src/rum/instrumentation/DdRumXhr.tsx +0 -33
  192. package/src/rum/instrumentation/TraceIdentifier.tsx +0 -34
@@ -6,23 +6,26 @@
6
6
 
7
7
  import { Platform, NativeModules } from 'react-native';
8
8
 
9
- import { InternalLog } from '../../../InternalLog';
10
- import { SdkVerbosity } from '../../../SdkVerbosity';
9
+ import { InternalLog } from '../../../../../InternalLog';
10
+ import { SdkVerbosity } from '../../../../../SdkVerbosity';
11
+ import { XMLHttpRequestMock } from '../../__tests__/__utils__/XMLHttpRequestMock';
12
+ import { firstPartyHostsRegexBuilder } from '../../domain/firstPartyHosts';
13
+ import { ResourceReporter } from '../DatadogRumResource/ResourceReporter';
11
14
  import {
12
- DdRumResourceTracking,
13
15
  PARENT_ID_HEADER_KEY,
14
16
  TRACE_ID_HEADER_KEY,
15
17
  ORIGIN_RUM,
16
18
  ORIGIN_HEADER_KEY,
17
19
  SAMPLING_PRIORITY_HEADER_KEY,
20
+ XHRProxy
21
+ } from '../XHRProxy';
22
+ import {
18
23
  calculateResponseSize,
19
24
  RESOURCE_SIZE_ERROR_MESSAGE
20
- } from '../../../rum/instrumentation/DdRumResourceTracking';
21
-
22
- import { XMLHttpRequestMock } from './__utils__/XMLHttpRequestMock';
25
+ } from '../responseSize';
23
26
 
24
27
  jest.useFakeTimers();
25
- jest.mock('../../../InternalLog');
28
+ jest.mock('../../../../../InternalLog');
26
29
  const mockedInternalLog = (InternalLog as unknown) as {
27
30
  log: jest.MockedFunction<typeof InternalLog.log>;
28
31
  };
@@ -35,10 +38,15 @@ function randomInt(max: number): number {
35
38
  }
36
39
 
37
40
  const flushPromises = () => new Promise(setImmediate);
41
+ let xhrProxy;
38
42
 
39
43
  beforeEach(() => {
40
44
  DdRum.startResource.mockClear();
41
45
  DdRum.stopResource.mockClear();
46
+ xhrProxy = new XHRProxy({
47
+ xhrType: XMLHttpRequestMock,
48
+ resourceReporter: new ResourceReporter([])
49
+ });
42
50
 
43
51
  // we need this because with ms precision between Date.now() calls we can get 0, so we advance
44
52
  // it manually with each call
@@ -52,20 +60,20 @@ beforeEach(() => {
52
60
  });
53
61
 
54
62
  afterEach(() => {
55
- DdRumResourceTracking.stopTracking();
63
+ xhrProxy.onTrackingStop();
56
64
  (Date.now as jest.MockedFunction<typeof Date.now>).mockClear();
57
65
  jest.spyOn(global.Math, 'random').mockRestore();
58
66
  });
59
67
 
60
- describe('DdRumResourceTracking', () => {
68
+ describe('XHRPr', () => {
61
69
  describe('resource interception', () => {
62
70
  it('intercepts XHR request when startTracking() + XHR.open() + XHR.send()', async () => {
63
71
  // GIVEN
64
72
  const method = 'GET';
65
73
  const url = 'https://api.example.com/v2/user';
66
- DdRumResourceTracking.startTrackingInternal(XMLHttpRequestMock, {
74
+ xhrProxy.onTrackingStart({
67
75
  tracingSamplingRate: 100,
68
- firstPartyHosts: []
76
+ firstPartyHostsRegex: firstPartyHostsRegexBuilder([])
69
77
  });
70
78
 
71
79
  // WHEN
@@ -98,9 +106,9 @@ describe('DdRumResourceTracking', () => {
98
106
  // GIVEN
99
107
  const method = 'GET';
100
108
  const url = 'https://api.example.com/v2/user';
101
- DdRumResourceTracking.startTrackingInternal(XMLHttpRequestMock, {
109
+ xhrProxy.onTrackingStart({
102
110
  tracingSamplingRate: 100,
103
- firstPartyHosts: []
111
+ firstPartyHostsRegex: firstPartyHostsRegexBuilder([])
104
112
  });
105
113
 
106
114
  // WHEN
@@ -133,9 +141,9 @@ describe('DdRumResourceTracking', () => {
133
141
  // GIVEN
134
142
  const method = 'GET';
135
143
  const url = 'https://api.example.com/v2/user';
136
- DdRumResourceTracking.startTrackingInternal(XMLHttpRequestMock, {
144
+ xhrProxy.onTrackingStart({
137
145
  tracingSamplingRate: 100,
138
- firstPartyHosts: []
146
+ firstPartyHostsRegex: firstPartyHostsRegexBuilder([])
139
147
  });
140
148
 
141
149
  // WHEN
@@ -170,9 +178,11 @@ describe('DdRumResourceTracking', () => {
170
178
  // GIVEN
171
179
  const method = 'GET';
172
180
  const url = 'https://api.example.com/v2/user';
173
- DdRumResourceTracking.startTrackingInternal(XMLHttpRequestMock, {
181
+ xhrProxy.onTrackingStart({
174
182
  tracingSamplingRate: 100,
175
- firstPartyHosts: ['api.example.com']
183
+ firstPartyHostsRegex: firstPartyHostsRegexBuilder([
184
+ 'api.example.com'
185
+ ])
176
186
  });
177
187
 
178
188
  // WHEN
@@ -193,9 +203,11 @@ describe('DdRumResourceTracking', () => {
193
203
  // GIVEN
194
204
  const method = 'GET';
195
205
  const url = 'https://api.example.com/v2/user';
196
- DdRumResourceTracking.startTrackingInternal(XMLHttpRequestMock, {
206
+ xhrProxy.onTrackingStart({
197
207
  tracingSamplingRate: 100,
198
- firstPartyHosts: ['api.example.com']
208
+ firstPartyHostsRegex: firstPartyHostsRegexBuilder([
209
+ 'api.example.com'
210
+ ])
199
211
  });
200
212
 
201
213
  // WHEN
@@ -216,9 +228,12 @@ describe('DdRumResourceTracking', () => {
216
228
  // GIVEN
217
229
  const method = 'GET';
218
230
  const url = 'https://api.example.com:443/v2/user';
219
- DdRumResourceTracking.startTrackingInternal(XMLHttpRequestMock, {
231
+ xhrProxy.onTrackingStart({
220
232
  tracingSamplingRate: 100,
221
- firstPartyHosts: ['something.fr', 'example.com']
233
+ firstPartyHostsRegex: firstPartyHostsRegexBuilder([
234
+ 'something.fr',
235
+ 'example.com'
236
+ ])
222
237
  });
223
238
 
224
239
  // WHEN
@@ -239,9 +254,9 @@ describe('DdRumResourceTracking', () => {
239
254
  // GIVEN
240
255
  const method = 'GET';
241
256
  const url = 'https://api.example.com/v2/user';
242
- DdRumResourceTracking.startTrackingInternal(XMLHttpRequestMock, {
257
+ xhrProxy.onTrackingStart({
243
258
  tracingSamplingRate: 100,
244
- firstPartyHosts: []
259
+ firstPartyHostsRegex: firstPartyHostsRegexBuilder([])
245
260
  });
246
261
 
247
262
  // WHEN
@@ -261,9 +276,12 @@ describe('DdRumResourceTracking', () => {
261
276
  // GIVEN
262
277
  const method = 'GET';
263
278
  const url = 'https://api.example.com/v2/user';
264
- DdRumResourceTracking.startTrackingInternal(XMLHttpRequestMock, {
279
+ xhrProxy.onTrackingStart({
265
280
  tracingSamplingRate: 100,
266
- firstPartyHosts: ['google.com', 'api.example.co']
281
+ firstPartyHostsRegex: firstPartyHostsRegexBuilder([
282
+ 'google.com',
283
+ 'api.example.co'
284
+ ])
267
285
  });
268
286
 
269
287
  // WHEN
@@ -283,9 +301,11 @@ describe('DdRumResourceTracking', () => {
283
301
  // GIVEN
284
302
  const method = 'GET';
285
303
  const url = 'crash';
286
- DdRumResourceTracking.startTrackingInternal(XMLHttpRequestMock, {
304
+ xhrProxy.onTrackingStart({
287
305
  tracingSamplingRate: 100,
288
- firstPartyHosts: ['example.com']
306
+ firstPartyHostsRegex: firstPartyHostsRegexBuilder([
307
+ 'example.com'
308
+ ])
289
309
  });
290
310
 
291
311
  // WHEN
@@ -305,9 +325,11 @@ describe('DdRumResourceTracking', () => {
305
325
  // GIVEN
306
326
  const method = 'GET';
307
327
  const url = 'https://api.example.com/v2/user';
308
- DdRumResourceTracking.startTrackingInternal(XMLHttpRequestMock, {
328
+ xhrProxy.onTrackingStart({
309
329
  tracingSamplingRate: 50,
310
- firstPartyHosts: ['api.example.com']
330
+ firstPartyHostsRegex: firstPartyHostsRegexBuilder([
331
+ 'api.example.com'
332
+ ])
311
333
  });
312
334
  jest.spyOn(global.Math, 'random').mockReturnValue(0.7);
313
335
 
@@ -328,9 +350,9 @@ describe('DdRumResourceTracking', () => {
328
350
  // GIVEN
329
351
  const method = 'GET';
330
352
  const url = 'https://api.example.com/v2/user';
331
- DdRumResourceTracking.startTrackingInternal(XMLHttpRequestMock, {
353
+ xhrProxy.onTrackingStart({
332
354
  tracingSamplingRate: 100,
333
- firstPartyHosts: []
355
+ firstPartyHostsRegex: firstPartyHostsRegexBuilder([])
334
356
  });
335
357
 
336
358
  // WHEN
@@ -349,9 +371,11 @@ describe('DdRumResourceTracking', () => {
349
371
  // GIVEN
350
372
  const method = 'GET';
351
373
  const url = 'https://api.example.com/v2/user';
352
- DdRumResourceTracking.startTrackingInternal(XMLHttpRequestMock, {
374
+ xhrProxy.onTrackingStart({
353
375
  tracingSamplingRate: 100,
354
- firstPartyHosts: ['api.example.com']
376
+ firstPartyHostsRegex: firstPartyHostsRegexBuilder([
377
+ 'api.example.com'
378
+ ])
355
379
  });
356
380
 
357
381
  // WHEN
@@ -370,9 +394,11 @@ describe('DdRumResourceTracking', () => {
370
394
  // GIVEN
371
395
  const method = 'GET';
372
396
  const url = 'https://api.example.com/v2/user';
373
- DdRumResourceTracking.startTrackingInternal(XMLHttpRequestMock, {
397
+ xhrProxy.onTrackingStart({
374
398
  tracingSamplingRate: 50,
375
- firstPartyHosts: ['api.example.com']
399
+ firstPartyHostsRegex: firstPartyHostsRegexBuilder([
400
+ 'api.example.com'
401
+ ])
376
402
  });
377
403
  jest.spyOn(global.Math, 'random').mockReturnValue(0.7);
378
404
 
@@ -394,9 +420,11 @@ describe('DdRumResourceTracking', () => {
394
420
  // GIVEN
395
421
  const method = 'GET';
396
422
  const url = 'https://api.example.com/v2/user';
397
- DdRumResourceTracking.startTrackingInternal(XMLHttpRequestMock, {
423
+ xhrProxy.onTrackingStart({
398
424
  tracingSamplingRate: 100,
399
- firstPartyHosts: ['api.example.com']
425
+ firstPartyHostsRegex: firstPartyHostsRegexBuilder([
426
+ 'api.example.com'
427
+ ])
400
428
  });
401
429
 
402
430
  // WHEN
@@ -417,9 +445,11 @@ describe('DdRumResourceTracking', () => {
417
445
  // GIVEN
418
446
  const method = 'GET';
419
447
  const url = 'https://api.example.com/v2/user';
420
- DdRumResourceTracking.startTrackingInternal(XMLHttpRequestMock, {
448
+ xhrProxy.onTrackingStart({
421
449
  tracingSamplingRate: 100,
422
- firstPartyHosts: ['api.example.com']
450
+ firstPartyHostsRegex: firstPartyHostsRegexBuilder([
451
+ 'api.example.com'
452
+ ])
423
453
  });
424
454
 
425
455
  // WHEN
@@ -441,9 +471,11 @@ describe('DdRumResourceTracking', () => {
441
471
  // GIVEN
442
472
  const method = 'GET';
443
473
  const url = 'https://api.example.com/v2/user';
444
- DdRumResourceTracking.startTrackingInternal(XMLHttpRequestMock, {
474
+ xhrProxy.onTrackingStart({
445
475
  tracingSamplingRate: 100,
446
- firstPartyHosts: ['api.example.com']
476
+ firstPartyHostsRegex: firstPartyHostsRegexBuilder([
477
+ 'api.example.com'
478
+ ])
447
479
  });
448
480
 
449
481
  // WHEN
@@ -465,9 +497,11 @@ describe('DdRumResourceTracking', () => {
465
497
  // GIVEN
466
498
  const method = 'GET';
467
499
  const url = 'https://api.example.com/v2/user';
468
- DdRumResourceTracking.startTrackingInternal(XMLHttpRequestMock, {
500
+ xhrProxy.onTrackingStart({
469
501
  tracingSamplingRate: 50,
470
- firstPartyHosts: ['api.example.com']
502
+ firstPartyHostsRegex: firstPartyHostsRegexBuilder([
503
+ 'api.example.com'
504
+ ])
471
505
  });
472
506
  jest.spyOn(global.Math, 'random').mockReturnValue(0.7);
473
507
 
@@ -498,9 +532,9 @@ describe('DdRumResourceTracking', () => {
498
532
  // GIVEN
499
533
  const method = 'GET';
500
534
  const url = 'https://api.example.com/v2/user';
501
- DdRumResourceTracking.startTrackingInternal(XMLHttpRequestMock, {
535
+ xhrProxy.onTrackingStart({
502
536
  tracingSamplingRate: 100,
503
- firstPartyHosts: []
537
+ firstPartyHostsRegex: firstPartyHostsRegexBuilder([])
504
538
  });
505
539
 
506
540
  jest.doMock('react-native/Libraries/Utilities/Platform', () => ({
@@ -541,9 +575,9 @@ describe('DdRumResourceTracking', () => {
541
575
  // GIVEN
542
576
  const method = 'GET';
543
577
  const url = 'https://api.example.com/v2/user';
544
- DdRumResourceTracking.startTrackingInternal(XMLHttpRequestMock, {
578
+ xhrProxy.onTrackingStart({
545
579
  tracingSamplingRate: 100,
546
- firstPartyHosts: []
580
+ firstPartyHostsRegex: firstPartyHostsRegexBuilder([])
547
581
  });
548
582
 
549
583
  jest.doMock('react-native/Libraries/Utilities/Platform', () => ({
@@ -587,9 +621,9 @@ describe('DdRumResourceTracking', () => {
587
621
  // GIVEN
588
622
  const method = 'GET';
589
623
  const url = 'https://api.example.com/v2/user';
590
- DdRumResourceTracking.startTrackingInternal(XMLHttpRequestMock, {
624
+ xhrProxy.onTrackingStart({
591
625
  tracingSamplingRate: 100,
592
- firstPartyHosts: []
626
+ firstPartyHostsRegex: firstPartyHostsRegexBuilder([])
593
627
  });
594
628
 
595
629
  // WHEN
@@ -0,0 +1,83 @@
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 { InternalLog } from '../../../../InternalLog';
8
+ import { SdkVerbosity } from '../../../../SdkVerbosity';
9
+
10
+ const MISSING_RESOURCE_SIZE = -1;
11
+ export const RESOURCE_SIZE_ERROR_MESSAGE =
12
+ "Couldn't get resource size, because an error occured: ";
13
+
14
+ function byteLength(str: string): number {
15
+ // This is a weird trick, but it works.
16
+ // Output is the same as TextEncoder.encode(...).length
17
+ return unescape(encodeURI(str)).length;
18
+ }
19
+
20
+ function getResponseContentLengthFromHeader(
21
+ xhr: XMLHttpRequest
22
+ ): number | null {
23
+ const contentLengthHeader = parseInt(
24
+ xhr.getResponseHeader('Content-Length') ?? '',
25
+ 10
26
+ );
27
+ if (!isNaN(contentLengthHeader)) {
28
+ return contentLengthHeader;
29
+ }
30
+ return null;
31
+ }
32
+
33
+ export function calculateResponseSize(xhr: XMLHttpRequest): number {
34
+ const contentLengthHeader = getResponseContentLengthFromHeader(xhr);
35
+ if (contentLengthHeader != null) {
36
+ return contentLengthHeader as number;
37
+ }
38
+
39
+ const response = xhr.response;
40
+ if (!response) {
41
+ return MISSING_RESOURCE_SIZE;
42
+ }
43
+
44
+ let size;
45
+ try {
46
+ switch (xhr.responseType) {
47
+ case '':
48
+ case 'text':
49
+ // String
50
+ size = byteLength(response);
51
+ break;
52
+ case 'blob':
53
+ size = response.size;
54
+ break;
55
+ case 'arraybuffer':
56
+ size = response.byteLength;
57
+ break;
58
+ case 'document':
59
+ // currently not supported by RN as of 0.66
60
+ // HTML Document or XML Document
61
+ break;
62
+ case 'json':
63
+ // plain JS object
64
+ // original size was lost, because this is the object which was parsed.
65
+ // We can only convert back to the string and calculate the size,
66
+ // which will roughly match original.
67
+ size = byteLength(JSON.stringify(response));
68
+ break;
69
+ default:
70
+ break;
71
+ }
72
+ } catch (e) {
73
+ InternalLog.log(
74
+ `${RESOURCE_SIZE_ERROR_MESSAGE}${e}`,
75
+ SdkVerbosity.ERROR
76
+ );
77
+ }
78
+
79
+ if (typeof size !== 'number') {
80
+ return MISSING_RESOURCE_SIZE;
81
+ }
82
+ return size;
83
+ }
package/src/types.tsx CHANGED
@@ -143,13 +143,13 @@ export type DdRumType = {
143
143
 
144
144
  /**
145
145
  * Start tracking a RUM Action.
146
- * @param type: The action type (tap, scroll, swipe, click, custom).
146
+ * @param type: The action type (tap, scroll, swipe, back, custom).
147
147
  * @param name: The action name.
148
148
  * @param context: The additional context to send.
149
149
  * @param timestampMs: The timestamp when the action started (in milliseconds). If not provided, current timestamp will be used.
150
150
  */
151
151
  startAction(
152
- type: string,
152
+ type: RumActionType,
153
153
  name: string,
154
154
  context?: object,
155
155
  timestampMs?: number
@@ -157,6 +157,24 @@ export type DdRumType = {
157
157
 
158
158
  /**
159
159
  * Stop tracking the ongoing RUM Action.
160
+ * @param type: The action type (tap, scroll, swipe, back, custom).
161
+ * @param name: The action name.
162
+ * @param context: The additional context to send.
163
+ * @param timestampMs: The timestamp when the action stopped (in milliseconds). If not provided, current timestamp will be used.
164
+ */
165
+ stopAction(
166
+ type: RumActionType,
167
+ name: string,
168
+ context?: object,
169
+ timestampMs?: number
170
+ ): Promise<void>;
171
+
172
+ /**
173
+ * Stop tracking the ongoing RUM Action.
174
+ *
175
+ * Warning: using this function signature can lead to inconsistent behaviors on iOS and Android when multiple actions are started in parallel.
176
+ *
177
+ * @deprecated add the `type` and `name` of the action as first two arguments.
160
178
  * @param context: The additional context to send.
161
179
  * @param timestampMs: The timestamp when the action stopped (in milliseconds). If not provided, current timestamp will be used.
162
180
  */
@@ -164,13 +182,13 @@ export type DdRumType = {
164
182
 
165
183
  /**
166
184
  * Add a RUM Action.
167
- * @param type: The action type (tap, scroll, swipe, click, custom).
185
+ * @param type: The action type (tap, scroll, swipe, back, custom).
168
186
  * @param name: The action name.
169
187
  * @param context: The additional context to send.
170
188
  * @param timestampMs: The timestamp when the action occurred (in milliseconds). If not provided, current timestamp will be used.
171
189
  */
172
190
  addAction(
173
- type: string,
191
+ type: RumActionType,
174
192
  name: string,
175
193
  context?: object,
176
194
  timestampMs?: number
@@ -204,7 +222,7 @@ export type DdRumType = {
204
222
  stopResource(
205
223
  key: string,
206
224
  statusCode: number,
207
- kind: string,
225
+ kind: ResourceKind,
208
226
  size?: number,
209
227
  context?: object,
210
228
  timestampMs?: number
@@ -213,14 +231,14 @@ export type DdRumType = {
213
231
  /**
214
232
  * Add a RUM Error.
215
233
  * @param message: The error message.
216
- * @param source: The error source (network, source, console, logger, …).
234
+ * @param source: The error source (network, source, console, webview, custom).
217
235
  * @param stacktrace: The error stacktrace.
218
236
  * @param context: The additional context to send.
219
237
  * @param timestampMs: The timestamp when the error occurred (in milliseconds). If not provided, current timestamp will be used.
220
238
  */
221
239
  addError(
222
240
  message: string,
223
- source: string,
241
+ source: ErrorSource,
224
242
  stacktrace: string,
225
243
  context?: object,
226
244
  timestampMs?: number
@@ -232,3 +250,40 @@ export type DdRumType = {
232
250
  */
233
251
  addTiming(name: string): Promise<void>;
234
252
  };
253
+
254
+ /**
255
+ * Describe the type of a RUM Action.
256
+ */
257
+ export enum RumActionType {
258
+ /** User tapped on a widget. */
259
+ TAP = 'TAP',
260
+ /** User scrolled a view. */
261
+ SCROLL = 'SCROLL',
262
+ /** User swiped on a view. */
263
+ SWIPE = 'SWIPE',
264
+ /** User pressed hardware back button (Android only). */
265
+ BACK = 'BACK',
266
+ /** A custom action. */
267
+ CUSTOM = 'CUSTOM'
268
+ }
269
+
270
+ export type ResourceKind =
271
+ | 'image'
272
+ | 'xhr'
273
+ | 'beacon'
274
+ | 'css'
275
+ | 'document'
276
+ | 'fetch'
277
+ | 'font'
278
+ | 'js'
279
+ | 'media'
280
+ | 'other'
281
+ | 'native';
282
+
283
+ export enum ErrorSource {
284
+ NETWORK = 'NETWORK',
285
+ SOURCE = 'SOURCE',
286
+ CONSOLE = 'CONSOLE',
287
+ WEBVIEW = 'WEBVIEW',
288
+ CUSTOM = 'CUSTOM'
289
+ }
package/src/version.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  // generated by genversion
2
- export const version = '1.0.0-rc8';
2
+ export const version = '1.1.0';
@@ -1,142 +0,0 @@
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
- package com.datadog.reactnative
8
-
9
- import com.datadog.android.bridge.DdBridge
10
- import com.datadog.android.bridge.DdRum as SDKDdRum
11
- import com.facebook.react.bridge.Promise
12
- import com.facebook.react.bridge.ReactApplicationContext
13
- import com.facebook.react.bridge.ReactContextBaseJavaModule
14
- import com.facebook.react.bridge.ReactMethod
15
- import com.facebook.react.bridge.ReadableArray
16
- import com.facebook.react.bridge.ReadableMap
17
-
18
- /**
19
- * The entry point to use Datadog's RUM feature.
20
- */
21
- class DdRum(reactContext: ReactApplicationContext) : ReactContextBaseJavaModule(reactContext) {
22
-
23
- private val nativeInstance: SDKDdRum = DdBridge.getDdRum(reactContext)
24
-
25
- override fun getName(): String = "DdRum"
26
-
27
- /**
28
- * Start tracking a RUM View.
29
- * @param key The view unique key identifier.
30
- * @param name The view name.
31
- * @param context The additional context to send.
32
- * @param timestampMs The timestamp when the view started (in milliseconds). If not provided, current timestamp will be used.
33
- */
34
- @ReactMethod
35
- fun startView(key: String, name: String, context: ReadableMap, timestampMs: Double, promise: Promise) {
36
- nativeInstance.startView(key, name, context.toHashMap(), timestampMs.toLong())
37
- promise.resolve(null)
38
- }
39
-
40
- /**
41
- * Stop tracking a RUM View.
42
- * @param key The view unique key identifier.
43
- * @param context The additional context to send.
44
- * @param timestampMs The timestamp when the view stopped (in milliseconds). If not provided, current timestamp will be used.
45
- */
46
- @ReactMethod
47
- fun stopView(key: String, context: ReadableMap, timestampMs: Double, promise: Promise) {
48
- nativeInstance.stopView(key, context.toHashMap(), timestampMs.toLong())
49
- promise.resolve(null)
50
- }
51
-
52
- /**
53
- * Start tracking a RUM Action.
54
- * @param type The action type (tap, scroll, swipe, click, custom).
55
- * @param name The action name.
56
- * @param context The additional context to send.
57
- * @param timestampMs The timestamp when the action started (in milliseconds). If not provided, current timestamp will be used.
58
- */
59
- @ReactMethod
60
- fun startAction(type: String, name: String, context: ReadableMap, timestampMs: Double, promise: Promise) {
61
- nativeInstance.startAction(type, name, context.toHashMap(), timestampMs.toLong())
62
- promise.resolve(null)
63
- }
64
-
65
- /**
66
- * Stop tracking the ongoing RUM Action.
67
- * @param context The additional context to send.
68
- * @param timestampMs The timestamp when the action stopped (in milliseconds). If not provided, current timestamp will be used.
69
- */
70
- @ReactMethod
71
- fun stopAction(context: ReadableMap, timestampMs: Double, promise: Promise) {
72
- nativeInstance.stopAction(context.toHashMap(), timestampMs.toLong())
73
- promise.resolve(null)
74
- }
75
-
76
- /**
77
- * Add a RUM Action.
78
- * @param type The action type (tap, scroll, swipe, click, custom).
79
- * @param name The action name.
80
- * @param context The additional context to send.
81
- * @param timestampMs The timestamp when the action occurred (in milliseconds). If not provided, current timestamp will be used.
82
- */
83
- @ReactMethod
84
- fun addAction(type: String, name: String, context: ReadableMap, timestampMs: Double, promise: Promise) {
85
- nativeInstance.addAction(type, name, context.toHashMap(), timestampMs.toLong())
86
- promise.resolve(null)
87
- }
88
-
89
- /**
90
- * Start tracking a RUM Resource.
91
- * @param key The resource unique key identifier.
92
- * @param method The resource method (GET, POST, …).
93
- * @param url The resource url.
94
- * @param context The additional context to send.
95
- * @param timestampMs The timestamp when the resource started (in milliseconds). If not provided, current timestamp will be used.
96
- */
97
- @ReactMethod
98
- fun startResource(key: String, method: String, url: String, context: ReadableMap, timestampMs: Double, promise: Promise) {
99
- nativeInstance.startResource(key, method, url, context.toHashMap(), timestampMs.toLong())
100
- promise.resolve(null)
101
- }
102
-
103
- /**
104
- * Stop tracking a RUM Resource.
105
- * @param key The resource unique key identifier.
106
- * @param statusCode The resource status code.
107
- * @param kind The resource's kind (xhr, document, image, css, font, …).
108
- * @param size The resource size in bytes.
109
- * @param context The additional context to send.
110
- * @param timestampMs The timestamp when the resource stopped (in milliseconds). If not provided, current timestamp will be used.
111
- */
112
- @ReactMethod
113
- fun stopResource(key: String, statusCode: Double, kind: String, size: Double, context: ReadableMap, timestampMs: Double, promise: Promise) {
114
- nativeInstance.stopResource(key, statusCode.toLong(), kind, size.toLong(), context.toHashMap(), timestampMs.toLong())
115
- promise.resolve(null)
116
- }
117
-
118
- /**
119
- * Add a RUM Error.
120
- * @param message The error message.
121
- * @param source The error source (network, source, console, logger, …).
122
- * @param stacktrace The error stacktrace.
123
- * @param context The additional context to send.
124
- * @param timestampMs The timestamp when the error occurred (in milliseconds). If not provided, current timestamp will be used.
125
- */
126
- @ReactMethod
127
- fun addError(message: String, source: String, stacktrace: String, context: ReadableMap, timestampMs: Double, promise: Promise) {
128
- nativeInstance.addError(message, source, stacktrace, context.toHashMap(), timestampMs.toLong())
129
- promise.resolve(null)
130
- }
131
-
132
- /**
133
- * Adds a specific timing in the active View. The timing duration will be computed as the difference between the time the View was started and the time this function was called.
134
- * @param name The name of the new custom timing attribute. Timings can be nested up to 8 levels deep. Names using more than 8 levels will be sanitized by SDK.
135
- */
136
- @ReactMethod
137
- fun addTiming(name: String, promise: Promise) {
138
- nativeInstance.addTiming(name)
139
- promise.resolve(null)
140
- }
141
-
142
- }