@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
@@ -1,67 +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.DdSdk as SDKDdSdk
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 initialize Datadog's features.
20
- */
21
- class DdSdk(reactContext: ReactApplicationContext) : ReactContextBaseJavaModule(reactContext) {
22
-
23
- private val nativeInstance: SDKDdSdk = DdBridge.getDdSdk(reactContext)
24
-
25
- override fun getName(): String = "DdSdk"
26
-
27
- /**
28
- * Initializes Datadog's features.
29
- * @param configuration The configuration to use.
30
- */
31
- @ReactMethod
32
- fun initialize(configuration: ReadableMap, promise: Promise) {
33
- nativeInstance.initialize(configuration.asDdSdkConfiguration())
34
- promise.resolve(null)
35
- }
36
-
37
- /**
38
- * Sets the global context (set of attributes) attached with all future Logs, Spans and RUM events.
39
- * @param attributes The global context attributes.
40
- */
41
- @ReactMethod
42
- fun setAttributes(attributes: ReadableMap, promise: Promise) {
43
- nativeInstance.setAttributes(attributes.toHashMap())
44
- promise.resolve(null)
45
- }
46
-
47
- /**
48
- * Set the user information.
49
- * @param user The user object (use builtin attributes: 'id', 'email', 'name', and/or any custom attribute).
50
- */
51
- @ReactMethod
52
- fun setUser(user: ReadableMap, promise: Promise) {
53
- nativeInstance.setUser(user.toHashMap())
54
- promise.resolve(null)
55
- }
56
-
57
- /**
58
- * Set the tracking consent regarding the data collection.
59
- * @param trackingConsent Consent, which can take one of the following values: 'pending', 'granted', 'not_granted'.
60
- */
61
- @ReactMethod
62
- fun setTrackingConsent(trackingConsent: String, promise: Promise) {
63
- nativeInstance.setTrackingConsent(trackingConsent)
64
- promise.resolve(null)
65
- }
66
-
67
- }
@@ -1,51 +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.DdTrace as SDKDdTrace
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 Trace feature.
20
- */
21
- class DdTrace(reactContext: ReactApplicationContext) : ReactContextBaseJavaModule(reactContext) {
22
-
23
- private val nativeInstance: SDKDdTrace = DdBridge.getDdTrace(reactContext)
24
-
25
- override fun getName(): String = "DdTrace"
26
-
27
- /**
28
- * Start a span, and returns a unique identifier for the span.
29
- * @param operation The operation name of the span.
30
- * @param context The additional context to send.
31
- * @param timestampMs The timestamp when the operation started (in milliseconds). If not provided, current timestamp will be used.
32
- */
33
- @ReactMethod
34
- fun startSpan(operation: String, context: ReadableMap, timestampMs: Double, promise: Promise) {
35
- val result = nativeInstance.startSpan(operation, context.toHashMap(), timestampMs.toLong())
36
- promise.resolve(result)
37
- }
38
-
39
- /**
40
- * Finish a started span.
41
- * @param spanId The unique identifier of the span.
42
- * @param context The additional context to send.
43
- * @param timestampMs The timestamp when the operation stopped (in milliseconds). If not provided, current timestamp will be used.
44
- */
45
- @ReactMethod
46
- fun finishSpan(spanId: String, context: ReadableMap, timestampMs: Double, promise: Promise) {
47
- nativeInstance.finishSpan(spanId, context.toHashMap(), timestampMs.toLong())
48
- promise.resolve(null)
49
- }
50
-
51
- }
@@ -1,356 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.calculateResponseSize = calculateResponseSize;
7
- exports.DdRumResourceTracking = exports.RESOURCE_SIZE_ERROR_MESSAGE = exports.ORIGIN_RUM = exports.SAMPLING_PRIORITY_HEADER_KEY = exports.ORIGIN_HEADER_KEY = exports.PARENT_ID_HEADER_KEY = exports.TRACE_ID_HEADER_KEY = void 0;
8
-
9
- var _reactNative = require("react-native");
10
-
11
- var _InternalLog = require("../../InternalLog");
12
-
13
- var _SdkVerbosity = require("../../SdkVerbosity");
14
-
15
- var _Timer = _interopRequireDefault(require("../../Timer"));
16
-
17
- var _foundation = require("../../foundation");
18
-
19
- var _TraceIdentifier = require("./TraceIdentifier");
20
-
21
- var _URLHostParser = require("./URLHostParser");
22
-
23
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
24
-
25
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
26
-
27
- const TRACE_ID_HEADER_KEY = 'x-datadog-trace-id';
28
- exports.TRACE_ID_HEADER_KEY = TRACE_ID_HEADER_KEY;
29
- const PARENT_ID_HEADER_KEY = 'x-datadog-parent-id';
30
- exports.PARENT_ID_HEADER_KEY = PARENT_ID_HEADER_KEY;
31
- const ORIGIN_HEADER_KEY = 'x-datadog-origin';
32
- exports.ORIGIN_HEADER_KEY = ORIGIN_HEADER_KEY;
33
- const SAMPLING_PRIORITY_HEADER_KEY = 'x-datadog-sampling-priority';
34
- exports.SAMPLING_PRIORITY_HEADER_KEY = SAMPLING_PRIORITY_HEADER_KEY;
35
- const ORIGIN_RUM = 'rum';
36
- exports.ORIGIN_RUM = ORIGIN_RUM;
37
- const RESOURCE_SIZE_ERROR_MESSAGE = "Couldn't get resource size, because an error occured: ";
38
- exports.RESOURCE_SIZE_ERROR_MESSAGE = RESOURCE_SIZE_ERROR_MESSAGE;
39
- const RESPONSE_START_LABEL = 'response_start';
40
- const MISSING_RESOURCE_SIZE = -1; // This regex does not match anything
41
-
42
- const NO_MATCH_REGEX = new RegExp('a^');
43
-
44
- function createTimings(startTime, responseStartTime, responseEndTime) {
45
- const firstByte = formatTiming(startTime, startTime, responseStartTime);
46
- const download = formatTiming(startTime, responseStartTime, responseEndTime); // needed for iOS, simply total duration from start to end
47
-
48
- const fetch = formatTiming(startTime, startTime, responseEndTime);
49
- return {
50
- firstByte,
51
- download,
52
- fetch
53
- };
54
- }
55
- /**
56
- * @param origin Start time (absolute) of the request
57
- * @param start Start time (absolute) of the timing
58
- * @param end End time (absolute) of the timing
59
- */
60
-
61
-
62
- function formatTiming(origin, start, end) {
63
- return {
64
- duration: timeToNanos(end - start),
65
- // if it is Android, startTime should be relative to the origin,
66
- // if it is iOS - absolute (unix timestamp)
67
- startTime: _reactNative.Platform.OS === 'ios' ? timeToNanos(start) : timeToNanos(start - origin)
68
- };
69
- }
70
-
71
- function timeToNanos(durationMs) {
72
- return +(durationMs * 1e6).toFixed(0);
73
- }
74
-
75
- function byteLength(str) {
76
- // This is a weird trick, but it works.
77
- // Output is the same as TextEncoder.encode(...).length
78
- return unescape(encodeURI(str)).length;
79
- }
80
-
81
- function getResponseContentLengthFromHeader(xhr) {
82
- var _xhr$getResponseHeade;
83
-
84
- const contentLengthHeader = parseInt((_xhr$getResponseHeade = xhr.getResponseHeader('Content-Length')) !== null && _xhr$getResponseHeade !== void 0 ? _xhr$getResponseHeade : '', 10);
85
-
86
- if (!isNaN(contentLengthHeader)) {
87
- return contentLengthHeader;
88
- }
89
-
90
- return null;
91
- }
92
-
93
- function calculateResponseSize(xhr) {
94
- const contentLengthHeader = getResponseContentLengthFromHeader(xhr);
95
-
96
- if (contentLengthHeader != null) {
97
- return contentLengthHeader;
98
- }
99
-
100
- const response = xhr.response;
101
-
102
- if (!response) {
103
- return MISSING_RESOURCE_SIZE;
104
- }
105
-
106
- let size;
107
-
108
- try {
109
- switch (xhr.responseType) {
110
- case '':
111
- case 'text':
112
- // String
113
- size = byteLength(response);
114
- break;
115
-
116
- case 'blob':
117
- size = response.size;
118
- break;
119
-
120
- case 'arraybuffer':
121
- size = response.byteLength;
122
- break;
123
-
124
- case 'document':
125
- // currently not supported by RN as of 0.66
126
- // HTML Document or XML Document
127
- break;
128
-
129
- case 'json':
130
- // plain JS object
131
- // original size was lost, because this is the object which was parsed.
132
- // We can only convert back to the string and calculate the size,
133
- // which will roughly match original.
134
- size = byteLength(JSON.stringify(response));
135
- break;
136
-
137
- default:
138
- break;
139
- }
140
- } catch (e) {
141
- _InternalLog.InternalLog.log(`${RESOURCE_SIZE_ERROR_MESSAGE}${e}`, _SdkVerbosity.SdkVerbosity.ERROR);
142
- }
143
-
144
- if (typeof size !== 'number') {
145
- return MISSING_RESOURCE_SIZE;
146
- }
147
-
148
- return size;
149
- }
150
-
151
- const generateTracingAttributesWithSampling = tracingSamplingRate => {
152
- if (Math.random() * 100 <= tracingSamplingRate) {
153
- return {
154
- traceId: (0, _TraceIdentifier.generateTraceId)(),
155
- spanId: (0, _TraceIdentifier.generateTraceId)(),
156
- samplingPriorityHeader: '1',
157
- tracingStrategy: 'KEEP'
158
- };
159
- }
160
-
161
- return {
162
- samplingPriorityHeader: '0',
163
- tracingStrategy: 'DISCARD'
164
- };
165
- };
166
-
167
- const getFirstPartyHostsRegex = firstPartyHosts => {
168
- if (firstPartyHosts.length === 0) {
169
- return NO_MATCH_REGEX;
170
- }
171
-
172
- try {
173
- // A regexp for matching hosts, e.g. when `hosts` is "example.com", it will match
174
- // "example.com", "api.example.com", but not "foo.com".
175
- const firstPartyHostsRegex = new RegExp(`^(.*\\.)*(${firstPartyHosts.map(host => `${host}$`).join('|')})`);
176
- firstPartyHostsRegex.test('test_the_regex_is_valid');
177
- return firstPartyHostsRegex;
178
- } catch (e) {
179
- _InternalLog.InternalLog.log(`Invalid first party hosts list ${JSON.stringify(firstPartyHosts)}. Regular expressions are not allowed.`, _SdkVerbosity.SdkVerbosity.WARN);
180
-
181
- return NO_MATCH_REGEX;
182
- }
183
- };
184
- /**
185
- * Provides RUM auto-instrumentation feature to track resources (fetch, XHR, axios) as RUM events.
186
- */
187
-
188
-
189
- class DdRumResourceTracking {
190
- // matches nothing by default
191
-
192
- /**
193
- * Starts tracking resources and sends a RUM Resource event every time a network request is detected.
194
- */
195
- static startTracking({
196
- tracingSamplingRate,
197
- firstPartyHosts
198
- }) {
199
- DdRumResourceTracking.startTrackingInternal(XMLHttpRequest, {
200
- tracingSamplingRate,
201
- firstPartyHosts
202
- });
203
- }
204
- /**
205
- * Starts tracking resources and sends a RUM Resource event every time a fetch or XHR call is detected.
206
- */
207
-
208
-
209
- static startTrackingInternal(xhrType, {
210
- tracingSamplingRate,
211
- firstPartyHosts
212
- }) {
213
- // extra safety to avoid proxying the XHR class twice
214
- if (DdRumResourceTracking.isTracking) {
215
- _InternalLog.InternalLog.log('Datadog SDK is already tracking XHR resources', _SdkVerbosity.SdkVerbosity.WARN);
216
-
217
- return;
218
- }
219
-
220
- DdRumResourceTracking.tracingSamplingRate = tracingSamplingRate;
221
- DdRumResourceTracking.firstPartyHostsRegex = getFirstPartyHostsRegex(firstPartyHosts);
222
- DdRumResourceTracking.originalXhrOpen = xhrType.prototype.open;
223
- DdRumResourceTracking.originalXhrSend = xhrType.prototype.send;
224
- DdRumResourceTracking.proxyXhr(xhrType);
225
-
226
- _InternalLog.InternalLog.log('Datadog SDK is tracking XHR resources', _SdkVerbosity.SdkVerbosity.INFO);
227
- }
228
-
229
- static stopTracking() {
230
- if (DdRumResourceTracking.isTracking) {
231
- DdRumResourceTracking.isTracking = false;
232
- XMLHttpRequest.prototype.open = DdRumResourceTracking.originalXhrOpen;
233
- XMLHttpRequest.prototype.send = DdRumResourceTracking.originalXhrSend;
234
- }
235
- }
236
-
237
- static getTracingAttributes(url) {
238
- try {
239
- const hostname = (0, _URLHostParser.URLHostParser)(url);
240
-
241
- if (DdRumResourceTracking.firstPartyHostsRegex.test(hostname)) {
242
- return generateTracingAttributesWithSampling(DdRumResourceTracking.tracingSamplingRate);
243
- }
244
-
245
- return {
246
- samplingPriorityHeader: '0',
247
- tracingStrategy: 'DISCARD'
248
- };
249
- } catch (e) {
250
- _InternalLog.InternalLog.log(`Impossible to cast ${url} as URL`, _SdkVerbosity.SdkVerbosity.WARN);
251
-
252
- return {
253
- samplingPriorityHeader: '0',
254
- tracingStrategy: 'DISCARD'
255
- };
256
- }
257
- } // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
258
-
259
-
260
- static proxyXhr(xhrType) {
261
- this.proxyOpen(xhrType);
262
- this.proxySend(xhrType);
263
- }
264
-
265
- static proxyOpen(xhrType) {
266
- const originalXhrOpen = this.originalXhrOpen;
267
-
268
- xhrType.prototype.open = function (method, url) {
269
- // Keep track of the method and url
270
- // start time is tracked by the `send` method
271
- this._datadog_xhr = {
272
- method,
273
- url,
274
- reported: false,
275
- timer: new _Timer.default(),
276
- tracingAttributes: DdRumResourceTracking.getTracingAttributes(url)
277
- }; // eslint-disable-next-line prefer-rest-params
278
-
279
- return originalXhrOpen.apply(this, arguments);
280
- };
281
- }
282
-
283
- static proxySend(xhrType) {
284
- const originalXhrSend = this.originalXhrSend;
285
-
286
- xhrType.prototype.send = function () {
287
- if (this._datadog_xhr) {
288
- // keep track of start time
289
- this._datadog_xhr.timer.start();
290
-
291
- this.setRequestHeader(ORIGIN_HEADER_KEY, ORIGIN_RUM);
292
- const tracingAttributes = this._datadog_xhr.tracingAttributes;
293
- this.setRequestHeader(SAMPLING_PRIORITY_HEADER_KEY, tracingAttributes.samplingPriorityHeader);
294
-
295
- if (tracingAttributes.tracingStrategy !== 'DISCARD') {
296
- this.setRequestHeader(TRACE_ID_HEADER_KEY, tracingAttributes.traceId);
297
- this.setRequestHeader(PARENT_ID_HEADER_KEY, tracingAttributes.spanId);
298
- }
299
- }
300
-
301
- DdRumResourceTracking.proxyOnReadyStateChange(this, xhrType); // eslint-disable-next-line prefer-rest-params
302
-
303
- return originalXhrSend.apply(this, arguments);
304
- };
305
- }
306
-
307
- static proxyOnReadyStateChange(xhrProxy, xhrType) {
308
- const originalOnreadystatechange = xhrProxy.onreadystatechange;
309
-
310
- xhrProxy.onreadystatechange = function () {
311
- if (xhrProxy.readyState === xhrType.DONE) {
312
- if (!xhrProxy._datadog_xhr.reported) {
313
- DdRumResourceTracking.reportXhr(xhrProxy);
314
- xhrProxy._datadog_xhr.reported = true;
315
- }
316
- } else if (xhrProxy.readyState === xhrType.HEADERS_RECEIVED) {
317
- xhrProxy._datadog_xhr.timer.recordTick(RESPONSE_START_LABEL);
318
- }
319
-
320
- if (originalOnreadystatechange) {
321
- // eslint-disable-next-line prefer-rest-params
322
- originalOnreadystatechange.apply(xhrProxy, arguments);
323
- }
324
- };
325
- }
326
-
327
- static reportXhr(xhrProxy) {
328
- const responseSize = calculateResponseSize(xhrProxy);
329
- const context = xhrProxy._datadog_xhr;
330
- const key = `${context.timer.startTime}/${context.method}`;
331
- context.timer.stop();
332
-
333
- _foundation.DdRum.startResource(key, context.method, context.url, context.tracingAttributes.tracingStrategy === 'DISCARD' ? undefined : {
334
- '_dd.span_id': context.tracingAttributes.spanId,
335
- '_dd.trace_id': context.tracingAttributes.traceId
336
- }, context.timer.startTime).then(() => {
337
- _foundation.DdRum.stopResource(key, xhrProxy.status, 'xhr', responseSize, {
338
- '_dd.resource_timings': context.timer.hasTickFor(RESPONSE_START_LABEL) ? createTimings(context.timer.startTime, context.timer.timeAt(RESPONSE_START_LABEL), context.timer.stopTime) : null
339
- }, context.timer.stopTime);
340
- });
341
- }
342
-
343
- }
344
-
345
- exports.DdRumResourceTracking = DdRumResourceTracking;
346
-
347
- _defineProperty(DdRumResourceTracking, "isTracking", false);
348
-
349
- _defineProperty(DdRumResourceTracking, "tracingSamplingRate", void 0);
350
-
351
- _defineProperty(DdRumResourceTracking, "firstPartyHostsRegex", NO_MATCH_REGEX);
352
-
353
- _defineProperty(DdRumResourceTracking, "originalXhrOpen", void 0);
354
-
355
- _defineProperty(DdRumResourceTracking, "originalXhrSend", void 0);
356
- //# sourceMappingURL=DdRumResourceTracking.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["DdRumResourceTracking.tsx"],"names":["TRACE_ID_HEADER_KEY","PARENT_ID_HEADER_KEY","ORIGIN_HEADER_KEY","SAMPLING_PRIORITY_HEADER_KEY","ORIGIN_RUM","RESOURCE_SIZE_ERROR_MESSAGE","RESPONSE_START_LABEL","MISSING_RESOURCE_SIZE","NO_MATCH_REGEX","RegExp","createTimings","startTime","responseStartTime","responseEndTime","firstByte","formatTiming","download","fetch","origin","start","end","duration","timeToNanos","Platform","OS","durationMs","toFixed","byteLength","str","unescape","encodeURI","length","getResponseContentLengthFromHeader","xhr","contentLengthHeader","parseInt","getResponseHeader","isNaN","calculateResponseSize","response","size","responseType","JSON","stringify","e","InternalLog","log","SdkVerbosity","ERROR","generateTracingAttributesWithSampling","tracingSamplingRate","Math","random","traceId","spanId","samplingPriorityHeader","tracingStrategy","getFirstPartyHostsRegex","firstPartyHosts","firstPartyHostsRegex","map","host","join","test","WARN","DdRumResourceTracking","startTracking","startTrackingInternal","XMLHttpRequest","xhrType","isTracking","originalXhrOpen","prototype","open","originalXhrSend","send","proxyXhr","INFO","stopTracking","getTracingAttributes","url","hostname","proxyOpen","proxySend","method","_datadog_xhr","reported","timer","Timer","tracingAttributes","apply","arguments","setRequestHeader","proxyOnReadyStateChange","xhrProxy","originalOnreadystatechange","onreadystatechange","readyState","DONE","reportXhr","HEADERS_RECEIVED","recordTick","responseSize","context","key","stop","DdRum","startResource","undefined","then","stopResource","status","hasTickFor","timeAt","stopTime"],"mappings":";;;;;;;;AAMA;;AAEA;;AACA;;AACA;;AACA;;AAGA;;AACA;;;;;;AAEO,MAAMA,mBAAmB,GAAG,oBAA5B;;AACA,MAAMC,oBAAoB,GAAG,qBAA7B;;AACA,MAAMC,iBAAiB,GAAG,kBAA1B;;AACA,MAAMC,4BAA4B,GAAG,6BAArC;;AACA,MAAMC,UAAU,GAAG,KAAnB;;AACA,MAAMC,2BAA2B,GACpC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I,GAAED,OAAO,CAAChB,KAAR,CAAc5E,SAAU,IAAG4F,OAAO,CAACnB,MAAO,EAAzD;AAEAmB,IAAAA,OAAO,CAAChB,KAAR,CAAckB,IAAd;;AAEAC,sBAAMC,aAAN,CACIH,GADJ,EAEID,OAAO,CAACnB,MAFZ,EAGImB,OAAO,CAACvB,GAHZ,EAIIuB,OAAO,CAACd,iBAAR,CAA0BjC,eAA1B,KAA8C,SAA9C,GACMoD,SADN,GAEM;AACI,qBAAeL,OAAO,CAACd,iBAAR,CAA0BnC,MAD7C;AAEI,sBAAgBiD,OAAO,CAACd,iBAAR,CAA0BpC;AAF9C,KANV,EAUIkD,OAAO,CAAChB,KAAR,CAAc5E,SAVlB,EAWEkG,IAXF,CAWO,MAAM;AACTH,wBAAMI,YAAN,CACIN,GADJ,EAEIV,QAAQ,CAACiB,MAFb,EAGI,KAHJ,EAIIT,YAJJ,EAKI;AACI,gCAAwBC,OAAO,CAAChB,KAAR,CAAcyB,UAAd,CACpB1G,oBADoB,IAGlBI,aAAa,CACT6F,OAAO,CAAChB,KAAR,CAAc5E,SADL,EAET4F,OAAO,CAAChB,KAAR,CAAc0B,MAAd,CAAqB3G,oBAArB,CAFS,EAGTiG,OAAO,CAAChB,KAAR,CAAc2B,QAHL,CAHK,GAQlB;AATV,OALJ,EAgBIX,OAAO,CAAChB,KAAR,CAAc2B,QAhBlB;AAkBH,KA9BD;AA+BH;;AAxN8B;;;;gBAAtBjD,qB,gBACmB,K;;gBADnBA,qB;;gBAAAA,qB,0BAGqCzD,c;;gBAHrCyD,qB;;gBAAAA,qB","sourcesContent":["/*\n * Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.\n * This product includes software developed at Datadog (https://www.datadoghq.com/).\n * Copyright 2016-Present Datadog, Inc.\n */\n\nimport { Platform } from 'react-native';\n\nimport { InternalLog } from '../../InternalLog';\nimport { SdkVerbosity } from '../../SdkVerbosity';\nimport Timer from '../../Timer';\nimport { DdRum } from '../../foundation';\n\nimport type { DdRumResourceTracingAttributes, DdRumXhr } from './DdRumXhr';\nimport { generateTraceId } from './TraceIdentifier';\nimport { URLHostParser } from './URLHostParser';\n\nexport const TRACE_ID_HEADER_KEY = 'x-datadog-trace-id';\nexport const PARENT_ID_HEADER_KEY = 'x-datadog-parent-id';\nexport const ORIGIN_HEADER_KEY = 'x-datadog-origin';\nexport const SAMPLING_PRIORITY_HEADER_KEY = 'x-datadog-sampling-priority';\nexport const ORIGIN_RUM = 'rum';\nexport const RESOURCE_SIZE_ERROR_MESSAGE =\n \"Couldn't get resource size, because an error occured: \";\n\nconst RESPONSE_START_LABEL = 'response_start';\nconst MISSING_RESOURCE_SIZE = -1;\n\n// This regex does not match anything\nconst NO_MATCH_REGEX = new RegExp('a^');\n\ninterface Timing {\n /**\n * Time relative (absolute in case of iOS) to some point, in ns.\n */\n startTime: number;\n /**\n * Duration in ns.\n */\n duration: number;\n}\n\ninterface ResourceTimings {\n // unlike in Performance API it is not the time until request\n // starts (requestStart, before it can be connect, SSL, DNS),\n // but the time until the response is first seen\n firstByte: Timing;\n download: Timing;\n // required by iOS, total timing from the beginning to the end\n fetch: Timing;\n}\n\nfunction createTimings(\n startTime: number,\n responseStartTime: number,\n responseEndTime: number\n): ResourceTimings {\n const firstByte = formatTiming(startTime, startTime, responseStartTime);\n const download = formatTiming(\n startTime,\n responseStartTime,\n responseEndTime\n );\n // needed for iOS, simply total duration from start to end\n const fetch = formatTiming(startTime, startTime, responseEndTime);\n\n return {\n firstByte,\n download,\n fetch\n };\n}\n\n/**\n * @param origin Start time (absolute) of the request\n * @param start Start time (absolute) of the timing\n * @param end End time (absolute) of the timing\n */\nfunction formatTiming(origin: number, start: number, end: number): Timing {\n return {\n duration: timeToNanos(end - start),\n // if it is Android, startTime should be relative to the origin,\n // if it is iOS - absolute (unix timestamp)\n startTime:\n Platform.OS === 'ios'\n ? timeToNanos(start)\n : timeToNanos(start - origin)\n };\n}\n\nfunction timeToNanos(durationMs: number): number {\n return +(durationMs * 1e6).toFixed(0);\n}\n\nfunction byteLength(str: string): number {\n // This is a weird trick, but it works.\n // Output is the same as TextEncoder.encode(...).length\n return unescape(encodeURI(str)).length;\n}\n\nfunction getResponseContentLengthFromHeader(\n xhr: XMLHttpRequest\n): number | null {\n const contentLengthHeader = parseInt(\n xhr.getResponseHeader('Content-Length') ?? '',\n 10\n );\n if (!isNaN(contentLengthHeader)) {\n return contentLengthHeader;\n }\n return null;\n}\n\nexport function calculateResponseSize(xhr: XMLHttpRequest): number {\n const contentLengthHeader = getResponseContentLengthFromHeader(xhr);\n if (contentLengthHeader != null) {\n return contentLengthHeader as number;\n }\n\n const response = xhr.response;\n if (!response) {\n return MISSING_RESOURCE_SIZE;\n }\n\n let size;\n try {\n switch (xhr.responseType) {\n case '':\n case 'text':\n // String\n size = byteLength(response);\n break;\n case 'blob':\n size = response.size;\n break;\n case 'arraybuffer':\n size = response.byteLength;\n break;\n case 'document':\n // currently not supported by RN as of 0.66\n // HTML Document or XML Document\n break;\n case 'json':\n // plain JS object\n // original size was lost, because this is the object which was parsed.\n // We can only convert back to the string and calculate the size,\n // which will roughly match original.\n size = byteLength(JSON.stringify(response));\n break;\n default:\n break;\n }\n } catch (e) {\n InternalLog.log(\n `${RESOURCE_SIZE_ERROR_MESSAGE}${e}`,\n SdkVerbosity.ERROR\n );\n }\n\n if (typeof size !== 'number') {\n return MISSING_RESOURCE_SIZE;\n }\n return size;\n}\n\nconst generateTracingAttributesWithSampling = (\n tracingSamplingRate: number\n): DdRumResourceTracingAttributes => {\n if (Math.random() * 100 <= tracingSamplingRate) {\n return {\n traceId: generateTraceId(),\n spanId: generateTraceId(),\n samplingPriorityHeader: '1',\n tracingStrategy: 'KEEP'\n };\n }\n return {\n samplingPriorityHeader: '0',\n tracingStrategy: 'DISCARD'\n };\n};\n\nconst getFirstPartyHostsRegex = (firstPartyHosts: string[]): RegExp => {\n if (firstPartyHosts.length === 0) {\n return NO_MATCH_REGEX;\n }\n try {\n // A regexp for matching hosts, e.g. when `hosts` is \"example.com\", it will match\n // \"example.com\", \"api.example.com\", but not \"foo.com\".\n const firstPartyHostsRegex = new RegExp(\n `^(.*\\\\.)*(${firstPartyHosts.map(host => `${host}$`).join('|')})`\n );\n firstPartyHostsRegex.test('test_the_regex_is_valid');\n return firstPartyHostsRegex;\n } catch (e) {\n InternalLog.log(\n `Invalid first party hosts list ${JSON.stringify(\n firstPartyHosts\n )}. Regular expressions are not allowed.`,\n SdkVerbosity.WARN\n );\n return NO_MATCH_REGEX;\n }\n};\n\n/**\n * Provides RUM auto-instrumentation feature to track resources (fetch, XHR, axios) as RUM events.\n */\nexport class DdRumResourceTracking {\n private static isTracking = false;\n private static tracingSamplingRate: number;\n private static firstPartyHostsRegex: RegExp = NO_MATCH_REGEX; // matches nothing by default\n\n private static originalXhrOpen: any;\n private static originalXhrSend: any;\n\n /**\n * Starts tracking resources and sends a RUM Resource event every time a network request is detected.\n */\n static startTracking({\n tracingSamplingRate,\n firstPartyHosts\n }: {\n tracingSamplingRate: number;\n firstPartyHosts: string[];\n }): void {\n DdRumResourceTracking.startTrackingInternal(XMLHttpRequest, {\n tracingSamplingRate,\n firstPartyHosts\n });\n }\n\n /**\n * Starts tracking resources and sends a RUM Resource event every time a fetch or XHR call is detected.\n */\n static startTrackingInternal(\n xhrType: typeof XMLHttpRequest,\n {\n tracingSamplingRate,\n firstPartyHosts\n }: { tracingSamplingRate: number; firstPartyHosts: string[] }\n ): void {\n // extra safety to avoid proxying the XHR class twice\n if (DdRumResourceTracking.isTracking) {\n InternalLog.log(\n 'Datadog SDK is already tracking XHR resources',\n SdkVerbosity.WARN\n );\n return;\n }\n\n DdRumResourceTracking.tracingSamplingRate = tracingSamplingRate;\n DdRumResourceTracking.firstPartyHostsRegex = getFirstPartyHostsRegex(\n firstPartyHosts\n );\n\n DdRumResourceTracking.originalXhrOpen = xhrType.prototype.open;\n DdRumResourceTracking.originalXhrSend = xhrType.prototype.send;\n\n DdRumResourceTracking.proxyXhr(xhrType);\n InternalLog.log(\n 'Datadog SDK is tracking XHR resources',\n SdkVerbosity.INFO\n );\n }\n\n static stopTracking(): void {\n if (DdRumResourceTracking.isTracking) {\n DdRumResourceTracking.isTracking = false;\n XMLHttpRequest.prototype.open =\n DdRumResourceTracking.originalXhrOpen;\n XMLHttpRequest.prototype.send =\n DdRumResourceTracking.originalXhrSend;\n }\n }\n\n static getTracingAttributes(url: string): DdRumResourceTracingAttributes {\n try {\n const hostname = URLHostParser(url);\n\n if (DdRumResourceTracking.firstPartyHostsRegex.test(hostname)) {\n return generateTracingAttributesWithSampling(\n DdRumResourceTracking.tracingSamplingRate\n );\n }\n return {\n samplingPriorityHeader: '0',\n tracingStrategy: 'DISCARD'\n };\n } catch (e) {\n InternalLog.log(\n `Impossible to cast ${url} as URL`,\n SdkVerbosity.WARN\n );\n return {\n samplingPriorityHeader: '0',\n tracingStrategy: 'DISCARD'\n };\n }\n }\n\n // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types\n static proxyXhr(xhrType: any): void {\n this.proxyOpen(xhrType);\n this.proxySend(xhrType);\n }\n\n private static proxyOpen(xhrType: any): void {\n const originalXhrOpen = this.originalXhrOpen;\n xhrType.prototype.open = function (\n this: DdRumXhr,\n method: string,\n url: string\n ) {\n // Keep track of the method and url\n // start time is tracked by the `send` method\n this._datadog_xhr = {\n method,\n url,\n reported: false,\n timer: new Timer(),\n tracingAttributes: DdRumResourceTracking.getTracingAttributes(\n url\n )\n };\n // eslint-disable-next-line prefer-rest-params\n return originalXhrOpen.apply(this, arguments as any);\n };\n }\n\n private static proxySend(xhrType: any): void {\n const originalXhrSend = this.originalXhrSend;\n xhrType.prototype.send = function (this: DdRumXhr) {\n if (this._datadog_xhr) {\n // keep track of start time\n this._datadog_xhr.timer.start();\n this.setRequestHeader(ORIGIN_HEADER_KEY, ORIGIN_RUM);\n\n const tracingAttributes = this._datadog_xhr.tracingAttributes;\n this.setRequestHeader(\n SAMPLING_PRIORITY_HEADER_KEY,\n tracingAttributes.samplingPriorityHeader\n );\n if (tracingAttributes.tracingStrategy !== 'DISCARD') {\n this.setRequestHeader(\n TRACE_ID_HEADER_KEY,\n tracingAttributes.traceId\n );\n this.setRequestHeader(\n PARENT_ID_HEADER_KEY,\n tracingAttributes.spanId\n );\n }\n }\n\n DdRumResourceTracking.proxyOnReadyStateChange(this, xhrType);\n\n // eslint-disable-next-line prefer-rest-params\n return originalXhrSend.apply(this, arguments as any);\n };\n }\n\n private static proxyOnReadyStateChange(\n xhrProxy: DdRumXhr,\n xhrType: any\n ): void {\n const originalOnreadystatechange = xhrProxy.onreadystatechange;\n xhrProxy.onreadystatechange = function () {\n if (xhrProxy.readyState === xhrType.DONE) {\n if (!xhrProxy._datadog_xhr.reported) {\n DdRumResourceTracking.reportXhr(xhrProxy);\n xhrProxy._datadog_xhr.reported = true;\n }\n } else if (xhrProxy.readyState === xhrType.HEADERS_RECEIVED) {\n xhrProxy._datadog_xhr.timer.recordTick(RESPONSE_START_LABEL);\n }\n\n if (originalOnreadystatechange) {\n // eslint-disable-next-line prefer-rest-params\n originalOnreadystatechange.apply(xhrProxy, arguments as any);\n }\n };\n }\n\n private static reportXhr(xhrProxy: DdRumXhr): void {\n const responseSize = calculateResponseSize(xhrProxy);\n\n const context = xhrProxy._datadog_xhr;\n\n const key = `${context.timer.startTime}/${context.method}`;\n\n context.timer.stop();\n\n DdRum.startResource(\n key,\n context.method,\n context.url,\n context.tracingAttributes.tracingStrategy === 'DISCARD'\n ? undefined\n : {\n '_dd.span_id': context.tracingAttributes.spanId,\n '_dd.trace_id': context.tracingAttributes.traceId\n },\n context.timer.startTime\n ).then(() => {\n DdRum.stopResource(\n key,\n xhrProxy.status,\n 'xhr',\n responseSize,\n {\n '_dd.resource_timings': context.timer.hasTickFor(\n RESPONSE_START_LABEL\n )\n ? createTimings(\n context.timer.startTime,\n context.timer.timeAt(RESPONSE_START_LABEL),\n context.timer.stopTime\n )\n : null\n },\n context.timer.stopTime\n );\n });\n }\n}\n"]}
@@ -1,2 +0,0 @@
1
- "use strict";
2
- //# sourceMappingURL=DdRumXhr.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["TraceIdentifier.tsx"],"names":["generateTraceId","radix","MAX_32_BITS_NUMBER","low","Math","floor","random","high","str","modH","temp","digit","toString"],"mappings":";;;;;;;AAAA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AAEO,SAASA,eAAT,GAAmC;AACtC,QAAMC,KAAK,GAAG,EAAd;AACA,QAAMC,kBAAkB,GAAG,UAA3B,CAFsC,CAEC;;AACvC,MAAIC,GAAW,GAAGC,IAAI,CAACC,KAAL,CAAWD,IAAI,CAACE,MAAL,KAAgBJ,kBAA3B,CAAlB;AACA,MAAIK,IAAY,GAAGH,IAAI,CAACC,KAAL,CAAWD,IAAI,CAACE,MAAL,KAAgBJ,kBAA3B,CAAnB;AACA,MAAIM,GAAG,GAAG,EAAV;;AAEA,SAAOD,IAAI,GAAG,CAAP,IAAYJ,GAAG,GAAG,CAAzB,EAA4B;AACxB;AACA;AACA,UAAMM,IAAI,GAAGF,IAAI,GAAGN,KAApB;AACA,UAAMS,IAAI,GAAG,CAACD,IAAI,IAAI,EAAT,IAAeN,GAA5B;AACA,UAAMQ,KAAK,GAAGD,IAAI,GAAGT,KAArB,CALwB,CAOxB;;AACAM,IAAAA,IAAI,GAAG,CAACA,IAAI,GAAGE,IAAR,IAAgBR,KAAvB,CARwB,CAQM;AAC9B;;AACAE,IAAAA,GAAG,GAAG,CAACO,IAAI,GAAGC,KAAR,IAAiBV,KAAvB,CAVwB,CAUM;AAE9B;;AACAO,IAAAA,GAAG,GAAGG,KAAK,CAACC,QAAN,KAAmBJ,GAAzB;AACH;;AACD,SAAOA,GAAP;AACH","sourcesContent":["/*\n * Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.\n * This product includes software developed at Datadog (https://www.datadoghq.com/).\n * Copyright 2016-Present Datadog, Inc.\n */\n\n/*\n * This code was inspired from browser-sdk at (https://github.com/DataDog/browser-sdk/blob/master/packages/rum-core/src/domain/tracing/tracer.ts#L107)\n */\n\nexport function generateTraceId(): string {\n const radix = 10;\n const MAX_32_BITS_NUMBER = 4294967295; // 2^32-1\n let low: number = Math.floor(Math.random() * MAX_32_BITS_NUMBER);\n let high: number = Math.floor(Math.random() * MAX_32_BITS_NUMBER);\n let str = '';\n\n while (high > 0 && low > 0) {\n // Create an intermediate value with the same modulo as the combined high and low value\n // but requiring 36 bits max (32 for the low value + 4 for the high part)\n const modH = high % radix;\n const temp = (modH << 32) + low;\n const digit = temp % radix;\n\n // update the high value\n high = (high - modH) / radix; // we reuse the modH to avoid the need of a floor op\n // the low value reuses the previous temp value to account for the \"missing mod\" in the high update\n low = (temp - digit) / radix; // we reuse the digit to avoid the need of a floor op\n\n // update the string from right to left\n str = digit.toString() + str;\n }\n return str;\n}\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["URLHostParser.ts"],"names":["hostRegex","URLHostParser","url","matchedHost","match","Error"],"mappings":";;;;;;;AAAA;AACA;AACA;AACA;AACA;AAEA;AACA,MAAMA,SAAS,GAAG,mBAAlB;AAEA;AACA;AACA;AACA;AACA;;AACO,MAAMC,aAAa,GAAIC,GAAD,IAAyB;AAClD,QAAMC,WAAW,GAAGD,GAAG,CAACE,KAAJ,CAAUJ,SAAV,CAApB;;AACA,MAAIG,WAAW,KAAK,IAApB,EAA0B;AACtB,UAAM,IAAIE,KAAJ,CAAW,GAAEH,GAAI,mCAAjB,CAAN;AACH,GAJiD,CAMlD;;;AACA,SAAOC,WAAW,CAAC,CAAD,CAAlB;AACH,CARM","sourcesContent":["/*\n * Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.\n * This product includes software developed at Datadog (https://www.datadoghq.com/).\n * Copyright 2016-Present Datadog, Inc.\n */\n\n// matches what is between the first \"://\" and the next \"/\", \":\" or whitespace\nconst hostRegex = '^.+://([^:/\\\\s]+)';\n\n/**\n * Returns the host from an URL.\n * @returns the host (without the port)\n * @throws if URL is not well formatted\n */\nexport const URLHostParser = (url: string): string => {\n const matchedHost = url.match(hostRegex);\n if (matchedHost === null) {\n throw new Error(`${url} is not a correctly formatted URL`);\n }\n\n // [0] is the input, [1] is the captured group\n return matchedHost[1];\n};\n"]}