@datadog/mobile-react-native 1.0.0-rc5 → 1.0.0-rc8

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 (128) hide show
  1. package/DatadogSDKReactNative.podspec +1 -1
  2. package/README.md +48 -17
  3. package/android/build.gradle +1 -1
  4. package/android/gradle.properties +4 -4
  5. package/ios/Sources/DdSdk.swift +6 -3
  6. package/lib/commonjs/DdSdkReactNative.js +35 -31
  7. package/lib/commonjs/DdSdkReactNative.js.map +1 -1
  8. package/lib/commonjs/DdSdkReactNativeConfiguration.js +20 -7
  9. package/lib/commonjs/DdSdkReactNativeConfiguration.js.map +1 -1
  10. package/lib/commonjs/InternalLog.js +10 -5
  11. package/lib/commonjs/InternalLog.js.map +1 -1
  12. package/lib/commonjs/ProxyConfiguration.js.map +1 -1
  13. package/lib/commonjs/SdkVerbosity.js.map +1 -1
  14. package/lib/commonjs/TimeProvider.js +72 -0
  15. package/lib/commonjs/TimeProvider.js.map +1 -0
  16. package/lib/commonjs/Timer.js +10 -23
  17. package/lib/commonjs/Timer.js.map +1 -1
  18. package/lib/commonjs/TrackingConsent.js.map +1 -1
  19. package/lib/commonjs/foundation.js +19 -54
  20. package/lib/commonjs/foundation.js.map +1 -1
  21. package/lib/commonjs/index.js +27 -19
  22. package/lib/commonjs/index.js.map +1 -1
  23. package/lib/commonjs/rum/instrumentation/DdEventsInterceptor.js +16 -11
  24. package/lib/commonjs/rum/instrumentation/DdEventsInterceptor.js.map +1 -1
  25. package/lib/commonjs/rum/instrumentation/DdRumErrorTracking.js +19 -23
  26. package/lib/commonjs/rum/instrumentation/DdRumErrorTracking.js.map +1 -1
  27. package/lib/commonjs/rum/instrumentation/DdRumResourceTracking.js +118 -42
  28. package/lib/commonjs/rum/instrumentation/DdRumResourceTracking.js.map +1 -1
  29. package/lib/commonjs/rum/instrumentation/DdRumUserInteractionTracking.js +46 -19
  30. package/lib/commonjs/rum/instrumentation/DdRumUserInteractionTracking.js.map +1 -1
  31. package/lib/commonjs/rum/instrumentation/DdRumXhr.js +0 -4
  32. package/lib/commonjs/rum/instrumentation/NoOpEventsInterceptor.js +1 -1
  33. package/lib/commonjs/rum/instrumentation/NoOpEventsInterceptor.js.map +1 -1
  34. package/lib/commonjs/rum/instrumentation/ShallowObjectEqualityChecker.js +34 -0
  35. package/lib/commonjs/rum/instrumentation/ShallowObjectEqualityChecker.js.map +1 -0
  36. package/lib/commonjs/rum/instrumentation/TraceIdentifier.js.map +1 -1
  37. package/lib/commonjs/rum/instrumentation/URLHostParser.js +33 -0
  38. package/lib/commonjs/rum/instrumentation/URLHostParser.js.map +1 -0
  39. package/lib/commonjs/types.js.map +1 -1
  40. package/lib/commonjs/version.js +1 -1
  41. package/lib/commonjs/version.js.map +1 -1
  42. package/lib/module/DdSdkReactNative.js +33 -29
  43. package/lib/module/DdSdkReactNative.js.map +1 -1
  44. package/lib/module/DdSdkReactNativeConfiguration.js +21 -8
  45. package/lib/module/DdSdkReactNativeConfiguration.js.map +1 -1
  46. package/lib/module/InternalLog.js +11 -5
  47. package/lib/module/InternalLog.js.map +1 -1
  48. package/lib/module/ProxyConfiguration.js.map +1 -1
  49. package/lib/module/SdkVerbosity.js.map +1 -1
  50. package/lib/module/TimeProvider.js +63 -0
  51. package/lib/module/TimeProvider.js.map +1 -0
  52. package/lib/module/Timer.js +14 -23
  53. package/lib/module/Timer.js.map +1 -1
  54. package/lib/module/TrackingConsent.js.map +1 -1
  55. package/lib/module/foundation.js +16 -39
  56. package/lib/module/foundation.js.map +1 -1
  57. package/lib/module/index.js +4 -3
  58. package/lib/module/index.js.map +1 -1
  59. package/lib/module/rum/instrumentation/DdEventsInterceptor.js +12 -10
  60. package/lib/module/rum/instrumentation/DdEventsInterceptor.js.map +1 -1
  61. package/lib/module/rum/instrumentation/DdRumErrorTracking.js +19 -23
  62. package/lib/module/rum/instrumentation/DdRumErrorTracking.js.map +1 -1
  63. package/lib/module/rum/instrumentation/DdRumResourceTracking.js +113 -39
  64. package/lib/module/rum/instrumentation/DdRumResourceTracking.js.map +1 -1
  65. package/lib/module/rum/instrumentation/DdRumUserInteractionTracking.js +44 -17
  66. package/lib/module/rum/instrumentation/DdRumUserInteractionTracking.js.map +1 -1
  67. package/lib/module/rum/instrumentation/DdRumXhr.js +1 -1
  68. package/lib/module/rum/instrumentation/NoOpEventsInterceptor.js +1 -1
  69. package/lib/module/rum/instrumentation/NoOpEventsInterceptor.js.map +1 -1
  70. package/lib/module/rum/instrumentation/ShallowObjectEqualityChecker.js +25 -0
  71. package/lib/module/rum/instrumentation/ShallowObjectEqualityChecker.js.map +1 -0
  72. package/lib/module/rum/instrumentation/TraceIdentifier.js.map +1 -1
  73. package/lib/module/rum/instrumentation/URLHostParser.js +24 -0
  74. package/lib/module/rum/instrumentation/URLHostParser.js.map +1 -0
  75. package/lib/module/types.js.map +1 -1
  76. package/lib/module/version.js +1 -1
  77. package/lib/module/version.js.map +1 -1
  78. package/lib/typescript/DdSdkReactNative.d.ts +6 -6
  79. package/lib/typescript/DdSdkReactNativeConfiguration.d.ts +15 -3
  80. package/lib/typescript/InternalLog.d.ts +5 -0
  81. package/lib/typescript/TimeProvider.d.ts +20 -0
  82. package/lib/typescript/Timer.d.ts +3 -2
  83. package/lib/typescript/index.d.ts +4 -3
  84. package/lib/typescript/rum/instrumentation/DdEventsInterceptor.d.ts +1 -0
  85. package/lib/typescript/rum/instrumentation/DdRumErrorTracking.d.ts +2 -2
  86. package/lib/typescript/rum/instrumentation/DdRumResourceTracking.d.ts +19 -9
  87. package/lib/typescript/rum/instrumentation/DdRumUserInteractionTracking.d.ts +3 -3
  88. package/lib/typescript/rum/instrumentation/DdRumXhr.d.ts +13 -3
  89. package/lib/typescript/rum/instrumentation/ShallowObjectEqualityChecker.d.ts +4 -0
  90. package/lib/typescript/rum/instrumentation/URLHostParser.d.ts +6 -0
  91. package/lib/typescript/version.d.ts +1 -1
  92. package/package.json +6 -3
  93. package/src/DdSdkReactNative.tsx +116 -70
  94. package/src/DdSdkReactNativeConfiguration.tsx +22 -13
  95. package/src/InternalLog.tsx +18 -16
  96. package/src/ProxyConfiguration.tsx +5 -5
  97. package/src/SdkVerbosity.tsx +4 -4
  98. package/src/TimeProvider.tsx +64 -0
  99. package/src/Timer.ts +20 -35
  100. package/src/TrackingConsent.tsx +3 -3
  101. package/src/__mocks__/InternalLog.tsx +9 -0
  102. package/src/__tests__/DdRumWrapper.test.tsx +40 -33
  103. package/src/__tests__/DdSdkReactNative.test.tsx +712 -513
  104. package/src/__tests__/InternalLog.test.tsx +114 -117
  105. package/src/__tests__/TimeProvider.test.tsx +75 -0
  106. package/src/__tests__/Timer.test.ts +148 -57
  107. package/src/__tests__/rum/instrumentation/DdEventsInterceptor.test.tsx +151 -92
  108. package/src/__tests__/rum/instrumentation/DdRumErrorTracking.test.tsx +168 -116
  109. package/src/__tests__/rum/instrumentation/DdRumResourceTracking.test.tsx +789 -644
  110. package/src/__tests__/rum/instrumentation/DdRumUserInteractionTracking.test.tsx +239 -85
  111. package/src/__tests__/rum/instrumentation/ShallowObjectEqualityChecker.test.ts +31 -0
  112. package/src/__tests__/rum/instrumentation/TraceIdentifier.test.tsx +13 -15
  113. package/src/__tests__/rum/instrumentation/URLHostParser.test.ts +40 -0
  114. package/src/__tests__/rum/instrumentation/__utils__/XMLHttpRequestMock.ts +97 -0
  115. package/src/foundation.tsx +13 -10
  116. package/src/index.tsx +15 -4
  117. package/src/rum/instrumentation/DdEventsInterceptor.tsx +51 -35
  118. package/src/rum/instrumentation/DdRumErrorTracking.tsx +49 -44
  119. package/src/rum/instrumentation/DdRumResourceTracking.tsx +369 -234
  120. package/src/rum/instrumentation/DdRumUserInteractionTracking.tsx +72 -29
  121. package/src/rum/instrumentation/DdRumXhr.tsx +21 -11
  122. package/src/rum/instrumentation/EventsInterceptor.tsx +3 -3
  123. package/src/rum/instrumentation/NoOpEventsInterceptor.tsx +2 -2
  124. package/src/rum/instrumentation/ShallowObjectEqualityChecker.ts +24 -0
  125. package/src/rum/instrumentation/TraceIdentifier.tsx +19 -19
  126. package/src/rum/instrumentation/URLHostParser.ts +23 -0
  127. package/src/types.tsx +199 -158
  128. package/src/version.ts +1 -1
@@ -6,19 +6,22 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
6
6
  * Copyright 2016-Present Datadog, Inc.
7
7
  */
8
8
  import { Platform } from 'react-native';
9
- import { DdRum } from '../../foundation';
9
+ import { InternalLog } from '../../InternalLog';
10
+ import { SdkVerbosity } from '../../SdkVerbosity';
10
11
  import Timer from '../../Timer';
12
+ import { DdRum } from '../../foundation';
11
13
  import { generateTraceId } from './TraceIdentifier';
12
- import { InternalLog } from "../../InternalLog";
13
- import { SdkVerbosity } from "../../SdkVerbosity";
14
- export const TRACE_ID_HEADER_KEY = "x-datadog-trace-id";
15
- export const PARENT_ID_HEADER_KEY = "x-datadog-parent-id";
16
- export const ORIGIN_HEADER_KEY = "x-datadog-origin";
17
- export const SAMPLING_PRIORITY_HEADER_KEY = "x-datadog-sampling-priority";
18
- export const SAMPLED_HEADER_KEY = "x-datadog-sampled";
19
- export const ORIGIN_RUM = "rum";
20
- const RESPONSE_START_LABEL = "response_start";
21
- const MISSING_RESOURCE_SIZE = -1;
14
+ import { URLHostParser } from './URLHostParser';
15
+ export const TRACE_ID_HEADER_KEY = 'x-datadog-trace-id';
16
+ export const PARENT_ID_HEADER_KEY = 'x-datadog-parent-id';
17
+ export const ORIGIN_HEADER_KEY = 'x-datadog-origin';
18
+ export const SAMPLING_PRIORITY_HEADER_KEY = 'x-datadog-sampling-priority';
19
+ export const ORIGIN_RUM = 'rum';
20
+ export const RESOURCE_SIZE_ERROR_MESSAGE = "Couldn't get resource size, because an error occured: ";
21
+ const RESPONSE_START_LABEL = 'response_start';
22
+ const MISSING_RESOURCE_SIZE = -1; // This regex does not match anything
23
+
24
+ const NO_MATCH_REGEX = new RegExp('a^');
22
25
 
23
26
  function createTimings(startTime, responseStartTime, responseEndTime) {
24
27
  const firstByte = formatTiming(startTime, startTime, responseStartTime);
@@ -117,7 +120,7 @@ export function calculateResponseSize(xhr) {
117
120
  break;
118
121
  }
119
122
  } catch (e) {
120
- console.error("Couldn't get resource size, because of the error", e);
123
+ InternalLog.log(`${RESOURCE_SIZE_ERROR_MESSAGE}${e}`, SdkVerbosity.ERROR);
121
124
  }
122
125
 
123
126
  if (typeof size !== 'number') {
@@ -126,34 +129,80 @@ export function calculateResponseSize(xhr) {
126
129
 
127
130
  return size;
128
131
  }
132
+
133
+ const generateTracingAttributesWithSampling = tracingSamplingRate => {
134
+ if (Math.random() * 100 <= tracingSamplingRate) {
135
+ return {
136
+ traceId: generateTraceId(),
137
+ spanId: generateTraceId(),
138
+ samplingPriorityHeader: '1',
139
+ tracingStrategy: 'KEEP'
140
+ };
141
+ }
142
+
143
+ return {
144
+ samplingPriorityHeader: '0',
145
+ tracingStrategy: 'DISCARD'
146
+ };
147
+ };
148
+
149
+ const getFirstPartyHostsRegex = firstPartyHosts => {
150
+ if (firstPartyHosts.length === 0) {
151
+ return NO_MATCH_REGEX;
152
+ }
153
+
154
+ try {
155
+ // A regexp for matching hosts, e.g. when `hosts` is "example.com", it will match
156
+ // "example.com", "api.example.com", but not "foo.com".
157
+ const firstPartyHostsRegex = new RegExp(`^(.*\\.)*(${firstPartyHosts.map(host => `${host}$`).join('|')})`);
158
+ firstPartyHostsRegex.test('test_the_regex_is_valid');
159
+ return firstPartyHostsRegex;
160
+ } catch (e) {
161
+ InternalLog.log(`Invalid first party hosts list ${JSON.stringify(firstPartyHosts)}. Regular expressions are not allowed.`, SdkVerbosity.WARN);
162
+ return NO_MATCH_REGEX;
163
+ }
164
+ };
129
165
  /**
130
- * Provides RUM auto-instrumentation feature to track resources (fetch, XHR, axios) as RUM events.
131
- */
166
+ * Provides RUM auto-instrumentation feature to track resources (fetch, XHR, axios) as RUM events.
167
+ */
168
+
132
169
 
133
170
  export class DdRumResourceTracking {
171
+ // matches nothing by default
172
+
134
173
  /**
135
- * Starts tracking resources and sends a RUM Resource event every time a network request is detected.
136
- */
137
- static startTracking() {
138
- DdRumResourceTracking.startTrackingInternal(XMLHttpRequest);
174
+ * Starts tracking resources and sends a RUM Resource event every time a network request is detected.
175
+ */
176
+ static startTracking({
177
+ tracingSamplingRate,
178
+ firstPartyHosts
179
+ }) {
180
+ DdRumResourceTracking.startTrackingInternal(XMLHttpRequest, {
181
+ tracingSamplingRate,
182
+ firstPartyHosts
183
+ });
139
184
  }
140
185
  /**
141
- * Starts tracking resources and sends a RUM Resource event every time a fetch or XHR call is detected.
142
- */
143
- // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
186
+ * Starts tracking resources and sends a RUM Resource event every time a fetch or XHR call is detected.
187
+ */
144
188
 
145
189
 
146
- static startTrackingInternal(xhrType) {
190
+ static startTrackingInternal(xhrType, {
191
+ tracingSamplingRate,
192
+ firstPartyHosts
193
+ }) {
147
194
  // extra safety to avoid proxying the XHR class twice
148
195
  if (DdRumResourceTracking.isTracking) {
149
- InternalLog.log("Datadog SDK is already tracking XHR resources", SdkVerbosity.WARN);
196
+ InternalLog.log('Datadog SDK is already tracking XHR resources', SdkVerbosity.WARN);
150
197
  return;
151
198
  }
152
199
 
200
+ DdRumResourceTracking.tracingSamplingRate = tracingSamplingRate;
201
+ DdRumResourceTracking.firstPartyHostsRegex = getFirstPartyHostsRegex(firstPartyHosts);
153
202
  DdRumResourceTracking.originalXhrOpen = xhrType.prototype.open;
154
203
  DdRumResourceTracking.originalXhrSend = xhrType.prototype.send;
155
204
  DdRumResourceTracking.proxyXhr(xhrType);
156
- InternalLog.log("Datadog SDK is tracking XHR resources", SdkVerbosity.INFO);
205
+ InternalLog.log('Datadog SDK is tracking XHR resources', SdkVerbosity.INFO);
157
206
  }
158
207
 
159
208
  static stopTracking() {
@@ -162,6 +211,27 @@ export class DdRumResourceTracking {
162
211
  XMLHttpRequest.prototype.open = DdRumResourceTracking.originalXhrOpen;
163
212
  XMLHttpRequest.prototype.send = DdRumResourceTracking.originalXhrSend;
164
213
  }
214
+ }
215
+
216
+ static getTracingAttributes(url) {
217
+ try {
218
+ const hostname = URLHostParser(url);
219
+
220
+ if (DdRumResourceTracking.firstPartyHostsRegex.test(hostname)) {
221
+ return generateTracingAttributesWithSampling(DdRumResourceTracking.tracingSamplingRate);
222
+ }
223
+
224
+ return {
225
+ samplingPriorityHeader: '0',
226
+ tracingStrategy: 'DISCARD'
227
+ };
228
+ } catch (e) {
229
+ InternalLog.log(`Impossible to cast ${url} as URL`, SdkVerbosity.WARN);
230
+ return {
231
+ samplingPriorityHeader: '0',
232
+ tracingStrategy: 'DISCARD'
233
+ };
234
+ }
165
235
  } // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
166
236
 
167
237
 
@@ -176,15 +246,12 @@ export class DdRumResourceTracking {
176
246
  xhrType.prototype.open = function (method, url) {
177
247
  // Keep track of the method and url
178
248
  // start time is tracked by the `send` method
179
- const spanId = generateTraceId();
180
- const traceId = generateTraceId();
181
249
  this._datadog_xhr = {
182
250
  method,
183
- url: url,
251
+ url,
184
252
  reported: false,
185
253
  timer: new Timer(),
186
- spanId: spanId,
187
- traceId: traceId
254
+ tracingAttributes: DdRumResourceTracking.getTracingAttributes(url)
188
255
  }; // eslint-disable-next-line prefer-rest-params
189
256
 
190
257
  return originalXhrOpen.apply(this, arguments);
@@ -199,11 +266,14 @@ export class DdRumResourceTracking {
199
266
  // keep track of start time
200
267
  this._datadog_xhr.timer.start();
201
268
 
202
- this.setRequestHeader(TRACE_ID_HEADER_KEY, this._datadog_xhr.traceId);
203
- this.setRequestHeader(PARENT_ID_HEADER_KEY, this._datadog_xhr.spanId);
204
269
  this.setRequestHeader(ORIGIN_HEADER_KEY, ORIGIN_RUM);
205
- this.setRequestHeader(SAMPLING_PRIORITY_HEADER_KEY, "1");
206
- this.setRequestHeader(SAMPLED_HEADER_KEY, "1");
270
+ const tracingAttributes = this._datadog_xhr.tracingAttributes;
271
+ this.setRequestHeader(SAMPLING_PRIORITY_HEADER_KEY, tracingAttributes.samplingPriorityHeader);
272
+
273
+ if (tracingAttributes.tracingStrategy !== 'DISCARD') {
274
+ this.setRequestHeader(TRACE_ID_HEADER_KEY, tracingAttributes.traceId);
275
+ this.setRequestHeader(PARENT_ID_HEADER_KEY, tracingAttributes.spanId);
276
+ }
207
277
  }
208
278
 
209
279
  DdRumResourceTracking.proxyOnReadyStateChange(this, xhrType); // eslint-disable-next-line prefer-rest-params
@@ -235,14 +305,14 @@ export class DdRumResourceTracking {
235
305
  static reportXhr(xhrProxy) {
236
306
  const responseSize = calculateResponseSize(xhrProxy);
237
307
  const context = xhrProxy._datadog_xhr;
238
- const key = context.timer.startTime + "/" + context.method;
308
+ const key = `${context.timer.startTime}/${context.method}`;
239
309
  context.timer.stop();
240
- DdRum.startResource(key, context.method, context.url, {
241
- "_dd.span_id": context.spanId,
242
- "_dd.trace_id": context.traceId
310
+ DdRum.startResource(key, context.method, context.url, context.tracingAttributes.tracingStrategy === 'DISCARD' ? undefined : {
311
+ '_dd.span_id': context.tracingAttributes.spanId,
312
+ '_dd.trace_id': context.tracingAttributes.traceId
243
313
  }, context.timer.startTime).then(() => {
244
- DdRum.stopResource(key, xhrProxy.status, "xhr", responseSize, {
245
- "_dd.resource_timings": context.timer.hasTickFor(RESPONSE_START_LABEL) ? createTimings(context.timer.startTime, context.timer.timeAt(RESPONSE_START_LABEL), context.timer.stopTime) : null
314
+ DdRum.stopResource(key, xhrProxy.status, 'xhr', responseSize, {
315
+ '_dd.resource_timings': context.timer.hasTickFor(RESPONSE_START_LABEL) ? createTimings(context.timer.startTime, context.timer.timeAt(RESPONSE_START_LABEL), context.timer.stopTime) : null
246
316
  }, context.timer.stopTime);
247
317
  });
248
318
  }
@@ -251,6 +321,10 @@ export class DdRumResourceTracking {
251
321
 
252
322
  _defineProperty(DdRumResourceTracking, "isTracking", false);
253
323
 
324
+ _defineProperty(DdRumResourceTracking, "tracingSamplingRate", void 0);
325
+
326
+ _defineProperty(DdRumResourceTracking, "firstPartyHostsRegex", NO_MATCH_REGEX);
327
+
254
328
  _defineProperty(DdRumResourceTracking, "originalXhrOpen", void 0);
255
329
 
256
330
  _defineProperty(DdRumResourceTracking, "originalXhrSend", void 0);
@@ -1 +1 @@
1
- {"version":3,"sources":["DdRumResourceTracking.tsx"],"names":["Platform","DdRum","Timer","generateTraceId","InternalLog","SdkVerbosity","TRACE_ID_HEADER_KEY","PARENT_ID_HEADER_KEY","ORIGIN_HEADER_KEY","SAMPLING_PRIORITY_HEADER_KEY","SAMPLED_HEADER_KEY","ORIGIN_RUM","RESPONSE_START_LABEL","MISSING_RESOURCE_SIZE","createTimings","startTime","responseStartTime","responseEndTime","firstByte","formatTiming","download","fetch","origin","start","end","duration","timeToNanos","OS","durationMs","toFixed","byteLength","str","unescape","encodeURI","length","getResponseContentLengthFromHeader","xhr","contentLengthHeader","parseInt","getResponseHeader","isNaN","calculateResponseSize","response","size","responseType","JSON","stringify","e","console","error","DdRumResourceTracking","startTracking","startTrackingInternal","XMLHttpRequest","xhrType","isTracking","log","WARN","originalXhrOpen","prototype","open","originalXhrSend","send","proxyXhr","INFO","stopTracking","proxyOpen","proxySend","method","url","spanId","traceId","_datadog_xhr","reported","timer","apply","arguments","setRequestHeader","proxyOnReadyStateChange","xhrProxy","originalOnreadystatechange","onreadystatechange","readyState","DONE","reportXhr","HEADERS_RECEIVED","recordTick","responseSize","context","key","stop","startResource","then","stopResource","status","hasTickFor","timeAt","stopTime"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AAEA,SAASA,QAAT,QAAyB,cAAzB;AACA,SAASC,KAAT,QAAsB,kBAAtB;AACA,OAAOC,KAAP,MAAkB,aAAlB;AAEA,SAASC,eAAT,QAAgC,mBAAhC;AACA,SAAQC,WAAR,QAA0B,mBAA1B;AACA,SAAQC,YAAR,QAA2B,oBAA3B;AAEA,OAAO,MAAMC,mBAAmB,GAAG,oBAA5B;AACP,OAAO,MAAMC,oBAAoB,GAAG,qBAA7B;AACP,OAAO,MAA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ADF,EAEEV,QAAQ,CAACe,MAFX,EAGE,KAHF,EAIEP,YAJF,EAKE;AACE,gCAAwBC,OAAO,CAACd,KAAR,CAAcqB,UAAd,CAAyBnF,oBAAzB,IACtBE,aAAa,CACX0E,OAAO,CAACd,KAAR,CAAc3D,SADH,EAEXyE,OAAO,CAACd,KAAR,CAAcsB,MAAd,CAAqBpF,oBAArB,CAFW,EAGX4E,OAAO,CAACd,KAAR,CAAcuB,QAHH,CADS,GAKlB;AANR,OALF,EAaET,OAAO,CAACd,KAAR,CAAcuB,QAbhB;AAeD,KAzBD;AA0BD;;AA/IgC;;gBAAtB/C,qB,gBAEiB,K;;gBAFjBA,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';\nimport { DdRum } from '../../foundation'\nimport Timer from '../../Timer';\nimport type { DdRumXhr } from './DdRumXhr'\nimport { generateTraceId } from './TraceIdentifier'\nimport {InternalLog} from \"../../InternalLog\"\nimport {SdkVerbosity} from \"../../SdkVerbosity\"\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 SAMPLED_HEADER_KEY = \"x-datadog-sampled\"\nexport const ORIGIN_RUM = \"rum\"\n\nconst RESPONSE_START_LABEL = \"response_start\"\nconst MISSING_RESOURCE_SIZE = -1\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(startTime: number,\n responseStartTime: number, responseEndTime: number): ResourceTimings {\n\n const firstByte = formatTiming(startTime, startTime, responseStartTime)\n const download = formatTiming(startTime, responseStartTime, responseEndTime)\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: Platform.OS === 'ios' ? timeToNanos(start) : 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(xhr: XMLHttpRequest): number | null {\n const contentLengthHeader = parseInt(xhr.getResponseHeader('Content-Length') ?? '', 10);\n if (!isNaN(contentLengthHeader)) {\n return contentLengthHeader;\n }\n return null;\n}\n\nexport function calculateResponseSize(xhr: XMLHttpRequest): number {\n\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 console.error(\"Couldn't get resource size, because of the error\", e);\n }\n\n if (typeof size !== 'number') {\n return MISSING_RESOURCE_SIZE;\n }\n return size;\n}\n\n/**\n* Provides RUM auto-instrumentation feature to track resources (fetch, XHR, axios) as RUM events.\n*/\nexport class DdRumResourceTracking {\n\n private static isTracking = false\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(): void {\n DdRumResourceTracking.startTrackingInternal(XMLHttpRequest);\n }\n\n /**\n * Starts tracking resources and sends a RUM Resource event every time a fetch or XHR call is detected.\n */\n // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types\n static startTrackingInternal(xhrType: any): void {\n // extra safety to avoid proxying the XHR class twice\n if (DdRumResourceTracking.isTracking) {\n InternalLog.log(\"Datadog SDK is already tracking XHR resources\", SdkVerbosity.WARN);\n return\n }\n\n DdRumResourceTracking.originalXhrOpen = xhrType.prototype.open;\n DdRumResourceTracking.originalXhrSend = xhrType.prototype.send;\n\n DdRumResourceTracking.proxyXhr(xhrType);\n InternalLog.log(\"Datadog SDK is tracking XHR resources\", SdkVerbosity.INFO);\n }\n\n\n static stopTracking(): void {\n if (DdRumResourceTracking.isTracking) {\n DdRumResourceTracking.isTracking = false;\n XMLHttpRequest.prototype.open = DdRumResourceTracking.originalXhrOpen;\n XMLHttpRequest.prototype.send = DdRumResourceTracking.originalXhrSend;\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 (this: DdRumXhr, method: string, url: string) {\n // Keep track of the method and url\n // start time is tracked by the `send` method\n const spanId = generateTraceId()\n const traceId = generateTraceId()\n this._datadog_xhr = {\n method,\n url: url,\n reported: false,\n timer: new Timer(),\n spanId: spanId,\n traceId: traceId\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\n if (this._datadog_xhr) {\n // keep track of start time\n this._datadog_xhr.timer.start()\n this.setRequestHeader(TRACE_ID_HEADER_KEY, this._datadog_xhr.traceId)\n this.setRequestHeader(PARENT_ID_HEADER_KEY, this._datadog_xhr.spanId)\n this.setRequestHeader(ORIGIN_HEADER_KEY, ORIGIN_RUM)\n this.setRequestHeader(SAMPLING_PRIORITY_HEADER_KEY, \"1\")\n this.setRequestHeader(SAMPLED_HEADER_KEY, \"1\")\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(xhrProxy: DdRumXhr, xhrType: any): 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\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 {\n \"_dd.span_id\": context.spanId,\n \"_dd.trace_id\": context.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(RESPONSE_START_LABEL) ?\n createTimings(\n context.timer.startTime,\n context.timer.timeAt(RESPONSE_START_LABEL),\n context.timer.stopTime\n ) : null\n },\n context.timer.stopTime\n );\n })\n }\n\n}\n"]}
1
+ {"version":3,"sources":["DdRumResourceTracking.tsx"],"names":["Platform","InternalLog","SdkVerbosity","Timer","DdRum","generateTraceId","URLHostParser","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","OS","durationMs","toFixed","byteLength","str","unescape","encodeURI","length","getResponseContentLengthFromHeader","xhr","contentLengthHeader","parseInt","getResponseHeader","isNaN","calculateResponseSize","response","size","responseType","JSON","stringify","e","log","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","tracingAttributes","apply","arguments","setRequestHeader","proxyOnReadyStateChange","xhrProxy","originalOnreadystatechange","onreadystatechange","readyState","DONE","reportXhr","HEADERS_RECEIVED","recordTick","responseSize","context","key","stop","startResource","undefined","then","stopResource","status","hasTickFor","timeAt","stopTime"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AAEA,SAASA,QAAT,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TyF,OAAO,CAACf,KAAR,CAAczE,SADL,EAETwF,OAAO,CAACf,KAAR,CAAcwB,MAAd,CAAqBtG,oBAArB,CAFS,EAGT6F,OAAO,CAACf,KAAR,CAAcyB,QAHL,CAHK,GAQlB;AATV,OALJ,EAgBIV,OAAO,CAACf,KAAR,CAAcyB,QAhBlB;AAkBH,KA9BD;AA+BH;;AAxN8B;;gBAAtB/C,qB,gBACmB,K;;gBADnBA,qB;;gBAAAA,qB,0BAGqCtD,c;;gBAHrCsD,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"]}
@@ -6,15 +6,15 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
6
6
  * Copyright 2016-Present Datadog, Inc.
7
7
  */
8
8
  import React from 'react';
9
+ import { InternalLog } from '../../InternalLog';
10
+ import { SdkVerbosity } from '../../SdkVerbosity';
9
11
  import { DdEventsInterceptor } from './DdEventsInterceptor';
10
12
  import NoOpEventsInterceptor from './NoOpEventsInterceptor';
11
- import { InternalLog } from "../../InternalLog";
12
- import { SdkVerbosity } from "../../SdkVerbosity";
13
- const PROPERTY_FUNCTION_TYPE = "function";
13
+ import { areObjectShallowEqual } from './ShallowObjectEqualityChecker';
14
14
  /**
15
- * Provides RUM auto-instrumentation feature to track user interaction as RUM events.
16
- * For now we are only covering the "onPress" events.
17
- */
15
+ * Provides RUM auto-instrumentation feature to track user interaction as RUM events.
16
+ * For now we are only covering the "onPress" events.
17
+ */
18
18
 
19
19
  export class DdRumUserInteractionTracking {
20
20
  /**
@@ -25,33 +25,60 @@ export class DdRumUserInteractionTracking {
25
25
  static startTracking() {
26
26
  // extra safety to avoid wrapping more than 1 time this function
27
27
  if (DdRumUserInteractionTracking.isTracking) {
28
- InternalLog.log("Datadog SDK is already tracking interactions", SdkVerbosity.WARN);
28
+ InternalLog.log('Datadog SDK is already tracking interactions', SdkVerbosity.WARN);
29
29
  return;
30
30
  }
31
31
 
32
32
  DdRumUserInteractionTracking.eventsInterceptor = new DdEventsInterceptor();
33
33
  const original = React.createElement;
34
34
 
35
- React.createElement = function (element, props) {
35
+ React.createElement = (element, props, ...children) => {
36
36
  // check if we have an 'onPress' property and that this is really a function
37
- if (props && typeof props.onPress === PROPERTY_FUNCTION_TYPE) {
37
+ if (props && typeof props.onPress === 'function') {
38
38
  const originalOnPress = props.onPress;
39
39
 
40
- props.onPress = function () {
41
- DdRumUserInteractionTracking.eventsInterceptor.interceptOnPress(...arguments);
42
- return originalOnPress(...arguments);
43
- };
44
- }
40
+ props.onPress = (...args) => {
41
+ DdRumUserInteractionTracking.eventsInterceptor.interceptOnPress(...args);
42
+ return originalOnPress(...args);
43
+ }; // we store the original onPress prop so we can keep memoization working
45
44
 
46
- for (var _len = arguments.length, children = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
47
- children[_key - 2] = arguments[_key];
45
+
46
+ props.__DATADOG_INTERNAL_ORIGINAL_ON_PRESS__ = originalOnPress;
48
47
  }
49
48
 
50
49
  return original(element, props, ...children);
51
50
  };
52
51
 
52
+ const originalMemo = React.memo;
53
+
54
+ React.memo = (component, propsAreEqual) => {
55
+ return originalMemo(component, (prev, next) => {
56
+ if (!next.onPress || !prev.onPress) {
57
+ return propsAreEqual ? propsAreEqual(prev, next) : areObjectShallowEqual(prev, next);
58
+ } // we replace "our" onPress from the props by the original for comparison
59
+
60
+
61
+ const {
62
+ onPress: _prevOnPress,
63
+ ...partialPrevProps
64
+ } = prev;
65
+ const prevProps = { ...partialPrevProps,
66
+ onPress: prev.__DATADOG_INTERNAL_ORIGINAL_ON_PRESS__
67
+ };
68
+ const {
69
+ onPress: _nextOnPress,
70
+ ...partialNextProps
71
+ } = next;
72
+ const nextProps = { ...partialNextProps,
73
+ onPress: next.__DATADOG_INTERNAL_ORIGINAL_ON_PRESS__
74
+ }; // if no comparison function is provided we do shallow comparison
75
+
76
+ return propsAreEqual ? propsAreEqual(prevProps, nextProps) : areObjectShallowEqual(nextProps, prevProps);
77
+ });
78
+ };
79
+
53
80
  DdRumUserInteractionTracking.isTracking = true;
54
- InternalLog.log("Datadog SDK is tracking interactions", SdkVerbosity.INFO);
81
+ InternalLog.log('Datadog SDK is tracking interactions', SdkVerbosity.INFO);
55
82
  }
56
83
 
57
84
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["DdRumUserInteractionTracking.tsx"],"names":["React","DdEventsInterceptor","NoOpEventsInterceptor","InternalLog","SdkVerbosity","PROPERTY_FUNCTION_TYPE","DdRumUserInteractionTracking","startTracking","isTracking","log","WARN","eventsInterceptor","original","createElement","element","props","onPress","originalOnPress","interceptOnPress","children","INFO"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AAEA,OAAOA,KAAP,MAAkB,OAAlB;AACA,SAASC,mBAAT,QAAoC,uBAApC;AACA,OAAOC,qBAAP,MAAkC,yBAAlC;AAEA,SAAQC,WAAR,QAA0B,mBAA1B;AACA,SAAQC,YAAR,QAA2B,oBAA3B;AAGA,MAAMC,sBAAsB,GAAG,UAA/B;AAEA;AACA;AACA;AACA;;AACA,OAAO,MAAMC,4BAAN,CAAmC;AAKtC;AACJ;AACA;AACA;AACA;AACwB,SAAbC,aAAa,GAAS;AACzB;AACA,QAAID,4BAA4B,CAACE,UAAjC,EAA6C;AACzCL,MAAAA,WAAW,CAACM,GAAZ,CAAgB,8CAAhB,EAAgEL,YAAY,CAACM,IAA7E;AACA;AACH;;AACDJ,IAAAA,4BAA4B,CAACK,iBAA7B,GAAiD,IAAIV,mBAAJ,EAAjD;AACA,UAAMW,QAAQ,GAAGZ,KAAK,CAACa,aAAvB;;AACAb,IAAAA,KAAK,CAACa,aAAN,GAAsB,UAACC,OAAD,EAAeC,KAAf,EAAqD;AACvE;AACA,UAAIA,KAAK,IAAI,OAAOA,KAAK,CAACC,OAAb,KAAyBX,sBAAtC,EAA8D;AAC1D,cAAMY,eAAe,GAAGF,KAAK,CAACC,OAA9B;;AACAD,QAAAA,KAAK,CAACC,OAAN,GAAgB,YAAoB;AAChCV,UAAAA,4BAA4B,CAACK,iBAA7B,CAA+CO,gBAA/C,CAAgE,YAAhE;AACA,iBAAOD,eAAe,CAAC,YAAD,CAAtB;AACH,SAHD;AAIH;;AARsE,wCAAvBE,QAAuB;AAAvBA,QAAAA,QAAuB;AAAA;;AASvE,aAAOP,QAAQ,CAACE,OAAD,EAAUC,KAAV,EAAiB,GAAGI,QAApB,CAAf;AACH,KAVD;;AAWAb,IAAAA,4BAA4B,CAACE,UAA7B,GAA0C,IAA1C;AACAL,IAAAA,WAAW,CAACM,GAAZ,CAAgB,sCAAhB,EAAwDL,YAAY,CAACgB,IAArE;AACH;;AA/BqC;;gBAA7Bd,4B,gBAEmB,K;;gBAFnBA,4B,uBAG6C,IAAIJ,qBAAJ,E","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 React from 'react'\nimport { DdEventsInterceptor } from './DdEventsInterceptor'\nimport NoOpEventsInterceptor from './NoOpEventsInterceptor'\nimport type EventsInterceptor from './EventsInterceptor'\nimport {InternalLog} from \"../../InternalLog\"\nimport {SdkVerbosity} from \"../../SdkVerbosity\"\n\n\nconst PROPERTY_FUNCTION_TYPE = \"function\"\n\n/**\n* Provides RUM auto-instrumentation feature to track user interaction as RUM events.\n* For now we are only covering the \"onPress\" events.\n*/\nexport class DdRumUserInteractionTracking {\n\n private static isTracking = false\n private static eventsInterceptor: EventsInterceptor = new NoOpEventsInterceptor()\n\n /**\n * Starts tracking user interactions and sends a RUM Action event every time a new interaction was detected.\n * Please note that we are only considering as valid - for - tracking only the user interactions that have\n * a visible output (either an UI state change or a Resource request)\n */\n static startTracking(): void {\n // extra safety to avoid wrapping more than 1 time this function\n if (DdRumUserInteractionTracking.isTracking) {\n InternalLog.log(\"Datadog SDK is already tracking interactions\", SdkVerbosity.WARN);\n return\n }\n DdRumUserInteractionTracking.eventsInterceptor = new DdEventsInterceptor()\n const original = React.createElement\n React.createElement = (element: any, props: any, ...children: any): any => {\n // check if we have an 'onPress' property and that this is really a function\n if (props && typeof props.onPress === PROPERTY_FUNCTION_TYPE) {\n const originalOnPress = props.onPress\n props.onPress = (...args: any[]) => {\n DdRumUserInteractionTracking.eventsInterceptor.interceptOnPress(...args)\n return originalOnPress(...args)\n }\n }\n return original(element, props, ...children)\n }\n DdRumUserInteractionTracking.isTracking = true\n InternalLog.log(\"Datadog SDK is tracking interactions\", SdkVerbosity.INFO);\n }\n\n}\n\n"]}
1
+ {"version":3,"sources":["DdRumUserInteractionTracking.tsx"],"names":["React","InternalLog","SdkVerbosity","DdEventsInterceptor","NoOpEventsInterceptor","areObjectShallowEqual","DdRumUserInteractionTracking","startTracking","isTracking","log","WARN","eventsInterceptor","original","createElement","element","props","children","onPress","originalOnPress","args","interceptOnPress","__DATADOG_INTERNAL_ORIGINAL_ON_PRESS__","originalMemo","memo","component","propsAreEqual","prev","next","_prevOnPress","partialPrevProps","prevProps","_nextOnPress","partialNextProps","nextProps","INFO"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AAEA,OAAOA,KAAP,MAAkB,OAAlB;AAEA,SAASC,WAAT,QAA4B,mBAA5B;AACA,SAASC,YAAT,QAA6B,oBAA7B;AAEA,SAASC,mBAAT,QAAoC,uBAApC;AAEA,OAAOC,qBAAP,MAAkC,yBAAlC;AACA,SAASC,qBAAT,QAAsC,gCAAtC;AAEA;AACA;AACA;AACA;;AACA,OAAO,MAAMC,4BAAN,CAAmC;AAItC;AACJ;AACA;AACA;AACA;AACwB,SAAbC,aAAa,GAAS;AACzB;AACA,QAAID,4BA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EW,YAAX;AAAyB,aAAGC;AAA5B,YAAiDH,IAAvD;AACA,cAAMI,SAAS,GAAG,EACd,GAAGD,gBADW;AAEdZ,UAAAA,OAAO,EAAES,IAAI,CAACL;AAFA,SAAlB;AAKA,cAAM;AAAEJ,UAAAA,OAAO,EAAEc,YAAX;AAAyB,aAAGC;AAA5B,YAAiDL,IAAvD;AACA,cAAMM,SAAS,GAAG,EACd,GAAGD,gBADW;AAEdf,UAAAA,OAAO,EAAEU,IAAI,CAACN;AAFA,SAAlB,CAd2C,CAmB3C;;AACA,eAAOI,aAAa,GACdA,aAAa,CAACK,SAAD,EAAYG,SAAZ,CADC,GAEd5B,qBAAqB,CAAC4B,SAAD,EAAYH,SAAZ,CAF3B;AAGH,OAvBkB,CAAnB;AAwBH,KA5BD;;AA8BAxB,IAAAA,4BAA4B,CAACE,UAA7B,GAA0C,IAA1C;AACAP,IAAAA,WAAW,CAACQ,GAAZ,CACI,sCADJ,EAEIP,YAAY,CAACgC,IAFjB;AAIH;;AA5EqC;;gBAA7B5B,4B,gBACmB,K;;gBADnBA,4B,uBAE6C,IAAIF,qBAAJ,E","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 React from 'react';\n\nimport { InternalLog } from '../../InternalLog';\nimport { SdkVerbosity } from '../../SdkVerbosity';\n\nimport { DdEventsInterceptor } from './DdEventsInterceptor';\nimport type EventsInterceptor from './EventsInterceptor';\nimport NoOpEventsInterceptor from './NoOpEventsInterceptor';\nimport { areObjectShallowEqual } from './ShallowObjectEqualityChecker';\n\n/**\n * Provides RUM auto-instrumentation feature to track user interaction as RUM events.\n * For now we are only covering the \"onPress\" events.\n */\nexport class DdRumUserInteractionTracking {\n private static isTracking = false;\n private static eventsInterceptor: EventsInterceptor = new NoOpEventsInterceptor();\n\n /**\n * Starts tracking user interactions and sends a RUM Action event every time a new interaction was detected.\n * Please note that we are only considering as valid - for - tracking only the user interactions that have\n * a visible output (either an UI state change or a Resource request)\n */\n static startTracking(): void {\n // extra safety to avoid wrapping more than 1 time this function\n if (DdRumUserInteractionTracking.isTracking) {\n InternalLog.log(\n 'Datadog SDK is already tracking interactions',\n SdkVerbosity.WARN\n );\n return;\n }\n DdRumUserInteractionTracking.eventsInterceptor = new DdEventsInterceptor();\n const original = React.createElement;\n React.createElement = (\n element: any,\n props: any,\n ...children: any\n ): any => {\n // check if we have an 'onPress' property and that this is really a function\n if (props && typeof props.onPress === 'function') {\n const originalOnPress = props.onPress;\n props.onPress = (...args: any[]) => {\n DdRumUserInteractionTracking.eventsInterceptor.interceptOnPress(\n ...args\n );\n return originalOnPress(...args);\n };\n // we store the original onPress prop so we can keep memoization working\n props.__DATADOG_INTERNAL_ORIGINAL_ON_PRESS__ = originalOnPress;\n }\n return original(element, props, ...children);\n };\n\n const originalMemo = React.memo;\n React.memo = (\n component: any,\n propsAreEqual?: (prevProps: any, newProps: any) => boolean\n ) => {\n return originalMemo(component, (prev, next) => {\n if (!next.onPress || !prev.onPress) {\n return propsAreEqual\n ? propsAreEqual(prev, next)\n : areObjectShallowEqual(prev, next);\n }\n // we replace \"our\" onPress from the props by the original for comparison\n const { onPress: _prevOnPress, ...partialPrevProps } = prev;\n const prevProps = {\n ...partialPrevProps,\n onPress: prev.__DATADOG_INTERNAL_ORIGINAL_ON_PRESS__\n };\n\n const { onPress: _nextOnPress, ...partialNextProps } = next;\n const nextProps = {\n ...partialNextProps,\n onPress: next.__DATADOG_INTERNAL_ORIGINAL_ON_PRESS__\n };\n\n // if no comparison function is provided we do shallow comparison\n return propsAreEqual\n ? propsAreEqual(prevProps, nextProps)\n : areObjectShallowEqual(nextProps, prevProps);\n });\n };\n\n DdRumUserInteractionTracking.isTracking = true;\n InternalLog.log(\n 'Datadog SDK is tracking interactions',\n SdkVerbosity.INFO\n );\n }\n}\n"]}
@@ -1,2 +1,2 @@
1
- export {};
1
+
2
2
  //# sourceMappingURL=DdRumXhr.js.map
@@ -5,7 +5,7 @@
5
5
  */
6
6
  export default class NoOpEventsInterceptor {
7
7
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
8
- interceptOnPress() {// NoOp
8
+ interceptOnPress(..._args) {// NoOp
9
9
  }
10
10
 
11
11
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["NoOpEventsInterceptor.tsx"],"names":["NoOpEventsInterceptor","interceptOnPress"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AAIA,eAAe,MAAMA,qBAAN,CAAyD;AACpE;AACAC,EAAAA,gBAAgB,GAAwB,CACpC;AACH;;AAJmE","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 type EventsInterceptor from './EventsInterceptor'\n\nexport default class NoOpEventsInterceptor implements EventsInterceptor {\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n interceptOnPress(..._args: any[]): void {\n // NoOp\n }\n}"]}
1
+ {"version":3,"sources":["NoOpEventsInterceptor.tsx"],"names":["NoOpEventsInterceptor","interceptOnPress","_args"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AAIA,eAAe,MAAMA,qBAAN,CAAyD;AACpE;AACAC,EAAAA,gBAAgB,CAAC,GAAGC,KAAJ,EAAwB,CACpC;AACH;;AAJmE","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 type EventsInterceptor from './EventsInterceptor';\n\nexport default class NoOpEventsInterceptor implements EventsInterceptor {\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n interceptOnPress(..._args: any[]): void {\n // NoOp\n }\n}\n"]}
@@ -0,0 +1,25 @@
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
+ /**
8
+ * Does a shallow comparison between 2 objects
9
+ */
10
+ export const areObjectShallowEqual = (objectA, objectB) => {
11
+ const keys = Object.keys(objectA);
12
+
13
+ if (keys.length !== Object.keys(objectB).length) {
14
+ return false;
15
+ }
16
+
17
+ for (const key of keys) {
18
+ if (objectA[key] !== objectB[key]) {
19
+ return false;
20
+ }
21
+ }
22
+
23
+ return true;
24
+ };
25
+ //# sourceMappingURL=ShallowObjectEqualityChecker.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["ShallowObjectEqualityChecker.ts"],"names":["areObjectShallowEqual","objectA","objectB","keys","Object","length","key"],"mappings":"AAAA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA,OAAO,MAAMA,qBAAqB,GAAG,CACjCC,OADiC,EAEjCC,OAFiC,KAGvB;AACV,QAAMC,IAAI,GAAGC,MAAM,CAACD,IAAP,CAAYF,OAAZ,CAAb;;AACA,MAAIE,IAAI,CAACE,MAAL,KAAgBD,MAAM,CAACD,IAAP,CAAYD,OAAZ,EAAqBG,MAAzC,EAAiD;AAC7C,WAAO,KAAP;AACH;;AACD,OAAK,MAAMC,GAAX,IAAkBH,IAAlB,EAAwB;AACpB,QAAIF,OAAO,CAACK,GAAD,CAAP,KAAiBJ,OAAO,CAACI,GAAD,CAA5B,EAAmC;AAC/B,aAAO,KAAP;AACH;AACJ;;AACD,SAAO,IAAP;AACH,CAdM","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 * Does a shallow comparison between 2 objects\n */\nexport const areObjectShallowEqual = (\n objectA: Record<string, unknown>,\n objectB: Record<string, unknown>\n): boolean => {\n const keys = Object.keys(objectA);\n if (keys.length !== Object.keys(objectB).length) {\n return false;\n }\n for (const key of keys) {\n if (objectA[key] !== objectB[key]) {\n return false;\n }\n }\n return true;\n};\n"]}
@@ -1 +1 @@
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;AAEA,OAAO,SAASA,eAAT,GAAmC;AACxC,QAAMC,KAAK,GAAG,EAAd;AACA,QAAMC,kBAAkB,GAAG,UAA3B,CAFwC,CAEF;;AACtC,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;AAC1B;AACA;AACA,UAAMM,IAAI,GAAGF,IAAI,GAAGN,KAApB;AACA,UAAMS,IAAI,GAAG,CAAED,IAAD,IAAU,EAAX,IAAiBN,GAA9B;AACA,UAAMQ,KAAK,GAAGD,IAAI,GAAGT,KAArB,CAL0B,CAO1B;;AACAM,IAAAA,IAAI,GAAG,CAACA,IAAI,GAAGE,IAAR,IAAgBR,KAAvB,CAR0B,CAQG;AAC7B;;AACAE,IAAAA,GAAG,GAAG,CAACO,IAAI,GAAGC,KAAR,IAAiBV,KAAvB,CAV0B,CAUG;AAE7B;;AACAO,IAAAA,GAAG,GAAGG,KAAK,CAACC,QAAN,KAAmBJ,GAAzB;AACD;;AACD,SAAOA,GAAP;AACD","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
+ {"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;AAEA,OAAO,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"]}
@@ -0,0 +1,24 @@
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
+ // matches what is between the first "://" and the next "/", ":" or whitespace
7
+ const hostRegex = '^.+://([^:/\\s]+)';
8
+ /**
9
+ * Returns the host from an URL.
10
+ * @returns the host (without the port)
11
+ * @throws if URL is not well formatted
12
+ */
13
+
14
+ export const URLHostParser = url => {
15
+ const matchedHost = url.match(hostRegex);
16
+
17
+ if (matchedHost === null) {
18
+ throw new Error(`${url} is not a correctly formatted URL`);
19
+ } // [0] is the input, [1] is the captured group
20
+
21
+
22
+ return matchedHost[1];
23
+ };
24
+ //# sourceMappingURL=URLHostParser.js.map
@@ -0,0 +1 @@
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;;AACA,OAAO,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"]}
@@ -1 +1 @@
1
- {"version":3,"sources":["types.tsx"],"names":["DdSdkConfiguration","constructor","clientToken","env","applicationId","nativeCrashReportEnabled","sampleRate","site","trackingConsent","additionalConfig"],"mappings":"AAAA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA,OAAO,MAAMA,kBAAN,CAAyB;AAC9BC,EAAAA,WAAW,CACAC,WADA,EAEAC,GAFA,EAGAC,aAHA,EAIAC,wBAJA,EAKAC,UALA,EAMAC,IANA,EAOAC,eAPA,EAQAC,gBARA,EAST;AAAA,SARSP,WAQT,GARSA,WAQT;AAAA,SAPSC,GAOT,GAPSA,GAOT;AAAA,SANSC,aAMT,GANSA,aAMT;AAAA,SALSC,wBAKT,GALSA,wBAKT;AAAA,SAJSC,UAIT,GAJSA,UAIT;AAAA,SAHSC,IAGT,GAHSA,IAGT;AAAA,SAFSC,eAET,GAFSA,eAET;AAAA,SADSC,gBACT,GADSA,gBACT;AAAE;;AAV0B;AAahC;AACA;AACA","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 * A configuration object to initialize Datadog's features.\n */\nexport class DdSdkConfiguration {\n constructor(\n readonly clientToken: string,\n readonly env: string,\n readonly applicationId: string,\n readonly nativeCrashReportEnabled: boolean,\n readonly sampleRate: number,\n readonly site: string,\n readonly trackingConsent: string,\n readonly additionalConfig: object\n ) {}\n}\n\n/**\n * The entry point to initialize Datadog's features.\n */\nexport type DdSdkType = {\n /**\n * Initializes Datadog's features.\n * @param configuration: The configuration to use.\n */\n initialize(configuration: DdSdkConfiguration): Promise<void>;\n\n /**\n * Sets the global context (set of attributes) attached with all future Logs, Spans and RUM events.\n * @param attributes: The global context attributes.\n */\n setAttributes(attributes: object): Promise<void>;\n\n /**\n * Set the user information.\n * @param user: The user object (use builtin attributes: 'id', 'email', 'name', and/or any custom attribute).\n */\n setUser(user: object): Promise<void>;\n\n /**\n * Set the tracking consent regarding the data collection.\n * @param trackingConsent: Consent, which can take one of the following values: 'pending', 'granted', 'not_granted'.\n */\n setTrackingConsent(trackingConsent: string): Promise<void>;\n\n};\n\n/**\n * The entry point to use Datadog's Logs feature.\n */\nexport type DdLogsType = {\n /**\n * Send a log with level debug.\n * @param message: The message to send.\n * @param context: The additional context to send.\n */\n debug(message: string, context?: object): Promise<void>;\n\n /**\n * Send a log with level info.\n * @param message: The message to send.\n * @param context: The additional context to send.\n */\n info(message: string, context?: object): Promise<void>;\n\n /**\n * Send a log with level warn.\n * @param message: The message to send.\n * @param context: The additional context to send.\n */\n warn(message: string, context?: object): Promise<void>;\n\n /**\n * Send a log with level error.\n * @param message: The message to send.\n * @param context: The additional context to send.\n */\n error(message: string, context?: object): Promise<void>;\n\n};\n\n/**\n * The entry point to use Datadog's Trace feature.\n */\nexport type DdTraceType = {\n /**\n * Start a span, and returns a unique identifier for the span.\n * @param operation: The operation name of the span.\n * @param context: The additional context to send.\n * @param timestampMs: The timestamp when the operation started (in milliseconds). If not provided, current timestamp will be used.\n */\n startSpan(operation: string, context?: object, timestampMs?: number): Promise<string>;\n\n /**\n * Finish a started span.\n * @param spanId: The unique identifier of the span.\n * @param context: The additional context to send.\n * @param timestampMs: The timestamp when the operation stopped (in milliseconds). If not provided, current timestamp will be used.\n */\n finishSpan(spanId: string, context?: object, timestampMs?: number): Promise<void>;\n\n};\n\n/**\n * The entry point to use Datadog's RUM feature.\n */\nexport type DdRumType = {\n /**\n * Start tracking a RUM View.\n * @param key: The view unique key identifier.\n * @param name: The view name.\n * @param context: The additional context to send.\n * @param timestampMs: The timestamp when the view started (in milliseconds). If not provided, current timestamp will be used.\n */\n startView(key: string, name: string, context?: object, timestampMs?: number): Promise<void>;\n\n /**\n * Stop tracking a RUM View.\n * @param key: The view unique key identifier.\n * @param context: The additional context to send.\n * @param timestampMs: The timestamp when the view stopped (in milliseconds). If not provided, current timestamp will be used.\n */\n stopView(key: string, context?: object, timestampMs?: number): Promise<void>;\n\n /**\n * Start tracking a RUM Action.\n * @param type: The action type (tap, scroll, swipe, click, custom).\n * @param name: The action name.\n * @param context: The additional context to send.\n * @param timestampMs: The timestamp when the action started (in milliseconds). If not provided, current timestamp will be used.\n */\n startAction(type: string, name: string, context?: object, timestampMs?: number): Promise<void>;\n\n /**\n * Stop tracking the ongoing RUM Action.\n * @param context: The additional context to send.\n * @param timestampMs: The timestamp when the action stopped (in milliseconds). If not provided, current timestamp will be used.\n */\n stopAction(context?: object, timestampMs?: number): Promise<void>;\n\n /**\n * Add a RUM Action.\n * @param type: The action type (tap, scroll, swipe, click, custom).\n * @param name: The action name.\n * @param context: The additional context to send.\n * @param timestampMs: The timestamp when the action occurred (in milliseconds). If not provided, current timestamp will be used.\n */\n addAction(type: string, name: string, context?: object, timestampMs?: number): Promise<void>;\n\n /**\n * Start tracking a RUM Resource.\n * @param key: The resource unique key identifier.\n * @param method: The resource method (GET, POST, …).\n * @param url: The resource url.\n * @param context: The additional context to send.\n * @param timestampMs: The timestamp when the resource started (in milliseconds). If not provided, current timestamp will be used.\n */\n startResource(key: string, method: string, url: string, context?: object, timestampMs?: number): Promise<void>;\n\n /**\n * Stop tracking a RUM Resource.\n * @param key: The resource unique key identifier.\n * @param statusCode: The resource status code.\n * @param kind: The resource's kind (xhr, document, image, css, font, …).\n * @param size: The resource size in bytes. If size is unknown, use -1.\n * @param context: The additional context to send.\n * @param timestampMs: The timestamp when the resource stopped (in milliseconds). If not provided, current timestamp will be used.\n */\n stopResource(key: string, statusCode: number, kind: string, size?: number, context?: object, timestampMs?: number): Promise<void>;\n\n /**\n * Add a RUM Error.\n * @param message: The error message.\n * @param source: The error source (network, source, console, logger, …).\n * @param stacktrace: The error stacktrace.\n * @param context: The additional context to send.\n * @param timestampMs: The timestamp when the error occurred (in milliseconds). If not provided, current timestamp will be used.\n */\n addError(message: string, source: string, stacktrace: string, context?: object, timestampMs?: number): Promise<void>;\n\n /**\n * 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.\n * @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.\n */\n addTiming(name: string): Promise<void>;\n\n};\n\n"]}
1
+ {"version":3,"sources":["types.tsx"],"names":["DdSdkConfiguration","constructor","clientToken","env","applicationId","nativeCrashReportEnabled","sampleRate","site","trackingConsent","additionalConfig"],"mappings":"AAAA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA,OAAO,MAAMA,kBAAN,CAAyB;AAC5BC,EAAAA,WAAW,CACEC,WADF,EAEEC,GAFF,EAGEC,aAHF,EAIEC,wBAJF,EAKEC,UALF,EAMEC,IANF,EAOEC,eAPF,EAQEC,gBARF,EAST;AAAA,SARWP,WAQX,GARWA,WAQX;AAAA,SAPWC,GAOX,GAPWA,GAOX;AAAA,SANWC,aAMX,GANWA,aAMX;AAAA,SALWC,wBAKX,GALWA,wBAKX;AAAA,SAJWC,UAIX,GAJWA,UAIX;AAAA,SAHWC,IAGX,GAHWA,IAGX;AAAA,SAFWC,eAEX,GAFWA,eAEX;AAAA,SADWC,gBACX,GADWA,gBACX;AAAE;;AAVwB;AAahC;AACA;AACA","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 * A configuration object to initialize Datadog's features.\n */\nexport class DdSdkConfiguration {\n constructor(\n readonly clientToken: string,\n readonly env: string,\n readonly applicationId: string,\n readonly nativeCrashReportEnabled: boolean,\n readonly sampleRate: number,\n readonly site: string,\n readonly trackingConsent: string,\n readonly additionalConfig: object\n ) {}\n}\n\n/**\n * The entry point to initialize Datadog's features.\n */\nexport type DdSdkType = {\n /**\n * Initializes Datadog's features.\n * @param configuration: The configuration to use.\n */\n initialize(configuration: DdSdkConfiguration): Promise<void>;\n\n /**\n * Sets the global context (set of attributes) attached with all future Logs, Spans and RUM events.\n * @param attributes: The global context attributes.\n */\n setAttributes(attributes: object): Promise<void>;\n\n /**\n * Set the user information.\n * @param user: The user object (use builtin attributes: 'id', 'email', 'name', and/or any custom attribute).\n */\n setUser(user: object): Promise<void>;\n\n /**\n * Set the tracking consent regarding the data collection.\n * @param trackingConsent: Consent, which can take one of the following values: 'pending', 'granted', 'not_granted'.\n */\n setTrackingConsent(trackingConsent: string): Promise<void>;\n};\n\n/**\n * The entry point to use Datadog's Logs feature.\n */\nexport type DdLogsType = {\n /**\n * Send a log with level debug.\n * @param message: The message to send.\n * @param context: The additional context to send.\n */\n debug(message: string, context?: object): Promise<void>;\n\n /**\n * Send a log with level info.\n * @param message: The message to send.\n * @param context: The additional context to send.\n */\n info(message: string, context?: object): Promise<void>;\n\n /**\n * Send a log with level warn.\n * @param message: The message to send.\n * @param context: The additional context to send.\n */\n warn(message: string, context?: object): Promise<void>;\n\n /**\n * Send a log with level error.\n * @param message: The message to send.\n * @param context: The additional context to send.\n */\n error(message: string, context?: object): Promise<void>;\n};\n\n/**\n * The entry point to use Datadog's Trace feature.\n */\nexport type DdTraceType = {\n /**\n * Start a span, and returns a unique identifier for the span.\n * @param operation: The operation name of the span.\n * @param context: The additional context to send.\n * @param timestampMs: The timestamp when the operation started (in milliseconds). If not provided, current timestamp will be used.\n */\n startSpan(\n operation: string,\n context?: object,\n timestampMs?: number\n ): Promise<string>;\n\n /**\n * Finish a started span.\n * @param spanId: The unique identifier of the span.\n * @param context: The additional context to send.\n * @param timestampMs: The timestamp when the operation stopped (in milliseconds). If not provided, current timestamp will be used.\n */\n finishSpan(\n spanId: string,\n context?: object,\n timestampMs?: number\n ): Promise<void>;\n};\n\n/**\n * The entry point to use Datadog's RUM feature.\n */\nexport type DdRumType = {\n /**\n * Start tracking a RUM View.\n * @param key: The view unique key identifier.\n * @param name: The view name.\n * @param context: The additional context to send.\n * @param timestampMs: The timestamp when the view started (in milliseconds). If not provided, current timestamp will be used.\n */\n startView(\n key: string,\n name: string,\n context?: object,\n timestampMs?: number\n ): Promise<void>;\n\n /**\n * Stop tracking a RUM View.\n * @param key: The view unique key identifier.\n * @param context: The additional context to send.\n * @param timestampMs: The timestamp when the view stopped (in milliseconds). If not provided, current timestamp will be used.\n */\n stopView(\n key: string,\n context?: object,\n timestampMs?: number\n ): Promise<void>;\n\n /**\n * Start tracking a RUM Action.\n * @param type: The action type (tap, scroll, swipe, click, custom).\n * @param name: The action name.\n * @param context: The additional context to send.\n * @param timestampMs: The timestamp when the action started (in milliseconds). If not provided, current timestamp will be used.\n */\n startAction(\n type: string,\n name: string,\n context?: object,\n timestampMs?: number\n ): Promise<void>;\n\n /**\n * Stop tracking the ongoing RUM Action.\n * @param context: The additional context to send.\n * @param timestampMs: The timestamp when the action stopped (in milliseconds). If not provided, current timestamp will be used.\n */\n stopAction(context?: object, timestampMs?: number): Promise<void>;\n\n /**\n * Add a RUM Action.\n * @param type: The action type (tap, scroll, swipe, click, custom).\n * @param name: The action name.\n * @param context: The additional context to send.\n * @param timestampMs: The timestamp when the action occurred (in milliseconds). If not provided, current timestamp will be used.\n */\n addAction(\n type: string,\n name: string,\n context?: object,\n timestampMs?: number\n ): Promise<void>;\n\n /**\n * Start tracking a RUM Resource.\n * @param key: The resource unique key identifier.\n * @param method: The resource method (GET, POST, …).\n * @param url: The resource url.\n * @param context: The additional context to send.\n * @param timestampMs: The timestamp when the resource started (in milliseconds). If not provided, current timestamp will be used.\n */\n startResource(\n key: string,\n method: string,\n url: string,\n context?: object,\n timestampMs?: number\n ): Promise<void>;\n\n /**\n * Stop tracking a RUM Resource.\n * @param key: The resource unique key identifier.\n * @param statusCode: The resource status code.\n * @param kind: The resource's kind (xhr, document, image, css, font, …).\n * @param size: The resource size in bytes. If size is unknown, use -1.\n * @param context: The additional context to send.\n * @param timestampMs: The timestamp when the resource stopped (in milliseconds). If not provided, current timestamp will be used.\n */\n stopResource(\n key: string,\n statusCode: number,\n kind: string,\n size?: number,\n context?: object,\n timestampMs?: number\n ): Promise<void>;\n\n /**\n * Add a RUM Error.\n * @param message: The error message.\n * @param source: The error source (network, source, console, logger, …).\n * @param stacktrace: The error stacktrace.\n * @param context: The additional context to send.\n * @param timestampMs: The timestamp when the error occurred (in milliseconds). If not provided, current timestamp will be used.\n */\n addError(\n message: string,\n source: string,\n stacktrace: string,\n context?: object,\n timestampMs?: number\n ): Promise<void>;\n\n /**\n * 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.\n * @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.\n */\n addTiming(name: string): Promise<void>;\n};\n"]}