@datadog/mobile-react-native 1.3.1 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/android/src/main/kotlin/com/datadog/reactnative/DdSdk.kt +36 -2
- package/android/src/main/kotlin/com/datadog/reactnative/DdSdkConfigurationExt.kt +14 -0
- package/android/src/test/kotlin/com/datadog/reactnative/DdSdkTest.kt +145 -5
- package/android/src/test/kotlin/com/datadog/tools/unit/MapExt.kt +7 -0
- package/ios/Sources/DdSdk.swift +2 -2
- package/ios/Sources/RNDdSdkConfiguration.swift +42 -0
- package/lib/commonjs/DdSdkReactNative.js +2 -2
- package/lib/commonjs/DdSdkReactNative.js.map +1 -1
- package/lib/commonjs/DdSdkReactNativeConfiguration.js +26 -1
- package/lib/commonjs/DdSdkReactNativeConfiguration.js.map +1 -1
- package/lib/commonjs/index.js +12 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/rum/instrumentation/resourceTracking/DdRumResourceTracking.js +1 -1
- package/lib/commonjs/rum/instrumentation/resourceTracking/DdRumResourceTracking.js.map +1 -1
- package/lib/commonjs/rum/instrumentation/resourceTracking/domain/distributedTracing.js +59 -41
- package/lib/commonjs/rum/instrumentation/resourceTracking/domain/distributedTracing.js.map +1 -1
- package/lib/commonjs/rum/instrumentation/resourceTracking/domain/distributedTracingHeaders.js +136 -0
- package/lib/commonjs/rum/instrumentation/resourceTracking/domain/distributedTracingHeaders.js.map +1 -0
- package/lib/commonjs/rum/instrumentation/resourceTracking/domain/firstPartyHosts.js +39 -6
- package/lib/commonjs/rum/instrumentation/resourceTracking/domain/firstPartyHosts.js.map +1 -1
- package/lib/commonjs/rum/instrumentation/resourceTracking/domain/interfaces/RequestProxy.js.map +1 -1
- package/lib/commonjs/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/ResourceReporter.js +3 -3
- package/lib/commonjs/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/ResourceReporter.js.map +1 -1
- package/lib/commonjs/rum/instrumentation/resourceTracking/implementation/XHRProxy.js +12 -21
- package/lib/commonjs/rum/instrumentation/resourceTracking/implementation/XHRProxy.js.map +1 -1
- package/lib/commonjs/rum/types.js +19 -1
- package/lib/commonjs/rum/types.js.map +1 -1
- package/lib/commonjs/version.js +1 -1
- package/lib/commonjs/version.js.map +1 -1
- package/lib/module/DdSdkReactNative.js +3 -3
- package/lib/module/DdSdkReactNative.js.map +1 -1
- package/lib/module/DdSdkReactNativeConfiguration.js +22 -0
- package/lib/module/DdSdkReactNativeConfiguration.js.map +1 -1
- package/lib/module/index.js +3 -3
- package/lib/module/index.js.map +1 -1
- package/lib/module/rum/instrumentation/resourceTracking/DdRumResourceTracking.js +2 -2
- package/lib/module/rum/instrumentation/resourceTracking/DdRumResourceTracking.js.map +1 -1
- package/lib/module/rum/instrumentation/resourceTracking/domain/distributedTracing.js +57 -35
- package/lib/module/rum/instrumentation/resourceTracking/domain/distributedTracing.js.map +1 -1
- package/lib/module/rum/instrumentation/resourceTracking/domain/distributedTracingHeaders.js +115 -0
- package/lib/module/rum/instrumentation/resourceTracking/domain/distributedTracingHeaders.js.map +1 -0
- package/lib/module/rum/instrumentation/resourceTracking/domain/firstPartyHosts.js +37 -3
- package/lib/module/rum/instrumentation/resourceTracking/domain/firstPartyHosts.js.map +1 -1
- package/lib/module/rum/instrumentation/resourceTracking/domain/interfaces/RequestProxy.js.map +1 -1
- package/lib/module/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/ResourceReporter.js +3 -3
- package/lib/module/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/ResourceReporter.js.map +1 -1
- package/lib/module/rum/instrumentation/resourceTracking/implementation/XHRProxy.js +10 -15
- package/lib/module/rum/instrumentation/resourceTracking/implementation/XHRProxy.js.map +1 -1
- package/lib/module/rum/types.js +16 -0
- package/lib/module/rum/types.js.map +1 -1
- package/lib/module/version.js +1 -1
- package/lib/module/version.js.map +1 -1
- package/lib/typescript/DdSdkReactNativeConfiguration.d.ts +11 -3
- package/lib/typescript/index.d.ts +3 -3
- package/lib/typescript/rum/instrumentation/resourceTracking/DdRumResourceTracking.d.ts +2 -1
- package/lib/typescript/rum/instrumentation/resourceTracking/domain/distributedTracing.d.ts +32 -6
- package/lib/typescript/rum/instrumentation/resourceTracking/domain/distributedTracingHeaders.d.ts +21 -0
- package/lib/typescript/rum/instrumentation/resourceTracking/domain/firstPartyHosts.d.ts +4 -2
- package/lib/typescript/rum/instrumentation/resourceTracking/domain/interfaces/RequestProxy.d.ts +6 -1
- package/lib/typescript/rum/instrumentation/resourceTracking/implementation/XHRProxy.d.ts +0 -5
- package/lib/typescript/rum/types.d.ts +17 -0
- package/lib/typescript/version.d.ts +1 -1
- package/package.json +2 -2
- package/src/DdSdkReactNative.tsx +8 -4
- package/src/DdSdkReactNativeConfiguration.tsx +36 -3
- package/src/__tests__/DdSdkReactNative.test.tsx +16 -4
- package/src/index.tsx +6 -3
- package/src/rum/__tests__/DdRum.test.ts +17 -1
- package/src/rum/instrumentation/resourceTracking/DdRumResourceTracking.tsx +6 -3
- package/src/rum/instrumentation/resourceTracking/__tests__/DdRumResourceTracking.test.ts +13 -2
- package/src/rum/instrumentation/resourceTracking/domain/__tests__/distributedTracing.test.ts +64 -24
- package/src/rum/instrumentation/resourceTracking/domain/__tests__/firstPartyHosts.test.ts +19 -7
- package/src/rum/instrumentation/resourceTracking/domain/distributedTracing.tsx +82 -40
- package/src/rum/instrumentation/resourceTracking/domain/distributedTracingHeaders.ts +141 -0
- package/src/rum/instrumentation/resourceTracking/domain/firstPartyHosts.ts +43 -7
- package/src/rum/instrumentation/resourceTracking/domain/interfaces/RequestProxy.ts +8 -1
- package/src/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/ResourceReporter.ts +4 -4
- package/src/rum/instrumentation/resourceTracking/implementation/XHRProxy.ts +8 -23
- package/src/rum/instrumentation/resourceTracking/implementation/__tests__/XHRProxy.test.ts +251 -73
- package/src/rum/types.ts +19 -0
- package/src/sdk/DatadogProvider/__tests__/initializationModes.test.tsx +1 -1
- package/src/version.ts +1 -1
|
@@ -10,17 +10,23 @@ import { InternalLog } from '../../../../../InternalLog';
|
|
|
10
10
|
import { SdkVerbosity } from '../../../../../SdkVerbosity';
|
|
11
11
|
import { BufferSingleton } from '../../../../../sdk/DatadogProvider/Buffer/BufferSingleton';
|
|
12
12
|
import { DdRum } from '../../../../DdRum';
|
|
13
|
+
import { PropagatorType } from '../../../../types';
|
|
13
14
|
import { XMLHttpRequestMock } from '../../__tests__/__utils__/XMLHttpRequestMock';
|
|
14
|
-
import { firstPartyHostsRegexBuilder } from '../../domain/firstPartyHosts';
|
|
15
|
-
import { ResourceReporter } from '../DatadogRumResource/ResourceReporter';
|
|
16
15
|
import {
|
|
17
16
|
PARENT_ID_HEADER_KEY,
|
|
18
17
|
TRACE_ID_HEADER_KEY,
|
|
19
|
-
ORIGIN_RUM,
|
|
20
|
-
ORIGIN_HEADER_KEY,
|
|
21
18
|
SAMPLING_PRIORITY_HEADER_KEY,
|
|
22
|
-
|
|
23
|
-
|
|
19
|
+
TRACECONTEXT_HEADER_KEY,
|
|
20
|
+
B3_HEADER_KEY,
|
|
21
|
+
B3_MULTI_TRACE_ID_HEADER_KEY,
|
|
22
|
+
B3_MULTI_SPAN_ID_HEADER_KEY,
|
|
23
|
+
B3_MULTI_SAMPLED_HEADER_KEY,
|
|
24
|
+
ORIGIN_RUM,
|
|
25
|
+
ORIGIN_HEADER_KEY
|
|
26
|
+
} from '../../domain/distributedTracingHeaders';
|
|
27
|
+
import { firstPartyHostsRegexMapBuilder } from '../../domain/firstPartyHosts';
|
|
28
|
+
import { ResourceReporter } from '../DatadogRumResource/ResourceReporter';
|
|
29
|
+
import { XHRProxy } from '../XHRProxy';
|
|
24
30
|
import {
|
|
25
31
|
calculateResponseSize,
|
|
26
32
|
RESOURCE_SIZE_ERROR_MESSAGE
|
|
@@ -76,10 +82,10 @@ describe('XHRPr', () => {
|
|
|
76
82
|
it('intercepts XHR request when startTracking() + XHR.open() + XHR.send()', async () => {
|
|
77
83
|
// GIVEN
|
|
78
84
|
const method = 'GET';
|
|
79
|
-
const url = 'https://api.example.com/v2/user';
|
|
85
|
+
const url = 'https://api.example.com:443/v2/user';
|
|
80
86
|
xhrProxy.onTrackingStart({
|
|
81
87
|
tracingSamplingRate: 100,
|
|
82
|
-
|
|
88
|
+
firstPartyHostsRegexMap: firstPartyHostsRegexMapBuilder([])
|
|
83
89
|
});
|
|
84
90
|
|
|
85
91
|
// WHEN
|
|
@@ -116,7 +122,7 @@ describe('XHRPr', () => {
|
|
|
116
122
|
const url = 'https://api.example.com/v2/user';
|
|
117
123
|
xhrProxy.onTrackingStart({
|
|
118
124
|
tracingSamplingRate: 100,
|
|
119
|
-
|
|
125
|
+
firstPartyHostsRegexMap: firstPartyHostsRegexMapBuilder([])
|
|
120
126
|
});
|
|
121
127
|
|
|
122
128
|
// WHEN
|
|
@@ -153,7 +159,7 @@ describe('XHRPr', () => {
|
|
|
153
159
|
const url = 'https://api.example.com/v2/user';
|
|
154
160
|
xhrProxy.onTrackingStart({
|
|
155
161
|
tracingSamplingRate: 100,
|
|
156
|
-
|
|
162
|
+
firstPartyHostsRegexMap: firstPartyHostsRegexMapBuilder([])
|
|
157
163
|
});
|
|
158
164
|
|
|
159
165
|
// WHEN
|
|
@@ -184,14 +190,17 @@ describe('XHRPr', () => {
|
|
|
184
190
|
});
|
|
185
191
|
|
|
186
192
|
describe('request headers', () => {
|
|
187
|
-
it('adds the span id in the request headers when startTracking() + XHR.open() + XHR.send()', async () => {
|
|
193
|
+
it('adds the span id and trace Id in the request headers when startTracking() + XHR.open() + XHR.send()', async () => {
|
|
188
194
|
// GIVEN
|
|
189
195
|
const method = 'GET';
|
|
190
196
|
const url = 'https://api.example.com/v2/user';
|
|
191
197
|
xhrProxy.onTrackingStart({
|
|
192
198
|
tracingSamplingRate: 100,
|
|
193
|
-
|
|
194
|
-
|
|
199
|
+
firstPartyHostsRegexMap: firstPartyHostsRegexMapBuilder([
|
|
200
|
+
{
|
|
201
|
+
match: 'api.example.com',
|
|
202
|
+
propagatorTypes: [PropagatorType.DATADOG]
|
|
203
|
+
}
|
|
195
204
|
])
|
|
196
205
|
});
|
|
197
206
|
|
|
@@ -207,17 +216,23 @@ describe('XHRPr', () => {
|
|
|
207
216
|
const spanId = xhr.requestHeaders[PARENT_ID_HEADER_KEY];
|
|
208
217
|
expect(spanId).toBeDefined();
|
|
209
218
|
expect(spanId).toMatch(/[1-9].+/);
|
|
219
|
+
const traceId = xhr.requestHeaders[TRACE_ID_HEADER_KEY];
|
|
220
|
+
expect(traceId).toBeDefined();
|
|
221
|
+
expect(traceId).toMatch(/[1-9].+/);
|
|
222
|
+
|
|
223
|
+
expect(traceId !== spanId).toBeTruthy();
|
|
224
|
+
|
|
225
|
+
expect(xhr.requestHeaders[SAMPLING_PRIORITY_HEADER_KEY]).toBe('1');
|
|
226
|
+
expect(xhr.requestHeaders[ORIGIN_HEADER_KEY]).toBe(ORIGIN_RUM);
|
|
210
227
|
});
|
|
211
228
|
|
|
212
|
-
it('
|
|
229
|
+
it('does not generate spanId and traceId in request headers when no first party hosts are provided', async () => {
|
|
213
230
|
// GIVEN
|
|
214
231
|
const method = 'GET';
|
|
215
232
|
const url = 'https://api.example.com/v2/user';
|
|
216
233
|
xhrProxy.onTrackingStart({
|
|
217
234
|
tracingSamplingRate: 100,
|
|
218
|
-
|
|
219
|
-
'api.example.com'
|
|
220
|
-
])
|
|
235
|
+
firstPartyHostsRegexMap: firstPartyHostsRegexMapBuilder([])
|
|
221
236
|
});
|
|
222
237
|
|
|
223
238
|
// WHEN
|
|
@@ -229,20 +244,25 @@ describe('XHRPr', () => {
|
|
|
229
244
|
await flushPromises();
|
|
230
245
|
|
|
231
246
|
// THEN
|
|
232
|
-
|
|
233
|
-
expect(
|
|
234
|
-
expect(traceId).toMatch(/[1-9].+/);
|
|
247
|
+
expect(xhr.requestHeaders[TRACE_ID_HEADER_KEY]).toBeUndefined();
|
|
248
|
+
expect(xhr.requestHeaders[PARENT_ID_HEADER_KEY]).toBeUndefined();
|
|
235
249
|
});
|
|
236
250
|
|
|
237
|
-
it('
|
|
251
|
+
it('does not generate spanId and traceId in request headers when the url does not match first party hosts', async () => {
|
|
238
252
|
// GIVEN
|
|
239
253
|
const method = 'GET';
|
|
240
|
-
const url = 'https://api.example.com
|
|
254
|
+
const url = 'https://api.example.com/v2/user';
|
|
241
255
|
xhrProxy.onTrackingStart({
|
|
242
256
|
tracingSamplingRate: 100,
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
257
|
+
firstPartyHostsRegexMap: firstPartyHostsRegexMapBuilder([
|
|
258
|
+
{
|
|
259
|
+
match: 'google.com',
|
|
260
|
+
propagatorTypes: [PropagatorType.DATADOG]
|
|
261
|
+
},
|
|
262
|
+
{
|
|
263
|
+
match: 'api.example.co',
|
|
264
|
+
propagatorTypes: [PropagatorType.DATADOG]
|
|
265
|
+
}
|
|
246
266
|
])
|
|
247
267
|
});
|
|
248
268
|
|
|
@@ -255,18 +275,22 @@ describe('XHRPr', () => {
|
|
|
255
275
|
await flushPromises();
|
|
256
276
|
|
|
257
277
|
// THEN
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
expect(traceId !== spanId).toBeTruthy();
|
|
278
|
+
expect(xhr.requestHeaders[TRACE_ID_HEADER_KEY]).toBeUndefined();
|
|
279
|
+
expect(xhr.requestHeaders[PARENT_ID_HEADER_KEY]).toBeUndefined();
|
|
261
280
|
});
|
|
262
281
|
|
|
263
|
-
it('does not
|
|
282
|
+
it('does not crash when provided URL is not a valid one', async () => {
|
|
264
283
|
// GIVEN
|
|
265
284
|
const method = 'GET';
|
|
266
|
-
const url = '
|
|
285
|
+
const url = 'crash';
|
|
267
286
|
xhrProxy.onTrackingStart({
|
|
268
287
|
tracingSamplingRate: 100,
|
|
269
|
-
|
|
288
|
+
firstPartyHostsRegexMap: firstPartyHostsRegexMapBuilder([
|
|
289
|
+
{
|
|
290
|
+
match: 'example.com',
|
|
291
|
+
propagatorTypes: [PropagatorType.DATADOG]
|
|
292
|
+
}
|
|
293
|
+
])
|
|
270
294
|
});
|
|
271
295
|
|
|
272
296
|
// WHEN
|
|
@@ -282,17 +306,20 @@ describe('XHRPr', () => {
|
|
|
282
306
|
expect(xhr.requestHeaders[PARENT_ID_HEADER_KEY]).toBeUndefined();
|
|
283
307
|
});
|
|
284
308
|
|
|
285
|
-
it('
|
|
309
|
+
it('generates spanId and traceId with 0 sampling priority in request headers when trace is not sampled', async () => {
|
|
286
310
|
// GIVEN
|
|
287
311
|
const method = 'GET';
|
|
288
312
|
const url = 'https://api.example.com/v2/user';
|
|
289
313
|
xhrProxy.onTrackingStart({
|
|
290
|
-
tracingSamplingRate:
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
314
|
+
tracingSamplingRate: 50,
|
|
315
|
+
firstPartyHostsRegexMap: firstPartyHostsRegexMapBuilder([
|
|
316
|
+
{
|
|
317
|
+
match: 'api.example.com',
|
|
318
|
+
propagatorTypes: [PropagatorType.DATADOG]
|
|
319
|
+
}
|
|
294
320
|
])
|
|
295
321
|
});
|
|
322
|
+
jest.spyOn(global.Math, 'random').mockReturnValue(0.7);
|
|
296
323
|
|
|
297
324
|
// WHEN
|
|
298
325
|
const xhr = new XMLHttpRequestMock();
|
|
@@ -303,18 +330,46 @@ describe('XHRPr', () => {
|
|
|
303
330
|
await flushPromises();
|
|
304
331
|
|
|
305
332
|
// THEN
|
|
306
|
-
expect(xhr.requestHeaders[TRACE_ID_HEADER_KEY]).toBeUndefined();
|
|
307
|
-
expect(
|
|
333
|
+
expect(xhr.requestHeaders[TRACE_ID_HEADER_KEY]).not.toBeUndefined();
|
|
334
|
+
expect(
|
|
335
|
+
xhr.requestHeaders[PARENT_ID_HEADER_KEY]
|
|
336
|
+
).not.toBeUndefined();
|
|
337
|
+
expect(xhr.requestHeaders[SAMPLING_PRIORITY_HEADER_KEY]).toBe('0');
|
|
338
|
+
expect(xhr.requestHeaders[ORIGIN_HEADER_KEY]).toBe(ORIGIN_RUM);
|
|
308
339
|
});
|
|
309
340
|
|
|
310
|
-
it('does not
|
|
341
|
+
it('does not origin as RUM in the request headers when startTracking() + XHR.open() + XHR.send()', async () => {
|
|
311
342
|
// GIVEN
|
|
312
343
|
const method = 'GET';
|
|
313
|
-
const url = '
|
|
344
|
+
const url = 'https://api.example.com/v2/user';
|
|
345
|
+
xhrProxy.onTrackingStart({
|
|
346
|
+
tracingSamplingRate: 100,
|
|
347
|
+
firstPartyHostsRegexMap: firstPartyHostsRegexMapBuilder([])
|
|
348
|
+
});
|
|
349
|
+
|
|
350
|
+
// WHEN
|
|
351
|
+
const xhr = new XMLHttpRequestMock();
|
|
352
|
+
xhr.open(method, url);
|
|
353
|
+
xhr.send();
|
|
354
|
+
xhr.notifyResponseArrived();
|
|
355
|
+
xhr.complete(200, 'ok');
|
|
356
|
+
await flushPromises();
|
|
357
|
+
|
|
358
|
+
// THEN
|
|
359
|
+
expect(xhr.requestHeaders[ORIGIN_HEADER_KEY]).toBeUndefined();
|
|
360
|
+
});
|
|
361
|
+
|
|
362
|
+
it('forces the agent to keep the request generated trace when startTracking() + XHR.open() + XHR.send()', async () => {
|
|
363
|
+
// GIVEN
|
|
364
|
+
const method = 'GET';
|
|
365
|
+
const url = 'https://api.example.com/v2/user';
|
|
314
366
|
xhrProxy.onTrackingStart({
|
|
315
367
|
tracingSamplingRate: 100,
|
|
316
|
-
|
|
317
|
-
|
|
368
|
+
firstPartyHostsRegexMap: firstPartyHostsRegexMapBuilder([
|
|
369
|
+
{
|
|
370
|
+
match: 'api.example.com',
|
|
371
|
+
propagatorTypes: [PropagatorType.DATADOG]
|
|
372
|
+
}
|
|
318
373
|
])
|
|
319
374
|
});
|
|
320
375
|
|
|
@@ -327,18 +382,20 @@ describe('XHRPr', () => {
|
|
|
327
382
|
await flushPromises();
|
|
328
383
|
|
|
329
384
|
// THEN
|
|
330
|
-
expect(xhr.requestHeaders[
|
|
331
|
-
expect(xhr.requestHeaders[PARENT_ID_HEADER_KEY]).toBeUndefined();
|
|
385
|
+
expect(xhr.requestHeaders[SAMPLING_PRIORITY_HEADER_KEY]).toBe('1');
|
|
332
386
|
});
|
|
333
387
|
|
|
334
|
-
it('
|
|
388
|
+
it('forces the agent to discard the request generated trace when startTracking when the request is not traced', async () => {
|
|
335
389
|
// GIVEN
|
|
336
390
|
const method = 'GET';
|
|
337
391
|
const url = 'https://api.example.com/v2/user';
|
|
338
392
|
xhrProxy.onTrackingStart({
|
|
339
393
|
tracingSamplingRate: 50,
|
|
340
|
-
|
|
341
|
-
|
|
394
|
+
firstPartyHostsRegexMap: firstPartyHostsRegexMapBuilder([
|
|
395
|
+
{
|
|
396
|
+
match: 'api.example.com',
|
|
397
|
+
propagatorTypes: [PropagatorType.DATADOG]
|
|
398
|
+
}
|
|
342
399
|
])
|
|
343
400
|
});
|
|
344
401
|
jest.spyOn(global.Math, 'random').mockReturnValue(0.7);
|
|
@@ -352,17 +409,25 @@ describe('XHRPr', () => {
|
|
|
352
409
|
await flushPromises();
|
|
353
410
|
|
|
354
411
|
// THEN
|
|
355
|
-
expect(xhr.requestHeaders[
|
|
356
|
-
expect(xhr.requestHeaders[PARENT_ID_HEADER_KEY]).toBeUndefined();
|
|
412
|
+
expect(xhr.requestHeaders[SAMPLING_PRIORITY_HEADER_KEY]).toBe('0');
|
|
357
413
|
});
|
|
358
414
|
|
|
359
|
-
it('adds
|
|
415
|
+
it('adds tracecontext request headers when the host is instrumented with tracecontext and request is sampled', async () => {
|
|
360
416
|
// GIVEN
|
|
361
417
|
const method = 'GET';
|
|
362
|
-
const url = 'https://api.example.com/v2/user';
|
|
418
|
+
const url = 'https://api.example.com:443/v2/user';
|
|
363
419
|
xhrProxy.onTrackingStart({
|
|
364
420
|
tracingSamplingRate: 100,
|
|
365
|
-
|
|
421
|
+
firstPartyHostsRegexMap: firstPartyHostsRegexMapBuilder([
|
|
422
|
+
{
|
|
423
|
+
match: 'something.fr',
|
|
424
|
+
propagatorTypes: [PropagatorType.DATADOG]
|
|
425
|
+
},
|
|
426
|
+
{
|
|
427
|
+
match: 'example.com',
|
|
428
|
+
propagatorTypes: [PropagatorType.TRACECONTEXT]
|
|
429
|
+
}
|
|
430
|
+
])
|
|
366
431
|
});
|
|
367
432
|
|
|
368
433
|
// WHEN
|
|
@@ -374,17 +439,25 @@ describe('XHRPr', () => {
|
|
|
374
439
|
await flushPromises();
|
|
375
440
|
|
|
376
441
|
// THEN
|
|
377
|
-
|
|
442
|
+
const headerValue = xhr.requestHeaders[TRACECONTEXT_HEADER_KEY];
|
|
443
|
+
expect(headerValue).toMatch(/^00-[0-9a-f]{32}-[0-9a-f]{16}-01$/);
|
|
378
444
|
});
|
|
379
445
|
|
|
380
|
-
it('
|
|
446
|
+
it('adds tracecontext request headers when the host is instrumented with tracecontext and request is sampled', async () => {
|
|
381
447
|
// GIVEN
|
|
382
448
|
const method = 'GET';
|
|
383
|
-
const url = 'https://api.example.com/v2/user';
|
|
449
|
+
const url = 'https://api.example.com:443/v2/user';
|
|
384
450
|
xhrProxy.onTrackingStart({
|
|
385
451
|
tracingSamplingRate: 100,
|
|
386
|
-
|
|
387
|
-
|
|
452
|
+
firstPartyHostsRegexMap: firstPartyHostsRegexMapBuilder([
|
|
453
|
+
{
|
|
454
|
+
match: 'something.fr',
|
|
455
|
+
propagatorTypes: [PropagatorType.DATADOG]
|
|
456
|
+
},
|
|
457
|
+
{
|
|
458
|
+
match: 'example.com',
|
|
459
|
+
propagatorTypes: [PropagatorType.B3MULTI]
|
|
460
|
+
}
|
|
388
461
|
])
|
|
389
462
|
});
|
|
390
463
|
|
|
@@ -397,20 +470,31 @@ describe('XHRPr', () => {
|
|
|
397
470
|
await flushPromises();
|
|
398
471
|
|
|
399
472
|
// THEN
|
|
400
|
-
|
|
473
|
+
const traceId = xhr.requestHeaders[B3_MULTI_TRACE_ID_HEADER_KEY];
|
|
474
|
+
const spanId = xhr.requestHeaders[B3_MULTI_SPAN_ID_HEADER_KEY];
|
|
475
|
+
const sampled = xhr.requestHeaders[B3_MULTI_SAMPLED_HEADER_KEY];
|
|
476
|
+
expect(traceId).toMatch(/^[0-9a-f]{32}$/);
|
|
477
|
+
expect(spanId).toMatch(/^[0-9a-f]{16}$/);
|
|
478
|
+
expect(sampled).toBe('1');
|
|
401
479
|
});
|
|
402
480
|
|
|
403
|
-
it('
|
|
481
|
+
it('adds tracecontext request headers when the host is instrumented with b3 and request is sampled', async () => {
|
|
404
482
|
// GIVEN
|
|
405
483
|
const method = 'GET';
|
|
406
|
-
const url = 'https://api.example.com/v2/user';
|
|
484
|
+
const url = 'https://api.example.com:443/v2/user';
|
|
407
485
|
xhrProxy.onTrackingStart({
|
|
408
|
-
tracingSamplingRate:
|
|
409
|
-
|
|
410
|
-
|
|
486
|
+
tracingSamplingRate: 100,
|
|
487
|
+
firstPartyHostsRegexMap: firstPartyHostsRegexMapBuilder([
|
|
488
|
+
{
|
|
489
|
+
match: 'something.fr',
|
|
490
|
+
propagatorTypes: [PropagatorType.DATADOG]
|
|
491
|
+
},
|
|
492
|
+
{
|
|
493
|
+
match: 'example.com',
|
|
494
|
+
propagatorTypes: [PropagatorType.B3]
|
|
495
|
+
}
|
|
411
496
|
])
|
|
412
497
|
});
|
|
413
|
-
jest.spyOn(global.Math, 'random').mockReturnValue(0.7);
|
|
414
498
|
|
|
415
499
|
// WHEN
|
|
416
500
|
const xhr = new XMLHttpRequestMock();
|
|
@@ -421,7 +505,60 @@ describe('XHRPr', () => {
|
|
|
421
505
|
await flushPromises();
|
|
422
506
|
|
|
423
507
|
// THEN
|
|
424
|
-
|
|
508
|
+
const headerValue = xhr.requestHeaders[B3_HEADER_KEY];
|
|
509
|
+
expect(headerValue).toMatch(/^[0-9a-f]{32}-[0-9a-f]{16}-1$/);
|
|
510
|
+
});
|
|
511
|
+
|
|
512
|
+
it('adds all headers when the host is matched for different propagators', async () => {
|
|
513
|
+
// GIVEN
|
|
514
|
+
const method = 'GET';
|
|
515
|
+
const url = 'https://api.example.com:443/v2/user';
|
|
516
|
+
xhrProxy.onTrackingStart({
|
|
517
|
+
tracingSamplingRate: 100,
|
|
518
|
+
firstPartyHostsRegexMap: firstPartyHostsRegexMapBuilder([
|
|
519
|
+
{
|
|
520
|
+
match: 'api.example.com',
|
|
521
|
+
propagatorTypes: [
|
|
522
|
+
PropagatorType.DATADOG,
|
|
523
|
+
PropagatorType.TRACECONTEXT
|
|
524
|
+
]
|
|
525
|
+
},
|
|
526
|
+
{
|
|
527
|
+
match: 'example.com',
|
|
528
|
+
propagatorTypes: [
|
|
529
|
+
PropagatorType.B3,
|
|
530
|
+
PropagatorType.B3MULTI
|
|
531
|
+
]
|
|
532
|
+
}
|
|
533
|
+
])
|
|
534
|
+
});
|
|
535
|
+
|
|
536
|
+
// WHEN
|
|
537
|
+
const xhr = new XMLHttpRequestMock();
|
|
538
|
+
xhr.open(method, url);
|
|
539
|
+
xhr.send();
|
|
540
|
+
xhr.notifyResponseArrived();
|
|
541
|
+
xhr.complete(200, 'ok');
|
|
542
|
+
await flushPromises();
|
|
543
|
+
|
|
544
|
+
// THEN
|
|
545
|
+
expect(xhr.requestHeaders[B3_HEADER_KEY]).not.toBeUndefined();
|
|
546
|
+
expect(
|
|
547
|
+
xhr.requestHeaders[B3_MULTI_TRACE_ID_HEADER_KEY]
|
|
548
|
+
).not.toBeUndefined();
|
|
549
|
+
expect(
|
|
550
|
+
xhr.requestHeaders[B3_MULTI_SPAN_ID_HEADER_KEY]
|
|
551
|
+
).not.toBeUndefined();
|
|
552
|
+
expect(xhr.requestHeaders[B3_MULTI_SAMPLED_HEADER_KEY]).toBe('1');
|
|
553
|
+
expect(
|
|
554
|
+
xhr.requestHeaders[TRACECONTEXT_HEADER_KEY]
|
|
555
|
+
).not.toBeUndefined();
|
|
556
|
+
expect(xhr.requestHeaders[TRACE_ID_HEADER_KEY]).not.toBeUndefined();
|
|
557
|
+
expect(
|
|
558
|
+
xhr.requestHeaders[PARENT_ID_HEADER_KEY]
|
|
559
|
+
).not.toBeUndefined();
|
|
560
|
+
expect(xhr.requestHeaders[SAMPLING_PRIORITY_HEADER_KEY]).toBe('1');
|
|
561
|
+
expect(xhr.requestHeaders[ORIGIN_HEADER_KEY]).toBe(ORIGIN_RUM);
|
|
425
562
|
});
|
|
426
563
|
});
|
|
427
564
|
|
|
@@ -432,8 +569,11 @@ describe('XHRPr', () => {
|
|
|
432
569
|
const url = 'https://api.example.com/v2/user';
|
|
433
570
|
xhrProxy.onTrackingStart({
|
|
434
571
|
tracingSamplingRate: 100,
|
|
435
|
-
|
|
436
|
-
|
|
572
|
+
firstPartyHostsRegexMap: firstPartyHostsRegexMapBuilder([
|
|
573
|
+
{
|
|
574
|
+
match: 'api.example.com',
|
|
575
|
+
propagatorTypes: [PropagatorType.DATADOG]
|
|
576
|
+
}
|
|
437
577
|
])
|
|
438
578
|
});
|
|
439
579
|
|
|
@@ -470,8 +610,46 @@ describe('XHRPr', () => {
|
|
|
470
610
|
const url = 'https://api.example.com/v2/user';
|
|
471
611
|
xhrProxy.onTrackingStart({
|
|
472
612
|
tracingSamplingRate: 50,
|
|
473
|
-
|
|
474
|
-
|
|
613
|
+
firstPartyHostsRegexMap: firstPartyHostsRegexMapBuilder([])
|
|
614
|
+
});
|
|
615
|
+
jest.spyOn(global.Math, 'random').mockReturnValue(0.7);
|
|
616
|
+
|
|
617
|
+
// WHEN
|
|
618
|
+
const xhr = new XMLHttpRequestMock();
|
|
619
|
+
xhr.open(method, url);
|
|
620
|
+
xhr.send();
|
|
621
|
+
xhr.notifyResponseArrived();
|
|
622
|
+
xhr.complete(200, 'ok');
|
|
623
|
+
await flushPromises();
|
|
624
|
+
|
|
625
|
+
// THEN
|
|
626
|
+
expect(DdNativeRum.startResource).not.toHaveBeenCalledWith(
|
|
627
|
+
expect.anything(),
|
|
628
|
+
expect.anything(),
|
|
629
|
+
expect.anything(),
|
|
630
|
+
expect.objectContaining({
|
|
631
|
+
'_dd.trace_id': expect.any(String),
|
|
632
|
+
'_dd.span_id': expect.any(String),
|
|
633
|
+
'_dd.rule_psr': expect.any(Number)
|
|
634
|
+
}),
|
|
635
|
+
expect.anything()
|
|
636
|
+
);
|
|
637
|
+
expect(DdNativeRum.startResource.mock.calls[0][3]).toStrictEqual(
|
|
638
|
+
{}
|
|
639
|
+
);
|
|
640
|
+
});
|
|
641
|
+
|
|
642
|
+
it('generates spanId and traceId when the trace is not sampled', async () => {
|
|
643
|
+
// GIVEN
|
|
644
|
+
const method = 'GET';
|
|
645
|
+
const url = 'https://api.example.com/v2/user';
|
|
646
|
+
xhrProxy.onTrackingStart({
|
|
647
|
+
tracingSamplingRate: 50,
|
|
648
|
+
firstPartyHostsRegexMap: firstPartyHostsRegexMapBuilder([
|
|
649
|
+
{
|
|
650
|
+
match: 'api.example.com',
|
|
651
|
+
propagatorTypes: [PropagatorType.DATADOG]
|
|
652
|
+
}
|
|
475
653
|
])
|
|
476
654
|
});
|
|
477
655
|
jest.spyOn(global.Math, 'random').mockReturnValue(0.7);
|
|
@@ -509,7 +687,7 @@ describe('XHRPr', () => {
|
|
|
509
687
|
const url = 'https://api.example.com/v2/user';
|
|
510
688
|
xhrProxy.onTrackingStart({
|
|
511
689
|
tracingSamplingRate: 100,
|
|
512
|
-
|
|
690
|
+
firstPartyHostsRegexMap: firstPartyHostsRegexMapBuilder([])
|
|
513
691
|
});
|
|
514
692
|
|
|
515
693
|
jest.doMock('react-native/Libraries/Utilities/Platform', () => ({
|
|
@@ -556,7 +734,7 @@ describe('XHRPr', () => {
|
|
|
556
734
|
const url = 'https://api.example.com/v2/user';
|
|
557
735
|
xhrProxy.onTrackingStart({
|
|
558
736
|
tracingSamplingRate: 100,
|
|
559
|
-
|
|
737
|
+
firstPartyHostsRegexMap: firstPartyHostsRegexMapBuilder([])
|
|
560
738
|
});
|
|
561
739
|
|
|
562
740
|
jest.doMock('react-native/Libraries/Utilities/Platform', () => ({
|
|
@@ -606,7 +784,7 @@ describe('XHRPr', () => {
|
|
|
606
784
|
const url = 'https://api.example.com/v2/user';
|
|
607
785
|
xhrProxy.onTrackingStart({
|
|
608
786
|
tracingSamplingRate: 100,
|
|
609
|
-
|
|
787
|
+
firstPartyHostsRegexMap: firstPartyHostsRegexMapBuilder([])
|
|
610
788
|
});
|
|
611
789
|
|
|
612
790
|
// WHEN
|
|
@@ -629,7 +807,7 @@ describe('XHRPr', () => {
|
|
|
629
807
|
const url = 'https://api.example.com/v2/user';
|
|
630
808
|
xhrProxy.onTrackingStart({
|
|
631
809
|
tracingSamplingRate: 100,
|
|
632
|
-
|
|
810
|
+
firstPartyHostsRegexMap: firstPartyHostsRegexMapBuilder([])
|
|
633
811
|
});
|
|
634
812
|
DdRum.registerResourceEventMapper(event => {
|
|
635
813
|
event.context['body'] = JSON.parse(
|
package/src/rum/types.ts
CHANGED
|
@@ -180,3 +180,22 @@ export enum ErrorSource {
|
|
|
180
180
|
WEBVIEW = 'WEBVIEW',
|
|
181
181
|
CUSTOM = 'CUSTOM'
|
|
182
182
|
}
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* Type of instrumentation on the host.
|
|
186
|
+
* - DATADOG: Datadog’s propagator (`x-datadog-*`)
|
|
187
|
+
* - TRACECONTEXT: W3C Trace Context (`traceparent`)
|
|
188
|
+
* - B3: B3 single header (`b3`)
|
|
189
|
+
* - B3MULTI: B3 multiple headers (`X-B3-*`)
|
|
190
|
+
*/
|
|
191
|
+
export enum PropagatorType {
|
|
192
|
+
DATADOG = 'datadog',
|
|
193
|
+
TRACECONTEXT = 'tracecontext',
|
|
194
|
+
B3 = 'b3',
|
|
195
|
+
B3MULTI = 'b3multi'
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
export type FirstPartyHost = {
|
|
199
|
+
match: string;
|
|
200
|
+
propagatorTypes: PropagatorType[];
|
|
201
|
+
};
|
|
@@ -171,7 +171,7 @@ describe('DatadogProvider', () => {
|
|
|
171
171
|
expect(
|
|
172
172
|
NativeModules.DdSdk.initialize.mock.calls[0][0]
|
|
173
173
|
.additionalConfig['_dd.first_party_hosts']
|
|
174
|
-
).toEqual(['api.com']);
|
|
174
|
+
).toEqual([{ match: 'api.com', propagatorTypes: ['datadog'] }]);
|
|
175
175
|
expect(NativeModules.DdRum.addAction).toHaveBeenCalledTimes(1);
|
|
176
176
|
});
|
|
177
177
|
});
|
package/src/version.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// generated by genversion
|
|
2
|
-
export const version = '1.
|
|
2
|
+
export const version = '1.4.0';
|