@datadog/mobile-react-native 1.3.1 → 1.5.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 (165) hide show
  1. package/DatadogSDKReactNative.podspec +2 -2
  2. package/android/build.gradle +5 -5
  3. package/android/src/main/kotlin/com/datadog/reactnative/DatadogSDKWrapper.kt +4 -0
  4. package/android/src/main/kotlin/com/datadog/reactnative/DatadogWrapper.kt +6 -0
  5. package/android/src/main/kotlin/com/datadog/reactnative/DdSdk.kt +155 -92
  6. package/android/src/main/kotlin/com/datadog/reactnative/DdSdkConfiguration.kt +2 -0
  7. package/android/src/main/kotlin/com/datadog/reactnative/DdSdkConfigurationExt.kt +16 -0
  8. package/android/src/test/kotlin/com/datadog/reactnative/DdSdkTest.kt +293 -30
  9. package/android/src/test/kotlin/com/datadog/tools/unit/DdSdkConfigurationExt.kt +5 -0
  10. package/android/src/test/kotlin/com/datadog/tools/unit/MapExt.kt +7 -0
  11. package/android/src/test/kotlin/com/datadog/tools/unit/forge/DdSdkConfigurationForgeryFactory.kt +2 -1
  12. package/android/src/test/kotlin/com/datadog/tools/unit/forge/TelemetryConfigurationEventForgeryFactory.kt +10 -0
  13. package/datadog-sourcemaps.gradle +55 -7
  14. package/ios/Sources/DdSdk.m +4 -0
  15. package/ios/Sources/DdSdk.swift +19 -2
  16. package/ios/Sources/DdSdkConfiguration.swift +6 -0
  17. package/ios/Sources/RNDdSdkConfiguration.swift +44 -0
  18. package/jest/mock.js +1 -1
  19. package/lib/commonjs/DdSdkReactNative.js +3 -3
  20. package/lib/commonjs/DdSdkReactNative.js.map +1 -1
  21. package/lib/commonjs/DdSdkReactNativeConfiguration.js +34 -2
  22. package/lib/commonjs/DdSdkReactNativeConfiguration.js.map +1 -1
  23. package/lib/commonjs/index.js +12 -0
  24. package/lib/commonjs/index.js.map +1 -1
  25. package/lib/commonjs/nativeModulesTypes.js.map +1 -1
  26. package/lib/commonjs/rum/instrumentation/resourceTracking/DdRumResourceTracking.js +5 -5
  27. package/lib/commonjs/rum/instrumentation/resourceTracking/DdRumResourceTracking.js.map +1 -1
  28. package/lib/commonjs/rum/instrumentation/resourceTracking/distributedTracing/distributedTracing.js +101 -0
  29. package/lib/commonjs/rum/instrumentation/resourceTracking/distributedTracing/distributedTracing.js.map +1 -0
  30. package/lib/commonjs/rum/instrumentation/resourceTracking/distributedTracing/distributedTracingHeaders.js +136 -0
  31. package/lib/commonjs/rum/instrumentation/resourceTracking/distributedTracing/distributedTracingHeaders.js.map +1 -0
  32. package/lib/commonjs/rum/instrumentation/resourceTracking/{domain → distributedTracing}/firstPartyHosts.js +39 -6
  33. package/lib/commonjs/rum/instrumentation/resourceTracking/distributedTracing/firstPartyHosts.js.map +1 -0
  34. package/lib/commonjs/rum/instrumentation/resourceTracking/{implementation → requestProxy/XHRProxy}/DatadogRumResource/ResourceReporter.js +4 -4
  35. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/DatadogRumResource/ResourceReporter.js.map +1 -0
  36. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/DatadogRumResource/internalDevResourceBlocklist.js.map +1 -0
  37. package/lib/commonjs/rum/instrumentation/resourceTracking/{implementation → requestProxy/XHRProxy}/URLHostParser.js +2 -2
  38. package/lib/commonjs/rum/instrumentation/resourceTracking/{implementation → requestProxy/XHRProxy}/URLHostParser.js.map +1 -1
  39. package/lib/commonjs/rum/instrumentation/resourceTracking/{implementation → requestProxy/XHRProxy}/XHRProxy.js +15 -24
  40. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/XHRProxy.js.map +1 -0
  41. package/lib/commonjs/rum/instrumentation/resourceTracking/{implementation → requestProxy/XHRProxy}/responseSize.js +2 -2
  42. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/responseSize.js.map +1 -0
  43. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/interfaces/RequestProxy.js.map +1 -0
  44. package/lib/commonjs/rum/types.js +19 -1
  45. package/lib/commonjs/rum/types.js.map +1 -1
  46. package/lib/commonjs/types.js +2 -1
  47. package/lib/commonjs/types.js.map +1 -1
  48. package/lib/commonjs/version.js +1 -1
  49. package/lib/commonjs/version.js.map +1 -1
  50. package/lib/module/DdSdkReactNative.js +4 -4
  51. package/lib/module/DdSdkReactNative.js.map +1 -1
  52. package/lib/module/DdSdkReactNativeConfiguration.js +30 -1
  53. package/lib/module/DdSdkReactNativeConfiguration.js.map +1 -1
  54. package/lib/module/index.js +3 -3
  55. package/lib/module/index.js.map +1 -1
  56. package/lib/module/nativeModulesTypes.js.map +1 -1
  57. package/lib/module/rum/instrumentation/resourceTracking/DdRumResourceTracking.js +6 -6
  58. package/lib/module/rum/instrumentation/resourceTracking/DdRumResourceTracking.js.map +1 -1
  59. package/lib/module/rum/instrumentation/resourceTracking/distributedTracing/distributedTracing.js +93 -0
  60. package/lib/module/rum/instrumentation/resourceTracking/distributedTracing/distributedTracing.js.map +1 -0
  61. package/lib/module/rum/instrumentation/resourceTracking/distributedTracing/distributedTracingHeaders.js +115 -0
  62. package/lib/module/rum/instrumentation/resourceTracking/distributedTracing/distributedTracingHeaders.js.map +1 -0
  63. package/lib/module/rum/instrumentation/resourceTracking/{domain → distributedTracing}/firstPartyHosts.js +37 -3
  64. package/lib/module/rum/instrumentation/resourceTracking/distributedTracing/firstPartyHosts.js.map +1 -0
  65. package/lib/module/rum/instrumentation/resourceTracking/{implementation → requestProxy/XHRProxy}/DatadogRumResource/ResourceReporter.js +4 -4
  66. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/DatadogRumResource/ResourceReporter.js.map +1 -0
  67. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/DatadogRumResource/internalDevResourceBlocklist.js.map +1 -0
  68. package/lib/module/rum/instrumentation/resourceTracking/{implementation → requestProxy/XHRProxy}/URLHostParser.js +2 -2
  69. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/URLHostParser.js.map +1 -0
  70. package/lib/module/rum/instrumentation/resourceTracking/{implementation → requestProxy/XHRProxy}/XHRProxy.js +13 -18
  71. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/XHRProxy.js.map +1 -0
  72. package/lib/module/rum/instrumentation/resourceTracking/{implementation → requestProxy/XHRProxy}/responseSize.js +2 -2
  73. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/responseSize.js.map +1 -0
  74. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/interfaces/RequestProxy.js.map +1 -0
  75. package/lib/module/rum/types.js +16 -0
  76. package/lib/module/rum/types.js.map +1 -1
  77. package/lib/module/types.js +2 -1
  78. package/lib/module/types.js.map +1 -1
  79. package/lib/module/version.js +1 -1
  80. package/lib/module/version.js.map +1 -1
  81. package/lib/typescript/DdSdkReactNativeConfiguration.d.ts +16 -3
  82. package/lib/typescript/index.d.ts +3 -3
  83. package/lib/typescript/nativeModulesTypes.d.ts +5 -0
  84. package/lib/typescript/rum/instrumentation/resourceTracking/DdRumResourceTracking.d.ts +2 -1
  85. package/lib/typescript/rum/instrumentation/resourceTracking/distributedTracing/distributedTracing.d.ts +45 -0
  86. package/lib/typescript/rum/instrumentation/resourceTracking/distributedTracing/distributedTracingHeaders.d.ts +21 -0
  87. package/lib/typescript/rum/instrumentation/resourceTracking/distributedTracing/firstPartyHosts.d.ts +8 -0
  88. package/lib/typescript/rum/instrumentation/resourceTracking/{implementation → requestProxy/XHRProxy}/DatadogRumResource/ResourceReporter.d.ts +1 -1
  89. package/lib/typescript/rum/instrumentation/resourceTracking/{implementation → requestProxy/XHRProxy}/DatadogRumResource/internalDevResourceBlocklist.d.ts +1 -1
  90. package/lib/typescript/rum/instrumentation/resourceTracking/{implementation → requestProxy/XHRProxy}/URLHostParser.d.ts +1 -1
  91. package/lib/typescript/rum/instrumentation/resourceTracking/{implementation → requestProxy/XHRProxy}/XHRProxy.d.ts +2 -7
  92. package/lib/typescript/rum/instrumentation/resourceTracking/{domain → requestProxy}/interfaces/RequestProxy.d.ts +6 -1
  93. package/lib/typescript/rum/instrumentation/resourceTracking/{domain → requestProxy}/interfaces/RumResource.d.ts +1 -1
  94. package/lib/typescript/rum/types.d.ts +17 -0
  95. package/lib/typescript/types.d.ts +2 -1
  96. package/lib/typescript/version.d.ts +1 -1
  97. package/package.json +76 -76
  98. package/src/DdSdkReactNative.tsx +9 -4
  99. package/src/DdSdkReactNativeConfiguration.tsx +44 -4
  100. package/src/__tests__/DdSdkReactNative.test.tsx +16 -4
  101. package/src/__tests__/DdSdkReactNativeConfiguration.test.ts +7 -2
  102. package/src/index.tsx +6 -3
  103. package/src/nativeModulesTypes.ts +6 -0
  104. package/src/rum/__tests__/DdRum.test.ts +17 -1
  105. package/src/rum/instrumentation/resourceTracking/DdRumResourceTracking.tsx +10 -7
  106. package/src/rum/instrumentation/resourceTracking/__tests__/DdRumResourceTracking.test.ts +13 -2
  107. package/src/rum/instrumentation/resourceTracking/distributedTracing/__tests__/distributedTracing.test.ts +71 -0
  108. package/src/rum/instrumentation/resourceTracking/distributedTracing/__tests__/firstPartyHosts.test.ts +34 -0
  109. package/src/rum/instrumentation/resourceTracking/distributedTracing/distributedTracing.tsx +131 -0
  110. package/src/rum/instrumentation/resourceTracking/distributedTracing/distributedTracingHeaders.ts +141 -0
  111. package/src/rum/instrumentation/resourceTracking/{domain → distributedTracing}/firstPartyHosts.ts +42 -7
  112. package/src/rum/instrumentation/resourceTracking/{implementation → requestProxy/XHRProxy}/DatadogRumResource/ResourceReporter.ts +6 -6
  113. package/src/rum/instrumentation/resourceTracking/{implementation → requestProxy/XHRProxy}/DatadogRumResource/__tests__/ResourceReporter.test.ts +2 -2
  114. package/src/rum/instrumentation/resourceTracking/{implementation → requestProxy/XHRProxy}/DatadogRumResource/__tests__/__utils__/ResourceMockFactory.ts +1 -1
  115. package/src/rum/instrumentation/resourceTracking/{implementation → requestProxy/XHRProxy}/DatadogRumResource/internalDevResourceBlocklist.ts +1 -1
  116. package/src/rum/instrumentation/resourceTracking/{implementation → requestProxy/XHRProxy}/URLHostParser.ts +3 -3
  117. package/src/rum/instrumentation/resourceTracking/{implementation → requestProxy/XHRProxy}/XHRProxy.ts +13 -28
  118. package/src/rum/instrumentation/resourceTracking/{implementation → requestProxy/XHRProxy}/__tests__/XHRProxy.test.ts +257 -79
  119. package/src/rum/instrumentation/resourceTracking/{implementation → requestProxy/XHRProxy}/responseSize.ts +2 -2
  120. package/src/rum/instrumentation/resourceTracking/{domain → requestProxy}/interfaces/RequestProxy.ts +8 -1
  121. package/src/rum/instrumentation/resourceTracking/{domain → requestProxy}/interfaces/RumResource.ts +1 -1
  122. package/src/rum/types.ts +19 -0
  123. package/src/sdk/DatadogProvider/__tests__/initialization.test.tsx +1 -0
  124. package/src/sdk/DatadogProvider/__tests__/initializationModes.test.tsx +1 -1
  125. package/src/types.tsx +1 -0
  126. package/src/version.ts +1 -1
  127. package/lib/commonjs/rum/instrumentation/resourceTracking/domain/distributedTracing.js +0 -83
  128. package/lib/commonjs/rum/instrumentation/resourceTracking/domain/distributedTracing.js.map +0 -1
  129. package/lib/commonjs/rum/instrumentation/resourceTracking/domain/firstPartyHosts.js.map +0 -1
  130. package/lib/commonjs/rum/instrumentation/resourceTracking/domain/interfaces/RequestProxy.js.map +0 -1
  131. package/lib/commonjs/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/ResourceReporter.js.map +0 -1
  132. package/lib/commonjs/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/internalDevResourceBlocklist.js.map +0 -1
  133. package/lib/commonjs/rum/instrumentation/resourceTracking/implementation/XHRProxy.js.map +0 -1
  134. package/lib/commonjs/rum/instrumentation/resourceTracking/implementation/responseSize.js.map +0 -1
  135. package/lib/module/rum/instrumentation/resourceTracking/domain/distributedTracing.js +0 -71
  136. package/lib/module/rum/instrumentation/resourceTracking/domain/distributedTracing.js.map +0 -1
  137. package/lib/module/rum/instrumentation/resourceTracking/domain/firstPartyHosts.js.map +0 -1
  138. package/lib/module/rum/instrumentation/resourceTracking/domain/interfaces/RequestProxy.js.map +0 -1
  139. package/lib/module/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/ResourceReporter.js.map +0 -1
  140. package/lib/module/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/internalDevResourceBlocklist.js.map +0 -1
  141. package/lib/module/rum/instrumentation/resourceTracking/implementation/URLHostParser.js.map +0 -1
  142. package/lib/module/rum/instrumentation/resourceTracking/implementation/XHRProxy.js.map +0 -1
  143. package/lib/module/rum/instrumentation/resourceTracking/implementation/responseSize.js.map +0 -1
  144. package/lib/typescript/rum/instrumentation/resourceTracking/domain/distributedTracing.d.ts +0 -19
  145. package/lib/typescript/rum/instrumentation/resourceTracking/domain/firstPartyHosts.d.ts +0 -6
  146. package/src/rum/instrumentation/resourceTracking/domain/__tests__/distributedTracing.test.ts +0 -31
  147. package/src/rum/instrumentation/resourceTracking/domain/__tests__/firstPartyHosts.test.ts +0 -22
  148. package/src/rum/instrumentation/resourceTracking/domain/distributedTracing.tsx +0 -89
  149. /package/lib/commonjs/rum/instrumentation/resourceTracking/{implementation → requestProxy/XHRProxy}/DatadogRumResource/internalDevResourceBlocklist.js +0 -0
  150. /package/lib/commonjs/rum/instrumentation/resourceTracking/{implementation → requestProxy/XHRProxy}/DatadogRumResource/resourceTiming.js +0 -0
  151. /package/lib/commonjs/rum/instrumentation/resourceTracking/{implementation → requestProxy/XHRProxy}/DatadogRumResource/resourceTiming.js.map +0 -0
  152. /package/lib/commonjs/rum/instrumentation/resourceTracking/{domain → requestProxy}/interfaces/RequestProxy.js +0 -0
  153. /package/lib/commonjs/rum/instrumentation/resourceTracking/{domain → requestProxy}/interfaces/RumResource.js +0 -0
  154. /package/lib/commonjs/rum/instrumentation/resourceTracking/{domain → requestProxy}/interfaces/RumResource.js.map +0 -0
  155. /package/lib/module/rum/instrumentation/resourceTracking/{implementation → requestProxy/XHRProxy}/DatadogRumResource/internalDevResourceBlocklist.js +0 -0
  156. /package/lib/module/rum/instrumentation/resourceTracking/{implementation → requestProxy/XHRProxy}/DatadogRumResource/resourceTiming.js +0 -0
  157. /package/lib/module/rum/instrumentation/resourceTracking/{implementation → requestProxy/XHRProxy}/DatadogRumResource/resourceTiming.js.map +0 -0
  158. /package/lib/module/rum/instrumentation/resourceTracking/{domain → requestProxy}/interfaces/RequestProxy.js +0 -0
  159. /package/lib/module/rum/instrumentation/resourceTracking/{domain → requestProxy}/interfaces/RumResource.js +0 -0
  160. /package/lib/module/rum/instrumentation/resourceTracking/{domain → requestProxy}/interfaces/RumResource.js.map +0 -0
  161. /package/lib/typescript/rum/instrumentation/resourceTracking/{implementation → requestProxy/XHRProxy}/DatadogRumResource/resourceTiming.d.ts +0 -0
  162. /package/lib/typescript/rum/instrumentation/resourceTracking/{implementation → requestProxy/XHRProxy}/responseSize.d.ts +0 -0
  163. /package/src/rum/instrumentation/resourceTracking/{implementation → requestProxy/XHRProxy}/DatadogRumResource/__tests__/internalDevResourceBlocklist.test.ts +0 -0
  164. /package/src/rum/instrumentation/resourceTracking/{implementation → requestProxy/XHRProxy}/DatadogRumResource/resourceTiming.ts +0 -0
  165. /package/src/rum/instrumentation/resourceTracking/{implementation → requestProxy/XHRProxy}/__tests__/URLHostParser.test.ts +0 -0
@@ -48,6 +48,7 @@ describe('DdSdkReactNativeConfiguration', () => {
48
48
  "site": "US1",
49
49
  "telemetrySampleRate": 20,
50
50
  "trackErrors": false,
51
+ "trackFrustrations": true,
51
52
  "trackInteractions": false,
52
53
  "trackResources": false,
53
54
  "trackingConsent": "granted",
@@ -93,7 +94,8 @@ describe('DdSdkReactNativeConfiguration', () => {
93
94
  trackingConsent: TrackingConsent.PENDING,
94
95
  nativeCrashReportEnabled: true,
95
96
  nativeLongTaskThresholdMs: 345,
96
- longTaskThresholdMs: 567
97
+ longTaskThresholdMs: 567,
98
+ trackFrustrations: true
97
99
  }
98
100
  )
99
101
  ).toMatchInlineSnapshot(`
@@ -129,6 +131,7 @@ describe('DdSdkReactNativeConfiguration', () => {
129
131
  "site": "EU",
130
132
  "telemetrySampleRate": 20,
131
133
  "trackErrors": true,
134
+ "trackFrustrations": true,
132
135
  "trackInteractions": true,
133
136
  "trackResources": true,
134
137
  "trackingConsent": "pending",
@@ -163,7 +166,8 @@ describe('DdSdkReactNativeConfiguration', () => {
163
166
  additionalConfig: {},
164
167
  nativeCrashReportEnabled: false,
165
168
  nativeLongTaskThresholdMs: false,
166
- longTaskThresholdMs: false
169
+ longTaskThresholdMs: false,
170
+ trackFrustrations: false
167
171
  }
168
172
  )
169
173
  ).toMatchInlineSnapshot(`
@@ -189,6 +193,7 @@ describe('DdSdkReactNativeConfiguration', () => {
189
193
  "site": "",
190
194
  "telemetrySampleRate": 20,
191
195
  "trackErrors": false,
196
+ "trackFrustrations": false,
192
197
  "trackInteractions": false,
193
198
  "trackResources": false,
194
199
  "trackingConsent": "granted",
package/src/index.tsx CHANGED
@@ -7,7 +7,8 @@
7
7
  import {
8
8
  DatadogProviderConfiguration,
9
9
  DdSdkReactNativeConfiguration,
10
- InitializationMode
10
+ InitializationMode,
11
+ VitalsUpdateFrequency
11
12
  } from './DdSdkReactNativeConfiguration';
12
13
  import { DdSdkReactNative } from './DdSdkReactNative';
13
14
  import { InternalLog } from './InternalLog';
@@ -17,7 +18,7 @@ import { TrackingConsent } from './TrackingConsent';
17
18
  import { DdTrace } from './foundation';
18
19
  import { DdLogs } from './logs/DdLogs';
19
20
  import { DdRum } from './rum/DdRum';
20
- import { RumActionType, ErrorSource } from './rum/types';
21
+ import { RumActionType, ErrorSource, PropagatorType } from './rum/types';
21
22
  import { DatadogProvider } from './sdk/DatadogProvider/DatadogProvider';
22
23
 
23
24
  export {
@@ -35,5 +36,7 @@ export {
35
36
  ProxyConfiguration,
36
37
  ProxyType,
37
38
  TrackingConsent,
38
- SdkVerbosity
39
+ SdkVerbosity,
40
+ VitalsUpdateFrequency,
41
+ PropagatorType
39
42
  };
@@ -61,6 +61,12 @@ export type DdNativeSdkType = {
61
61
  * @param kind error kind
62
62
  */
63
63
  telemetryError(message: string, stack: string, kind: string): Promise<void>;
64
+
65
+ /**
66
+ * Send webview telemetry logs
67
+ * @param message event description
68
+ */
69
+ consumeWebviewEvent(message: string): Promise<void>;
64
70
  };
65
71
 
66
72
  /**
@@ -13,7 +13,7 @@ import { DdRum } from '../DdRum';
13
13
  import type { ActionEventMapper } from '../eventMappers/actionEventMapper';
14
14
  import type { ErrorEventMapper } from '../eventMappers/errorEventMapper';
15
15
  import type { ResourceEventMapper } from '../eventMappers/resourceEventMapper';
16
- import { ErrorSource, RumActionType } from '../types';
16
+ import { ErrorSource, PropagatorType, RumActionType } from '../types';
17
17
 
18
18
  jest.mock('../../TimeProvider', () => {
19
19
  return {
@@ -383,4 +383,20 @@ describe('DdRum', () => {
383
383
  );
384
384
  });
385
385
  });
386
+
387
+ describe('PropagatorTypes', () => {
388
+ it('matches with the native name of propagators', () => {
389
+ /**
390
+ * If you break this test by changing the value of the enum,
391
+ * be sure to update the native implementation of
392
+ * - ReadableArray.asTracingHeaderTypes (Android)
393
+ * - asTracingHeaderType (iOS)
394
+ * so that it uses the new values
395
+ */
396
+ expect(PropagatorType.DATADOG).toBe('datadog');
397
+ expect(PropagatorType.B3).toBe('b3');
398
+ expect(PropagatorType.B3MULTI).toBe('b3multi');
399
+ expect(PropagatorType.TRACECONTEXT).toBe('tracecontext');
400
+ });
401
+ });
386
402
  });
@@ -6,12 +6,13 @@
6
6
 
7
7
  import { InternalLog } from '../../../InternalLog';
8
8
  import { SdkVerbosity } from '../../../SdkVerbosity';
9
+ import type { FirstPartyHost } from '../../types';
9
10
 
10
- import { firstPartyHostsRegexBuilder } from './domain/firstPartyHosts';
11
- import type { RequestProxy } from './domain/interfaces/RequestProxy';
12
- import { ResourceReporter } from './implementation/DatadogRumResource/ResourceReporter';
13
- import { filterDevResource } from './implementation/DatadogRumResource/internalDevResourceBlocklist';
14
- import { XHRProxy } from './implementation/XHRProxy';
11
+ import { firstPartyHostsRegexMapBuilder } from './distributedTracing/firstPartyHosts';
12
+ import { ResourceReporter } from './requestProxy/XHRProxy/DatadogRumResource/ResourceReporter';
13
+ import { filterDevResource } from './requestProxy/XHRProxy/DatadogRumResource/internalDevResourceBlocklist';
14
+ import { XHRProxy } from './requestProxy/XHRProxy/XHRProxy';
15
+ import type { RequestProxy } from './requestProxy/interfaces/RequestProxy';
15
16
 
16
17
  /**
17
18
  * Provides RUM auto-instrumentation feature to track resources (fetch, XHR, axios) as RUM events.
@@ -28,7 +29,7 @@ export class DdRumResourceTracking {
28
29
  firstPartyHosts
29
30
  }: {
30
31
  tracingSamplingRate: number;
31
- firstPartyHosts: string[];
32
+ firstPartyHosts: FirstPartyHost[];
32
33
  }): void {
33
34
  // extra safety to avoid proxying the XHR class twice
34
35
  if (DdRumResourceTracking.isTracking) {
@@ -45,7 +46,9 @@ export class DdRumResourceTracking {
45
46
  });
46
47
  this.requestProxy.onTrackingStart({
47
48
  tracingSamplingRate,
48
- firstPartyHostsRegex: firstPartyHostsRegexBuilder(firstPartyHosts)
49
+ firstPartyHostsRegexMap: firstPartyHostsRegexMapBuilder(
50
+ firstPartyHosts
51
+ )
49
52
  });
50
53
 
51
54
  InternalLog.log(
@@ -7,6 +7,7 @@
7
7
  import { NativeModules } from 'react-native';
8
8
 
9
9
  import { BufferSingleton } from '../../../../sdk/DatadogProvider/Buffer/BufferSingleton';
10
+ import { PropagatorType } from '../../../types';
10
11
  import { DdRumResourceTracking } from '../DdRumResourceTracking';
11
12
 
12
13
  import { XMLHttpRequestMock } from './__utils__/XMLHttpRequestMock';
@@ -41,7 +42,12 @@ describe('DdRumResourceTracking', () => {
41
42
  global.XMLHttpRequest = XMLHttpRequestMock;
42
43
  DdRumResourceTracking.startTracking({
43
44
  tracingSamplingRate: 100,
44
- firstPartyHosts: ['example.com']
45
+ firstPartyHosts: [
46
+ {
47
+ match: 'example.com',
48
+ propagatorTypes: [PropagatorType.DATADOG]
49
+ }
50
+ ]
45
51
  });
46
52
 
47
53
  // WHEN
@@ -68,7 +74,12 @@ describe('DdRumResourceTracking', () => {
68
74
  global.XMLHttpRequest = XMLHttpRequestMock;
69
75
  DdRumResourceTracking.startTracking({
70
76
  tracingSamplingRate: 100,
71
- firstPartyHosts: ['example.com']
77
+ firstPartyHosts: [
78
+ {
79
+ match: 'example.com',
80
+ propagatorTypes: [PropagatorType.DATADOG]
81
+ }
82
+ ]
72
83
  });
73
84
 
74
85
  // WHEN
@@ -0,0 +1,71 @@
1
+ import { TraceIdentifier } from '../distributedTracing';
2
+
3
+ describe('TraceIdentifier', () => {
4
+ it('M return an unique identifier W toString', async () => {
5
+ // GIVEN
6
+ const generatedIds = new Set<string>();
7
+ const iterations = 100;
8
+ let counter = iterations;
9
+
10
+ // WHEN
11
+ while (counter-- > 0) {
12
+ generatedIds.add(new TraceIdentifier().toString(10));
13
+ }
14
+
15
+ // THEN
16
+ expect(generatedIds.size).toBe(iterations);
17
+ });
18
+
19
+ it('M return an 64 bits positive integer W toString', async () => {
20
+ let iterations = 100;
21
+ while (iterations-- > 0) {
22
+ // GIVEN
23
+ const id = new TraceIdentifier().toString(10);
24
+
25
+ // THEN
26
+ expect(id).toMatch(/[1-9]{1,19}/);
27
+ // should be less than the max 64 bits integer
28
+ if (id.length === 19) {
29
+ expect(id < '9223372036854775807').toBeTruthy();
30
+ }
31
+ }
32
+ });
33
+
34
+ it('M return an 64 bits positive hex W toString(16)', async () => {
35
+ let iterations = 100;
36
+ while (iterations-- > 0) {
37
+ // GIVEN
38
+ const trace = new TraceIdentifier();
39
+ const id = trace.toString(16);
40
+ const paddedId = trace.toPaddedString(16, 16);
41
+
42
+ // THEN
43
+ expect(id).toMatch(/[1-9a-f]{1,16}/);
44
+ expect(paddedId).toMatch(/[0-9a-f]{16}/);
45
+ }
46
+ });
47
+
48
+ it('M return an 64 bits positive padded hex W toPaddedString(16, 32)', async () => {
49
+ let iterations = 100;
50
+ while (iterations-- > 0) {
51
+ // GIVEN
52
+ const id = new TraceIdentifier().toPaddedString(16, 32);
53
+
54
+ // THEN
55
+ expect(id).not.toMatch(/[0]{32}/);
56
+ expect(id).toMatch(/[0]{16}[0-9a-f]{16}/);
57
+ }
58
+ });
59
+
60
+ it('M return original string hex W toPaddedString(16, 10)', async () => {
61
+ let iterations = 100;
62
+ while (iterations-- > 0) {
63
+ // GIVEN
64
+ const id = new TraceIdentifier().toPaddedString(16, 10);
65
+
66
+ // THEN
67
+ expect(id).not.toMatch(/[0]{10}/);
68
+ expect(id).toMatch(/[0-9a-f]{10}/);
69
+ }
70
+ });
71
+ });
@@ -0,0 +1,34 @@
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 { PropagatorType } from '../../../../types';
8
+ import { firstPartyHostsRegexMapBuilder } from '../firstPartyHosts';
9
+
10
+ describe('firstPartyHosts', () => {
11
+ describe('firstPartyHostsRegexMapBuilder', () => {
12
+ it('returns a RegExp that matches hosts', () => {
13
+ const regexMap = firstPartyHostsRegexMapBuilder([
14
+ {
15
+ match: 'api.example.com',
16
+ propagatorTypes: [PropagatorType.DATADOG]
17
+ }
18
+ ]);
19
+ expect(regexMap[0].propagatorType).toBe('datadog');
20
+ expect(regexMap[0].regex.test('api.example.com')).toBe(true);
21
+ expect(regexMap[0].regex.test('api.myapi.com')).toBe(false);
22
+ });
23
+
24
+ it('escapes special characters in hosts', () => {
25
+ const regexMap = firstPartyHostsRegexMapBuilder([
26
+ {
27
+ match: 'api.example.com',
28
+ propagatorTypes: [PropagatorType.DATADOG]
29
+ }
30
+ ]);
31
+ expect(regexMap[0].regex.test('apiiexample.com')).toBe(false);
32
+ });
33
+ });
34
+ });
@@ -0,0 +1,131 @@
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 type { PropagatorType } from '../../../types';
8
+ import type { RegexMap } from '../requestProxy/interfaces/RequestProxy';
9
+
10
+ import type { Hostname } from './firstPartyHosts';
11
+ import { getPropagatorsForHost } from './firstPartyHosts';
12
+
13
+ export type DdRumResourceTracingAttributes =
14
+ | {
15
+ tracingStrategy: 'KEEP';
16
+ traceId: TraceId;
17
+ spanId: SpanId;
18
+ samplingPriorityHeader: '1' | '0';
19
+ rulePsr: number;
20
+ propagatorTypes: PropagatorType[];
21
+ }
22
+ | {
23
+ tracingStrategy: 'DISCARD';
24
+ traceId?: void;
25
+ spanId?: void;
26
+ samplingPriorityHeader: '0';
27
+ };
28
+
29
+ const DISCARDED_TRACE_ATTRIBUTES: DdRumResourceTracingAttributes = {
30
+ samplingPriorityHeader: '0',
31
+ tracingStrategy: 'DISCARD'
32
+ };
33
+
34
+ export const getTracingAttributes = ({
35
+ hostname,
36
+ firstPartyHostsRegexMap,
37
+ tracingSamplingRate
38
+ }: {
39
+ hostname: Hostname | null;
40
+ firstPartyHostsRegexMap: RegexMap;
41
+ tracingSamplingRate: number;
42
+ }): DdRumResourceTracingAttributes => {
43
+ if (hostname === null) {
44
+ return DISCARDED_TRACE_ATTRIBUTES;
45
+ }
46
+ const propagatorsForHost = getPropagatorsForHost(
47
+ hostname,
48
+ firstPartyHostsRegexMap
49
+ );
50
+ if (propagatorsForHost) {
51
+ return generateTracingAttributesWithSampling(
52
+ tracingSamplingRate,
53
+ propagatorsForHost
54
+ );
55
+ }
56
+ return DISCARDED_TRACE_ATTRIBUTES;
57
+ };
58
+
59
+ const generateTracingAttributesWithSampling = (
60
+ tracingSamplingRate: number,
61
+ propagatorTypes: PropagatorType[]
62
+ ): DdRumResourceTracingAttributes => {
63
+ const isSampled = Math.random() * 100 <= tracingSamplingRate;
64
+ const tracingAttributes: DdRumResourceTracingAttributes = {
65
+ traceId: new TraceIdentifier() as TraceId,
66
+ spanId: new TraceIdentifier() as SpanId,
67
+ samplingPriorityHeader: isSampled ? '1' : '0',
68
+ tracingStrategy: 'KEEP',
69
+ rulePsr: tracingSamplingRate / 100,
70
+ propagatorTypes
71
+ };
72
+
73
+ return tracingAttributes;
74
+ };
75
+
76
+ /**
77
+ * Using branded types will ensure we don't accidentally use
78
+ * traceId for spanId when generating headers.
79
+ */
80
+ export type TraceId = TraceIdentifier & {
81
+ _brand: 'traceId';
82
+ };
83
+
84
+ export type SpanId = TraceIdentifier & {
85
+ _brand: 'spanId';
86
+ };
87
+
88
+ /*
89
+ * This code was inspired from browser-sdk at (https://github.com/DataDog/browser-sdk/blob/0e9722d5b06f6d49264bc82cd254a207d647d66c/packages/rum-core/src/domain/tracing/tracer.ts#L190)
90
+ */
91
+ const MAX_32_BITS_NUMBER = 4294967295; // 2^32-1
92
+ const MAX_31_BITS_NUMBER = 2147483647; // 2^31-1
93
+ export class TraceIdentifier {
94
+ private low: number;
95
+ private high: number;
96
+
97
+ constructor() {
98
+ // We need to have a 63 bits number max
99
+ this.high = Math.floor(Math.random() * MAX_31_BITS_NUMBER);
100
+ this.low = Math.floor(Math.random() * MAX_32_BITS_NUMBER);
101
+ }
102
+
103
+ toString = (radix: number) => {
104
+ let low = this.low;
105
+ let high = this.high;
106
+ let str = '';
107
+
108
+ while (high > 0 || low > 0) {
109
+ const mod = (high % radix) * (MAX_32_BITS_NUMBER + 1) + low;
110
+ high = Math.floor(high / radix);
111
+ low = Math.floor(mod / radix);
112
+ str = (mod % radix).toString(radix) + str;
113
+ }
114
+ return str;
115
+ };
116
+
117
+ /**
118
+ * This function pads the trace with `0`.
119
+ * It should not be used with a `length` lower than the trace, as we return the full trace in this case.
120
+ * @param radix radix for the trace
121
+ * @param length minimum length
122
+ * @returns padded string
123
+ */
124
+ toPaddedString = (radix: number, length: number) => {
125
+ const traceId = this.toString(radix);
126
+ if (traceId.length > length) {
127
+ return traceId;
128
+ }
129
+ return Array(length - traceId.length + 1).join('0') + traceId;
130
+ };
131
+ }
@@ -0,0 +1,141 @@
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 { PropagatorType } from '../../../types';
8
+
9
+ import type {
10
+ DdRumResourceTracingAttributes,
11
+ SpanId,
12
+ TraceId
13
+ } from './distributedTracing';
14
+
15
+ export const SAMPLING_PRIORITY_HEADER_KEY = 'x-datadog-sampling-priority';
16
+ /**
17
+ * Datadog headers
18
+ */
19
+ export const ORIGIN_HEADER_KEY = 'x-datadog-origin';
20
+ export const ORIGIN_RUM = 'rum';
21
+ export const TRACE_ID_HEADER_KEY = 'x-datadog-trace-id';
22
+ export const PARENT_ID_HEADER_KEY = 'x-datadog-parent-id';
23
+ /**
24
+ * OTel headers
25
+ */
26
+ export const TRACECONTEXT_HEADER_KEY = 'traceparent';
27
+ export const B3_HEADER_KEY = 'b3';
28
+ export const B3_MULTI_TRACE_ID_HEADER_KEY = 'X-B3-TraceId';
29
+ export const B3_MULTI_SPAN_ID_HEADER_KEY = 'X-B3-SpanId';
30
+ export const B3_MULTI_SAMPLED_HEADER_KEY = 'X-B3-Sampled';
31
+
32
+ export const getTracingHeaders = (
33
+ tracingAttributes: DdRumResourceTracingAttributes
34
+ ): { header: string; value: string }[] => {
35
+ const headers: { header: string; value: string }[] = [];
36
+ if (tracingAttributes.tracingStrategy === 'DISCARD') {
37
+ return headers;
38
+ }
39
+ tracingAttributes.propagatorTypes.forEach(propagator => {
40
+ switch (propagator) {
41
+ case PropagatorType.DATADOG: {
42
+ headers.push(
43
+ {
44
+ header: ORIGIN_HEADER_KEY,
45
+ value: ORIGIN_RUM
46
+ },
47
+ {
48
+ header: SAMPLING_PRIORITY_HEADER_KEY,
49
+ value: tracingAttributes.samplingPriorityHeader
50
+ },
51
+ {
52
+ header: TRACE_ID_HEADER_KEY,
53
+ value: tracingAttributes.traceId.toString(10)
54
+ },
55
+ {
56
+ header: PARENT_ID_HEADER_KEY,
57
+ value: tracingAttributes.spanId.toString(10)
58
+ }
59
+ );
60
+ break;
61
+ }
62
+ case PropagatorType.TRACECONTEXT: {
63
+ headers.push({
64
+ header: TRACECONTEXT_HEADER_KEY,
65
+ value: generateTraceContextHeader({
66
+ version: '00',
67
+ traceId: tracingAttributes.traceId,
68
+ parentId: tracingAttributes.spanId,
69
+ isSampled:
70
+ tracingAttributes.samplingPriorityHeader === '1'
71
+ })
72
+ });
73
+ break;
74
+ }
75
+ case PropagatorType.B3: {
76
+ headers.push({
77
+ header: B3_HEADER_KEY,
78
+ value: generateB3Header({
79
+ traceId: tracingAttributes.traceId,
80
+ spanId: tracingAttributes.spanId,
81
+ isSampled:
82
+ tracingAttributes.samplingPriorityHeader === '1'
83
+ })
84
+ });
85
+ break;
86
+ }
87
+ case PropagatorType.B3MULTI: {
88
+ headers.push(
89
+ {
90
+ header: B3_MULTI_TRACE_ID_HEADER_KEY,
91
+ value: tracingAttributes.traceId.toPaddedString(16, 32)
92
+ },
93
+ {
94
+ header: B3_MULTI_SPAN_ID_HEADER_KEY,
95
+ value: tracingAttributes.spanId.toPaddedString(16, 16)
96
+ },
97
+ {
98
+ header: B3_MULTI_SAMPLED_HEADER_KEY,
99
+ value: tracingAttributes.samplingPriorityHeader
100
+ }
101
+ );
102
+ }
103
+ }
104
+ });
105
+
106
+ return headers;
107
+ };
108
+
109
+ const generateTraceContextHeader = ({
110
+ version,
111
+ traceId,
112
+ parentId,
113
+ isSampled
114
+ }: {
115
+ version: string;
116
+ traceId: TraceId;
117
+ parentId: SpanId;
118
+ isSampled: boolean;
119
+ }) => {
120
+ const flags = isSampled ? '01' : '00';
121
+ return `${version}-${traceId.toPaddedString(
122
+ 16,
123
+ 32
124
+ )}-${parentId.toPaddedString(16, 16)}-${flags}`;
125
+ };
126
+
127
+ const generateB3Header = ({
128
+ traceId,
129
+ spanId,
130
+ isSampled
131
+ }: {
132
+ traceId: TraceId;
133
+ spanId: SpanId;
134
+ isSampled: boolean;
135
+ }) => {
136
+ const flags = isSampled ? '1' : '0';
137
+ return `${traceId.toPaddedString(16, 32)}-${spanId.toPaddedString(
138
+ 16,
139
+ 16
140
+ )}-${flags}`;
141
+ };
@@ -6,6 +6,8 @@
6
6
 
7
7
  import { InternalLog } from '../../../../InternalLog';
8
8
  import { SdkVerbosity } from '../../../../SdkVerbosity';
9
+ import type { FirstPartyHost, PropagatorType } from '../../../types';
10
+ import type { RegexMap } from '../requestProxy/interfaces/RequestProxy';
9
11
 
10
12
  export type Hostname = { _type: 'Hostname' } & string;
11
13
 
@@ -17,9 +19,36 @@ const escapeRegExp = (string: string) => {
17
19
  return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); // $& means the whole matched string
18
20
  };
19
21
 
20
- export const firstPartyHostsRegexBuilder = (
21
- firstPartyHosts: string[]
22
- ): RegExp => {
22
+ export const firstPartyHostsRegexMapBuilder = (
23
+ firstPartyHosts: FirstPartyHost[]
24
+ ): RegexMap => {
25
+ const hostsMap: Record<PropagatorType, string[]> = {
26
+ datadog: [],
27
+ tracecontext: [],
28
+ b3: [],
29
+ b3multi: []
30
+ };
31
+
32
+ firstPartyHosts.forEach(host => {
33
+ host.propagatorTypes.forEach(propagatorType => {
34
+ hostsMap[propagatorType].push(host.match);
35
+ });
36
+ });
37
+
38
+ const regexMap: { regex: RegExp; propagatorType: PropagatorType }[] = [];
39
+ Object.entries(hostsMap).forEach(([propagatorType, hosts]) => {
40
+ if (hosts.length > 0) {
41
+ regexMap.push({
42
+ propagatorType: propagatorType as PropagatorType,
43
+ regex: firstPartyHostsRegexBuilder(hosts)
44
+ });
45
+ }
46
+ });
47
+
48
+ return regexMap;
49
+ };
50
+
51
+ const firstPartyHostsRegexBuilder = (firstPartyHosts: string[]): RegExp => {
23
52
  if (firstPartyHosts.length === 0) {
24
53
  return NO_MATCH_REGEX;
25
54
  }
@@ -44,9 +73,15 @@ export const firstPartyHostsRegexBuilder = (
44
73
  }
45
74
  };
46
75
 
47
- export const isHostFirstParty = (
76
+ export const getPropagatorsForHost = (
48
77
  hostname: Hostname,
49
- firstPartyHostsRegex: RegExp
50
- ): boolean => {
51
- return firstPartyHostsRegex.test(hostname);
78
+ firstPartyHostsRegexMap: RegexMap
79
+ ): PropagatorType[] | null => {
80
+ const matchedPropagatorTypes: PropagatorType[] = [];
81
+ firstPartyHostsRegexMap.forEach(({ regex, propagatorType }) => {
82
+ if (regex.test(hostname)) {
83
+ matchedPropagatorTypes.push(propagatorType);
84
+ }
85
+ });
86
+ return matchedPropagatorTypes.length > 0 ? matchedPropagatorTypes : null;
52
87
  };
@@ -4,8 +4,8 @@
4
4
  * Copyright 2016-Present Datadog, Inc.
5
5
  */
6
6
 
7
- import { DdRum } from '../../../../DdRum';
8
- import type { RUMResource } from '../../domain/interfaces/RumResource';
7
+ import { DdRum } from '../../../../../DdRum';
8
+ import type { RUMResource } from '../../interfaces/RumResource';
9
9
 
10
10
  import { createTimings } from './resourceTiming';
11
11
 
@@ -34,12 +34,12 @@ export class ResourceReporter {
34
34
 
35
35
  const formatResourceStartContext = (
36
36
  tracingAttributes: RUMResource['tracingAttributes']
37
- ): Record<string, unknown> | undefined => {
38
- return tracingAttributes.tracingStrategy === 'DISCARD'
37
+ ): Record<string, string | number> | undefined => {
38
+ return tracingAttributes.samplingPriorityHeader === '0'
39
39
  ? undefined
40
40
  : {
41
- '_dd.span_id': tracingAttributes.spanId,
42
- '_dd.trace_id': tracingAttributes.traceId,
41
+ '_dd.span_id': tracingAttributes.spanId.toString(10),
42
+ '_dd.trace_id': tracingAttributes.traceId.toString(10),
43
43
  '_dd.rule_psr': tracingAttributes.rulePsr
44
44
  };
45
45
  };
@@ -6,8 +6,8 @@
6
6
 
7
7
  import { NativeModules } from 'react-native';
8
8
 
9
- import { BufferSingleton } from '../../../../../../sdk/DatadogProvider/Buffer/BufferSingleton';
10
- import type { RUMResource } from '../../../domain/interfaces/RumResource';
9
+ import { BufferSingleton } from '../../../../../../../sdk/DatadogProvider/Buffer/BufferSingleton';
10
+ import type { RUMResource } from '../../../interfaces/RumResource';
11
11
  import { ResourceReporter } from '../ResourceReporter';
12
12
 
13
13
  import { ResourceMockFactory } from './__utils__/ResourceMockFactory';