@datadog/mobile-react-native 1.0.0-rc7 → 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 (37) hide show
  1. package/DatadogSDKReactNative.podspec +1 -1
  2. package/README.md +2 -0
  3. package/android/build.gradle +1 -1
  4. package/ios/Sources/DdSdk.swift +6 -3
  5. package/lib/commonjs/DdSdkReactNative.js +5 -1
  6. package/lib/commonjs/DdSdkReactNative.js.map +1 -1
  7. package/lib/commonjs/DdSdkReactNativeConfiguration.js +2 -0
  8. package/lib/commonjs/DdSdkReactNativeConfiguration.js.map +1 -1
  9. package/lib/commonjs/rum/instrumentation/DdRumResourceTracking.js +64 -6
  10. package/lib/commonjs/rum/instrumentation/DdRumResourceTracking.js.map +1 -1
  11. package/lib/commonjs/rum/instrumentation/URLHostParser.js +33 -0
  12. package/lib/commonjs/rum/instrumentation/URLHostParser.js.map +1 -0
  13. package/lib/commonjs/version.js +1 -1
  14. package/lib/commonjs/version.js.map +1 -1
  15. package/lib/module/DdSdkReactNative.js +5 -1
  16. package/lib/module/DdSdkReactNative.js.map +1 -1
  17. package/lib/module/DdSdkReactNativeConfiguration.js +2 -0
  18. package/lib/module/DdSdkReactNativeConfiguration.js.map +1 -1
  19. package/lib/module/rum/instrumentation/DdRumResourceTracking.js +61 -6
  20. package/lib/module/rum/instrumentation/DdRumResourceTracking.js.map +1 -1
  21. package/lib/module/rum/instrumentation/URLHostParser.js +24 -0
  22. package/lib/module/rum/instrumentation/URLHostParser.js.map +1 -0
  23. package/lib/module/version.js +1 -1
  24. package/lib/module/version.js.map +1 -1
  25. package/lib/typescript/DdSdkReactNativeConfiguration.d.ts +1 -0
  26. package/lib/typescript/rum/instrumentation/DdRumResourceTracking.d.ts +11 -2
  27. package/lib/typescript/rum/instrumentation/URLHostParser.d.ts +6 -0
  28. package/lib/typescript/version.d.ts +1 -1
  29. package/package.json +2 -2
  30. package/src/DdSdkReactNative.tsx +7 -3
  31. package/src/DdSdkReactNativeConfiguration.tsx +1 -0
  32. package/src/__tests__/DdSdkReactNative.test.tsx +31 -16
  33. package/src/__tests__/rum/instrumentation/DdRumResourceTracking.test.tsx +135 -60
  34. package/src/__tests__/rum/instrumentation/URLHostParser.test.ts +40 -0
  35. package/src/rum/instrumentation/DdRumResourceTracking.tsx +74 -9
  36. package/src/rum/instrumentation/URLHostParser.ts +23 -0
  37. package/src/version.ts +1 -1
@@ -63,10 +63,10 @@ describe('DdRumResourceTracking', () => {
63
63
  // GIVEN
64
64
  const method = 'GET';
65
65
  const url = 'https://api.example.com/v2/user';
66
- DdRumResourceTracking.startTrackingInternal(
67
- XMLHttpRequestMock,
68
- 100
69
- );
66
+ DdRumResourceTracking.startTrackingInternal(XMLHttpRequestMock, {
67
+ tracingSamplingRate: 100,
68
+ firstPartyHosts: []
69
+ });
70
70
 
71
71
  // WHEN
72
72
  const xhr = new XMLHttpRequestMock();
@@ -98,10 +98,10 @@ describe('DdRumResourceTracking', () => {
98
98
  // GIVEN
99
99
  const method = 'GET';
100
100
  const url = 'https://api.example.com/v2/user';
101
- DdRumResourceTracking.startTrackingInternal(
102
- XMLHttpRequestMock,
103
- 100
104
- );
101
+ DdRumResourceTracking.startTrackingInternal(XMLHttpRequestMock, {
102
+ tracingSamplingRate: 100,
103
+ firstPartyHosts: []
104
+ });
105
105
 
106
106
  // WHEN
107
107
  const xhr = new XMLHttpRequestMock();
@@ -133,10 +133,10 @@ describe('DdRumResourceTracking', () => {
133
133
  // GIVEN
134
134
  const method = 'GET';
135
135
  const url = 'https://api.example.com/v2/user';
136
- DdRumResourceTracking.startTrackingInternal(
137
- XMLHttpRequestMock,
138
- 100
139
- );
136
+ DdRumResourceTracking.startTrackingInternal(XMLHttpRequestMock, {
137
+ tracingSamplingRate: 100,
138
+ firstPartyHosts: []
139
+ });
140
140
 
141
141
  // WHEN
142
142
  const xhr = new XMLHttpRequestMock();
@@ -170,10 +170,10 @@ describe('DdRumResourceTracking', () => {
170
170
  // GIVEN
171
171
  const method = 'GET';
172
172
  const url = 'https://api.example.com/v2/user';
173
- DdRumResourceTracking.startTrackingInternal(
174
- XMLHttpRequestMock,
175
- 100
176
- );
173
+ DdRumResourceTracking.startTrackingInternal(XMLHttpRequestMock, {
174
+ tracingSamplingRate: 100,
175
+ firstPartyHosts: ['api.example.com']
176
+ });
177
177
 
178
178
  // WHEN
179
179
  const xhr = new XMLHttpRequestMock();
@@ -193,10 +193,10 @@ describe('DdRumResourceTracking', () => {
193
193
  // GIVEN
194
194
  const method = 'GET';
195
195
  const url = 'https://api.example.com/v2/user';
196
- DdRumResourceTracking.startTrackingInternal(
197
- XMLHttpRequestMock,
198
- 100
199
- );
196
+ DdRumResourceTracking.startTrackingInternal(XMLHttpRequestMock, {
197
+ tracingSamplingRate: 100,
198
+ firstPartyHosts: ['api.example.com']
199
+ });
200
200
 
201
201
  // WHEN
202
202
  const xhr = new XMLHttpRequestMock();
@@ -215,11 +215,11 @@ describe('DdRumResourceTracking', () => {
215
215
  it('generates different ids for spanId and traceId in request headers', async () => {
216
216
  // GIVEN
217
217
  const method = 'GET';
218
- const url = 'https://api.example.com/v2/user';
219
- DdRumResourceTracking.startTrackingInternal(
220
- XMLHttpRequestMock,
221
- 100
222
- );
218
+ const url = 'https://api.example.com:443/v2/user';
219
+ DdRumResourceTracking.startTrackingInternal(XMLHttpRequestMock, {
220
+ tracingSamplingRate: 100,
221
+ firstPartyHosts: ['something.fr', 'example.com']
222
+ });
223
223
 
224
224
  // WHEN
225
225
  const xhr = new XMLHttpRequestMock();
@@ -235,11 +235,80 @@ describe('DdRumResourceTracking', () => {
235
235
  expect(traceId !== spanId).toBeTruthy();
236
236
  });
237
237
 
238
+ it('does not generate spanId and traceId in request headers when no first party hosts are provided', async () => {
239
+ // GIVEN
240
+ const method = 'GET';
241
+ const url = 'https://api.example.com/v2/user';
242
+ DdRumResourceTracking.startTrackingInternal(XMLHttpRequestMock, {
243
+ tracingSamplingRate: 100,
244
+ firstPartyHosts: []
245
+ });
246
+
247
+ // WHEN
248
+ const xhr = new XMLHttpRequestMock();
249
+ xhr.open(method, url);
250
+ xhr.send();
251
+ xhr.notifyResponseArrived();
252
+ xhr.complete(200, 'ok');
253
+ await flushPromises();
254
+
255
+ // THEN
256
+ expect(xhr.requestHeaders[TRACE_ID_HEADER_KEY]).toBeUndefined();
257
+ expect(xhr.requestHeaders[PARENT_ID_HEADER_KEY]).toBeUndefined();
258
+ });
259
+
260
+ it('does not generate spanId and traceId in request headers when no the url does not match first party hosts', async () => {
261
+ // GIVEN
262
+ const method = 'GET';
263
+ const url = 'https://api.example.com/v2/user';
264
+ DdRumResourceTracking.startTrackingInternal(XMLHttpRequestMock, {
265
+ tracingSamplingRate: 100,
266
+ firstPartyHosts: ['google.com', 'api.example.co']
267
+ });
268
+
269
+ // WHEN
270
+ const xhr = new XMLHttpRequestMock();
271
+ xhr.open(method, url);
272
+ xhr.send();
273
+ xhr.notifyResponseArrived();
274
+ xhr.complete(200, 'ok');
275
+ await flushPromises();
276
+
277
+ // THEN
278
+ expect(xhr.requestHeaders[TRACE_ID_HEADER_KEY]).toBeUndefined();
279
+ expect(xhr.requestHeaders[PARENT_ID_HEADER_KEY]).toBeUndefined();
280
+ });
281
+
282
+ it('does not crash when provided URL is not a valid one', async () => {
283
+ // GIVEN
284
+ const method = 'GET';
285
+ const url = 'crash';
286
+ DdRumResourceTracking.startTrackingInternal(XMLHttpRequestMock, {
287
+ tracingSamplingRate: 100,
288
+ firstPartyHosts: ['example.com']
289
+ });
290
+
291
+ // WHEN
292
+ const xhr = new XMLHttpRequestMock();
293
+ xhr.open(method, url);
294
+ xhr.send();
295
+ xhr.notifyResponseArrived();
296
+ xhr.complete(200, 'ok');
297
+ await flushPromises();
298
+
299
+ // THEN
300
+ expect(xhr.requestHeaders[TRACE_ID_HEADER_KEY]).toBeUndefined();
301
+ expect(xhr.requestHeaders[PARENT_ID_HEADER_KEY]).toBeUndefined();
302
+ });
303
+
238
304
  it('does not generate spanId and traceId in request headers when tracing is disabled', async () => {
239
305
  // GIVEN
240
306
  const method = 'GET';
241
307
  const url = 'https://api.example.com/v2/user';
242
- DdRumResourceTracking.startTrackingInternal(XMLHttpRequestMock, 50);
308
+ DdRumResourceTracking.startTrackingInternal(XMLHttpRequestMock, {
309
+ tracingSamplingRate: 50,
310
+ firstPartyHosts: ['api.example.com']
311
+ });
243
312
  jest.spyOn(global.Math, 'random').mockReturnValue(0.7);
244
313
 
245
314
  // WHEN
@@ -259,10 +328,10 @@ describe('DdRumResourceTracking', () => {
259
328
  // GIVEN
260
329
  const method = 'GET';
261
330
  const url = 'https://api.example.com/v2/user';
262
- DdRumResourceTracking.startTrackingInternal(
263
- XMLHttpRequestMock,
264
- 100
265
- );
331
+ DdRumResourceTracking.startTrackingInternal(XMLHttpRequestMock, {
332
+ tracingSamplingRate: 100,
333
+ firstPartyHosts: []
334
+ });
266
335
 
267
336
  // WHEN
268
337
  const xhr = new XMLHttpRequestMock();
@@ -280,10 +349,10 @@ describe('DdRumResourceTracking', () => {
280
349
  // GIVEN
281
350
  const method = 'GET';
282
351
  const url = 'https://api.example.com/v2/user';
283
- DdRumResourceTracking.startTrackingInternal(
284
- XMLHttpRequestMock,
285
- 100
286
- );
352
+ DdRumResourceTracking.startTrackingInternal(XMLHttpRequestMock, {
353
+ tracingSamplingRate: 100,
354
+ firstPartyHosts: ['api.example.com']
355
+ });
287
356
 
288
357
  // WHEN
289
358
  const xhr = new XMLHttpRequestMock();
@@ -301,7 +370,10 @@ describe('DdRumResourceTracking', () => {
301
370
  // GIVEN
302
371
  const method = 'GET';
303
372
  const url = 'https://api.example.com/v2/user';
304
- DdRumResourceTracking.startTrackingInternal(XMLHttpRequestMock, 50);
373
+ DdRumResourceTracking.startTrackingInternal(XMLHttpRequestMock, {
374
+ tracingSamplingRate: 50,
375
+ firstPartyHosts: ['api.example.com']
376
+ });
305
377
  jest.spyOn(global.Math, 'random').mockReturnValue(0.7);
306
378
 
307
379
  // WHEN
@@ -322,10 +394,10 @@ describe('DdRumResourceTracking', () => {
322
394
  // GIVEN
323
395
  const method = 'GET';
324
396
  const url = 'https://api.example.com/v2/user';
325
- DdRumResourceTracking.startTrackingInternal(
326
- XMLHttpRequestMock,
327
- 100
328
- );
397
+ DdRumResourceTracking.startTrackingInternal(XMLHttpRequestMock, {
398
+ tracingSamplingRate: 100,
399
+ firstPartyHosts: ['api.example.com']
400
+ });
329
401
 
330
402
  // WHEN
331
403
  const xhr = new XMLHttpRequestMock();
@@ -345,10 +417,10 @@ describe('DdRumResourceTracking', () => {
345
417
  // GIVEN
346
418
  const method = 'GET';
347
419
  const url = 'https://api.example.com/v2/user';
348
- DdRumResourceTracking.startTrackingInternal(
349
- XMLHttpRequestMock,
350
- 100
351
- );
420
+ DdRumResourceTracking.startTrackingInternal(XMLHttpRequestMock, {
421
+ tracingSamplingRate: 100,
422
+ firstPartyHosts: ['api.example.com']
423
+ });
352
424
 
353
425
  // WHEN
354
426
  const xhr = new XMLHttpRequestMock();
@@ -369,10 +441,10 @@ describe('DdRumResourceTracking', () => {
369
441
  // GIVEN
370
442
  const method = 'GET';
371
443
  const url = 'https://api.example.com/v2/user';
372
- DdRumResourceTracking.startTrackingInternal(
373
- XMLHttpRequestMock,
374
- 100
375
- );
444
+ DdRumResourceTracking.startTrackingInternal(XMLHttpRequestMock, {
445
+ tracingSamplingRate: 100,
446
+ firstPartyHosts: ['api.example.com']
447
+ });
376
448
 
377
449
  // WHEN
378
450
  const xhr = new XMLHttpRequestMock();
@@ -393,7 +465,10 @@ describe('DdRumResourceTracking', () => {
393
465
  // GIVEN
394
466
  const method = 'GET';
395
467
  const url = 'https://api.example.com/v2/user';
396
- DdRumResourceTracking.startTrackingInternal(XMLHttpRequestMock, 50);
468
+ DdRumResourceTracking.startTrackingInternal(XMLHttpRequestMock, {
469
+ tracingSamplingRate: 50,
470
+ firstPartyHosts: ['api.example.com']
471
+ });
397
472
  jest.spyOn(global.Math, 'random').mockReturnValue(0.7);
398
473
 
399
474
  // WHEN
@@ -423,10 +498,10 @@ describe('DdRumResourceTracking', () => {
423
498
  // GIVEN
424
499
  const method = 'GET';
425
500
  const url = 'https://api.example.com/v2/user';
426
- DdRumResourceTracking.startTrackingInternal(
427
- XMLHttpRequestMock,
428
- 100
429
- );
501
+ DdRumResourceTracking.startTrackingInternal(XMLHttpRequestMock, {
502
+ tracingSamplingRate: 100,
503
+ firstPartyHosts: []
504
+ });
430
505
 
431
506
  jest.doMock('react-native/Libraries/Utilities/Platform', () => ({
432
507
  OS: platform
@@ -466,10 +541,10 @@ describe('DdRumResourceTracking', () => {
466
541
  // GIVEN
467
542
  const method = 'GET';
468
543
  const url = 'https://api.example.com/v2/user';
469
- DdRumResourceTracking.startTrackingInternal(
470
- XMLHttpRequestMock,
471
- 100
472
- );
544
+ DdRumResourceTracking.startTrackingInternal(XMLHttpRequestMock, {
545
+ tracingSamplingRate: 100,
546
+ firstPartyHosts: []
547
+ });
473
548
 
474
549
  jest.doMock('react-native/Libraries/Utilities/Platform', () => ({
475
550
  OS: platform
@@ -512,10 +587,10 @@ describe('DdRumResourceTracking', () => {
512
587
  // GIVEN
513
588
  const method = 'GET';
514
589
  const url = 'https://api.example.com/v2/user';
515
- DdRumResourceTracking.startTrackingInternal(
516
- XMLHttpRequestMock,
517
- 100
518
- );
590
+ DdRumResourceTracking.startTrackingInternal(XMLHttpRequestMock, {
591
+ tracingSamplingRate: 100,
592
+ firstPartyHosts: []
593
+ });
519
594
 
520
595
  // WHEN
521
596
  const xhr = new XMLHttpRequestMock();
@@ -0,0 +1,40 @@
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 { URLHostParser } from '../../../rum/instrumentation/URLHostParser';
8
+
9
+ describe('URLHostParser', () => {
10
+ it('returns the host when a classic URL is provided', () => {
11
+ const url = 'https://api.example.com/api.json';
12
+ expect(URLHostParser(url)).toBe('api.example.com');
13
+ });
14
+ it('returns the host when a port is provided', () => {
15
+ const url = 'https://api.example.com:443/api.json';
16
+ expect(URLHostParser(url)).toBe('api.example.com');
17
+ });
18
+ it('returns the host when no slash is present', () => {
19
+ const url = 'https://api.example.com';
20
+ expect(URLHostParser(url)).toBe('api.example.com');
21
+ });
22
+ it('strips whitespaces from host when there is a whitespace', () => {
23
+ const url = 'https://api.example.com ';
24
+ expect(URLHostParser(url)).toBe('api.example.com');
25
+ });
26
+ it('returns the host when a URL contains non ASCII characters', () => {
27
+ const chineseURL = 'https://api.example.中国/api.json';
28
+ expect(URLHostParser(chineseURL)).toBe('api.example.中国');
29
+
30
+ const russianURL = 'https://api.example.рф/api.json';
31
+ expect(URLHostParser(russianURL)).toBe('api.example.рф');
32
+
33
+ const egyptianURL = 'https://api.example.مصر./api.json';
34
+ expect(URLHostParser(egyptianURL)).toBe('api.example.مصر.');
35
+ });
36
+ it('throws if not given an URL', () => {
37
+ const url = 'crash';
38
+ expect(() => URLHostParser(url)).toThrow();
39
+ });
40
+ });
@@ -13,6 +13,7 @@ import { DdRum } from '../../foundation';
13
13
 
14
14
  import type { DdRumResourceTracingAttributes, DdRumXhr } from './DdRumXhr';
15
15
  import { generateTraceId } from './TraceIdentifier';
16
+ import { URLHostParser } from './URLHostParser';
16
17
 
17
18
  export const TRACE_ID_HEADER_KEY = 'x-datadog-trace-id';
18
19
  export const PARENT_ID_HEADER_KEY = 'x-datadog-parent-id';
@@ -25,6 +26,9 @@ export const RESOURCE_SIZE_ERROR_MESSAGE =
25
26
  const RESPONSE_START_LABEL = 'response_start';
26
27
  const MISSING_RESOURCE_SIZE = -1;
27
28
 
29
+ // This regex does not match anything
30
+ const NO_MATCH_REGEX = new RegExp('a^');
31
+
28
32
  interface Timing {
29
33
  /**
30
34
  * Time relative (absolute in case of iOS) to some point, in ns.
@@ -159,7 +163,7 @@ export function calculateResponseSize(xhr: XMLHttpRequest): number {
159
163
  return size;
160
164
  }
161
165
 
162
- const generateTracingAttributes = (
166
+ const generateTracingAttributesWithSampling = (
163
167
  tracingSamplingRate: number
164
168
  ): DdRumResourceTracingAttributes => {
165
169
  if (Math.random() * 100 <= tracingSamplingRate) {
@@ -176,12 +180,36 @@ const generateTracingAttributes = (
176
180
  };
177
181
  };
178
182
 
183
+ const getFirstPartyHostsRegex = (firstPartyHosts: string[]): RegExp => {
184
+ if (firstPartyHosts.length === 0) {
185
+ return NO_MATCH_REGEX;
186
+ }
187
+ try {
188
+ // A regexp for matching hosts, e.g. when `hosts` is "example.com", it will match
189
+ // "example.com", "api.example.com", but not "foo.com".
190
+ const firstPartyHostsRegex = new RegExp(
191
+ `^(.*\\.)*(${firstPartyHosts.map(host => `${host}$`).join('|')})`
192
+ );
193
+ firstPartyHostsRegex.test('test_the_regex_is_valid');
194
+ return firstPartyHostsRegex;
195
+ } catch (e) {
196
+ InternalLog.log(
197
+ `Invalid first party hosts list ${JSON.stringify(
198
+ firstPartyHosts
199
+ )}. Regular expressions are not allowed.`,
200
+ SdkVerbosity.WARN
201
+ );
202
+ return NO_MATCH_REGEX;
203
+ }
204
+ };
205
+
179
206
  /**
180
207
  * Provides RUM auto-instrumentation feature to track resources (fetch, XHR, axios) as RUM events.
181
208
  */
182
209
  export class DdRumResourceTracking {
183
210
  private static isTracking = false;
184
211
  private static tracingSamplingRate: number;
212
+ private static firstPartyHostsRegex: RegExp = NO_MATCH_REGEX; // matches nothing by default
185
213
 
186
214
  private static originalXhrOpen: any;
187
215
  private static originalXhrSend: any;
@@ -189,11 +217,17 @@ export class DdRumResourceTracking {
189
217
  /**
190
218
  * Starts tracking resources and sends a RUM Resource event every time a network request is detected.
191
219
  */
192
- static startTracking(tracingSamplingRate: number): void {
193
- DdRumResourceTracking.startTrackingInternal(
194
- XMLHttpRequest,
195
- tracingSamplingRate
196
- );
220
+ static startTracking({
221
+ tracingSamplingRate,
222
+ firstPartyHosts
223
+ }: {
224
+ tracingSamplingRate: number;
225
+ firstPartyHosts: string[];
226
+ }): void {
227
+ DdRumResourceTracking.startTrackingInternal(XMLHttpRequest, {
228
+ tracingSamplingRate,
229
+ firstPartyHosts
230
+ });
197
231
  }
198
232
 
199
233
  /**
@@ -201,7 +235,10 @@ export class DdRumResourceTracking {
201
235
  */
202
236
  static startTrackingInternal(
203
237
  xhrType: typeof XMLHttpRequest,
204
- tracingSamplingRate: number
238
+ {
239
+ tracingSamplingRate,
240
+ firstPartyHosts
241
+ }: { tracingSamplingRate: number; firstPartyHosts: string[] }
205
242
  ): void {
206
243
  // extra safety to avoid proxying the XHR class twice
207
244
  if (DdRumResourceTracking.isTracking) {
@@ -213,6 +250,9 @@ export class DdRumResourceTracking {
213
250
  }
214
251
 
215
252
  DdRumResourceTracking.tracingSamplingRate = tracingSamplingRate;
253
+ DdRumResourceTracking.firstPartyHostsRegex = getFirstPartyHostsRegex(
254
+ firstPartyHosts
255
+ );
216
256
 
217
257
  DdRumResourceTracking.originalXhrOpen = xhrType.prototype.open;
218
258
  DdRumResourceTracking.originalXhrSend = xhrType.prototype.send;
@@ -234,6 +274,31 @@ export class DdRumResourceTracking {
234
274
  }
235
275
  }
236
276
 
277
+ static getTracingAttributes(url: string): DdRumResourceTracingAttributes {
278
+ try {
279
+ const hostname = URLHostParser(url);
280
+
281
+ if (DdRumResourceTracking.firstPartyHostsRegex.test(hostname)) {
282
+ return generateTracingAttributesWithSampling(
283
+ DdRumResourceTracking.tracingSamplingRate
284
+ );
285
+ }
286
+ return {
287
+ samplingPriorityHeader: '0',
288
+ tracingStrategy: 'DISCARD'
289
+ };
290
+ } catch (e) {
291
+ InternalLog.log(
292
+ `Impossible to cast ${url} as URL`,
293
+ SdkVerbosity.WARN
294
+ );
295
+ return {
296
+ samplingPriorityHeader: '0',
297
+ tracingStrategy: 'DISCARD'
298
+ };
299
+ }
300
+ }
301
+
237
302
  // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
238
303
  static proxyXhr(xhrType: any): void {
239
304
  this.proxyOpen(xhrType);
@@ -254,8 +319,8 @@ export class DdRumResourceTracking {
254
319
  url,
255
320
  reported: false,
256
321
  timer: new Timer(),
257
- tracingAttributes: generateTracingAttributes(
258
- DdRumResourceTracking.tracingSamplingRate
322
+ tracingAttributes: DdRumResourceTracking.getTracingAttributes(
323
+ url
259
324
  )
260
325
  };
261
326
  // eslint-disable-next-line prefer-rest-params
@@ -0,0 +1,23 @@
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
+ // matches what is between the first "://" and the next "/", ":" or whitespace
8
+ const hostRegex = '^.+://([^:/\\s]+)';
9
+
10
+ /**
11
+ * Returns the host from an URL.
12
+ * @returns the host (without the port)
13
+ * @throws if URL is not well formatted
14
+ */
15
+ export const URLHostParser = (url: string): string => {
16
+ const matchedHost = url.match(hostRegex);
17
+ if (matchedHost === null) {
18
+ throw new Error(`${url} is not a correctly formatted URL`);
19
+ }
20
+
21
+ // [0] is the input, [1] is the captured group
22
+ return matchedHost[1];
23
+ };
package/src/version.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  // generated by genversion
2
- export const version = '1.0.0-rc7';
2
+ export const version = '1.0.0-rc8';