@datadog/mobile-react-native 1.3.0 → 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/DatadogSDKReactNative.podspec +2 -2
- package/android/build.gradle +58 -64
- 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 +162 -16
- 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/interactionTracking/DdRumUserInteractionTracking.js +9 -0
- package/lib/commonjs/rum/instrumentation/interactionTracking/DdRumUserInteractionTracking.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/interactionTracking/DdRumUserInteractionTracking.js +9 -0
- package/lib/module/rum/instrumentation/interactionTracking/DdRumUserInteractionTracking.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/eventMappers/resourceEventMapper.d.ts +0 -1
- package/lib/typescript/rum/instrumentation/interactionTracking/DdRumUserInteractionTracking.d.ts +1 -0
- 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/domain/interfaces/RumResource.d.ts +0 -1
- package/lib/typescript/rum/instrumentation/resourceTracking/implementation/XHRProxy.d.ts +0 -6
- package/lib/typescript/rum/instrumentation/resourceTracking/implementation/responseSize.d.ts +0 -1
- 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/__tests__/DdSdkReactNativeConfiguration.test.ts +7 -6
- package/src/__tests__/rum/instrumentation/DdRumErrorTracking.test.tsx +2 -1
- package/src/__tests__/rum/instrumentation/DdRumUserInteractionTracking.test.tsx +130 -114
- package/src/index.tsx +6 -3
- package/src/rum/__tests__/DdRum.test.ts +17 -1
- package/src/rum/instrumentation/interactionTracking/DdRumUserInteractionTracking.tsx +8 -0
- package/src/rum/instrumentation/resourceTracking/DdRumResourceTracking.tsx +6 -3
- package/src/rum/instrumentation/resourceTracking/__tests__/DdRumResourceTracking.test.ts +15 -3
- 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/DatadogRumResource/__tests__/ResourceReporter.test.ts +2 -1
- package/src/rum/instrumentation/resourceTracking/implementation/XHRProxy.ts +8 -23
- package/src/rum/instrumentation/resourceTracking/implementation/__tests__/XHRProxy.test.ts +257 -74
- package/src/rum/types.ts +19 -0
- package/src/sdk/DatadogProvider/Buffer/__tests__/BufferSingleton.test.ts +2 -1
- package/src/sdk/DatadogProvider/__tests__/initialization.test.tsx +5 -4
- package/src/sdk/DatadogProvider/__tests__/initializationModes.test.tsx +6 -2
- package/src/version.ts +1 -1
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
import Timer from '../../../../Timer';
|
|
8
|
+
import { getTracingHeaders } from '../domain/distributedTracingHeaders';
|
|
8
9
|
import type { DdRumResourceTracingAttributes } from '../domain/distributedTracing';
|
|
9
10
|
import { getTracingAttributes } from '../domain/distributedTracing';
|
|
10
11
|
import type { RequestProxyOptions } from '../domain/interfaces/RequestProxy';
|
|
@@ -14,12 +15,6 @@ import type { ResourceReporter } from './DatadogRumResource/ResourceReporter';
|
|
|
14
15
|
import { URLHostParser } from './URLHostParser';
|
|
15
16
|
import { calculateResponseSize } from './responseSize';
|
|
16
17
|
|
|
17
|
-
export const TRACE_ID_HEADER_KEY = 'x-datadog-trace-id';
|
|
18
|
-
export const PARENT_ID_HEADER_KEY = 'x-datadog-parent-id';
|
|
19
|
-
export const ORIGIN_HEADER_KEY = 'x-datadog-origin';
|
|
20
|
-
export const SAMPLING_PRIORITY_HEADER_KEY = 'x-datadog-sampling-priority';
|
|
21
|
-
export const ORIGIN_RUM = 'rum';
|
|
22
|
-
|
|
23
18
|
const RESPONSE_START_LABEL = 'response_start';
|
|
24
19
|
|
|
25
20
|
interface DdRumXhr extends XMLHttpRequest {
|
|
@@ -77,7 +72,7 @@ const proxyOpen = (
|
|
|
77
72
|
context: RequestProxyOptions
|
|
78
73
|
): void => {
|
|
79
74
|
const originalXhrOpen = xhrType.prototype.open;
|
|
80
|
-
const
|
|
75
|
+
const firstPartyHostsRegexMap = context.firstPartyHostsRegexMap;
|
|
81
76
|
const tracingSamplingRate = context.tracingSamplingRate;
|
|
82
77
|
|
|
83
78
|
xhrType.prototype.open = function (
|
|
@@ -95,7 +90,7 @@ const proxyOpen = (
|
|
|
95
90
|
timer: new Timer(),
|
|
96
91
|
tracingAttributes: getTracingAttributes({
|
|
97
92
|
hostname,
|
|
98
|
-
|
|
93
|
+
firstPartyHostsRegexMap,
|
|
99
94
|
tracingSamplingRate
|
|
100
95
|
})
|
|
101
96
|
};
|
|
@@ -112,23 +107,13 @@ const proxySend = (providers: XHRProxyProviders): void => {
|
|
|
112
107
|
if (this._datadog_xhr) {
|
|
113
108
|
// keep track of start time
|
|
114
109
|
this._datadog_xhr.timer.start();
|
|
115
|
-
this.setRequestHeader(ORIGIN_HEADER_KEY, ORIGIN_RUM);
|
|
116
110
|
|
|
117
|
-
const
|
|
118
|
-
|
|
119
|
-
SAMPLING_PRIORITY_HEADER_KEY,
|
|
120
|
-
tracingAttributes.samplingPriorityHeader
|
|
111
|
+
const tracingHeaders = getTracingHeaders(
|
|
112
|
+
this._datadog_xhr.tracingAttributes
|
|
121
113
|
);
|
|
122
|
-
|
|
123
|
-
this.setRequestHeader(
|
|
124
|
-
|
|
125
|
-
tracingAttributes.traceId
|
|
126
|
-
);
|
|
127
|
-
this.setRequestHeader(
|
|
128
|
-
PARENT_ID_HEADER_KEY,
|
|
129
|
-
tracingAttributes.spanId
|
|
130
|
-
);
|
|
131
|
-
}
|
|
114
|
+
tracingHeaders.forEach(({ header, value }) => {
|
|
115
|
+
this.setRequestHeader(header, value);
|
|
116
|
+
});
|
|
132
117
|
}
|
|
133
118
|
|
|
134
119
|
proxyOnReadyStateChange(this, providers);
|
|
@@ -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
|
|
@@ -39,7 +45,8 @@ function randomInt(max: number): number {
|
|
|
39
45
|
return Math.floor(Math.random() * max);
|
|
40
46
|
}
|
|
41
47
|
|
|
42
|
-
const flushPromises = () =>
|
|
48
|
+
const flushPromises = () =>
|
|
49
|
+
new Promise(jest.requireActual('timers').setImmediate);
|
|
43
50
|
let xhrProxy;
|
|
44
51
|
|
|
45
52
|
beforeEach(() => {
|
|
@@ -75,10 +82,10 @@ describe('XHRPr', () => {
|
|
|
75
82
|
it('intercepts XHR request when startTracking() + XHR.open() + XHR.send()', async () => {
|
|
76
83
|
// GIVEN
|
|
77
84
|
const method = 'GET';
|
|
78
|
-
const url = 'https://api.example.com/v2/user';
|
|
85
|
+
const url = 'https://api.example.com:443/v2/user';
|
|
79
86
|
xhrProxy.onTrackingStart({
|
|
80
87
|
tracingSamplingRate: 100,
|
|
81
|
-
|
|
88
|
+
firstPartyHostsRegexMap: firstPartyHostsRegexMapBuilder([])
|
|
82
89
|
});
|
|
83
90
|
|
|
84
91
|
// WHEN
|
|
@@ -115,7 +122,7 @@ describe('XHRPr', () => {
|
|
|
115
122
|
const url = 'https://api.example.com/v2/user';
|
|
116
123
|
xhrProxy.onTrackingStart({
|
|
117
124
|
tracingSamplingRate: 100,
|
|
118
|
-
|
|
125
|
+
firstPartyHostsRegexMap: firstPartyHostsRegexMapBuilder([])
|
|
119
126
|
});
|
|
120
127
|
|
|
121
128
|
// WHEN
|
|
@@ -152,7 +159,7 @@ describe('XHRPr', () => {
|
|
|
152
159
|
const url = 'https://api.example.com/v2/user';
|
|
153
160
|
xhrProxy.onTrackingStart({
|
|
154
161
|
tracingSamplingRate: 100,
|
|
155
|
-
|
|
162
|
+
firstPartyHostsRegexMap: firstPartyHostsRegexMapBuilder([])
|
|
156
163
|
});
|
|
157
164
|
|
|
158
165
|
// WHEN
|
|
@@ -183,14 +190,17 @@ describe('XHRPr', () => {
|
|
|
183
190
|
});
|
|
184
191
|
|
|
185
192
|
describe('request headers', () => {
|
|
186
|
-
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 () => {
|
|
187
194
|
// GIVEN
|
|
188
195
|
const method = 'GET';
|
|
189
196
|
const url = 'https://api.example.com/v2/user';
|
|
190
197
|
xhrProxy.onTrackingStart({
|
|
191
198
|
tracingSamplingRate: 100,
|
|
192
|
-
|
|
193
|
-
|
|
199
|
+
firstPartyHostsRegexMap: firstPartyHostsRegexMapBuilder([
|
|
200
|
+
{
|
|
201
|
+
match: 'api.example.com',
|
|
202
|
+
propagatorTypes: [PropagatorType.DATADOG]
|
|
203
|
+
}
|
|
194
204
|
])
|
|
195
205
|
});
|
|
196
206
|
|
|
@@ -206,17 +216,23 @@ describe('XHRPr', () => {
|
|
|
206
216
|
const spanId = xhr.requestHeaders[PARENT_ID_HEADER_KEY];
|
|
207
217
|
expect(spanId).toBeDefined();
|
|
208
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);
|
|
209
227
|
});
|
|
210
228
|
|
|
211
|
-
it('
|
|
229
|
+
it('does not generate spanId and traceId in request headers when no first party hosts are provided', async () => {
|
|
212
230
|
// GIVEN
|
|
213
231
|
const method = 'GET';
|
|
214
232
|
const url = 'https://api.example.com/v2/user';
|
|
215
233
|
xhrProxy.onTrackingStart({
|
|
216
234
|
tracingSamplingRate: 100,
|
|
217
|
-
|
|
218
|
-
'api.example.com'
|
|
219
|
-
])
|
|
235
|
+
firstPartyHostsRegexMap: firstPartyHostsRegexMapBuilder([])
|
|
220
236
|
});
|
|
221
237
|
|
|
222
238
|
// WHEN
|
|
@@ -228,20 +244,25 @@ describe('XHRPr', () => {
|
|
|
228
244
|
await flushPromises();
|
|
229
245
|
|
|
230
246
|
// THEN
|
|
231
|
-
|
|
232
|
-
expect(
|
|
233
|
-
expect(traceId).toMatch(/[1-9].+/);
|
|
247
|
+
expect(xhr.requestHeaders[TRACE_ID_HEADER_KEY]).toBeUndefined();
|
|
248
|
+
expect(xhr.requestHeaders[PARENT_ID_HEADER_KEY]).toBeUndefined();
|
|
234
249
|
});
|
|
235
250
|
|
|
236
|
-
it('
|
|
251
|
+
it('does not generate spanId and traceId in request headers when the url does not match first party hosts', async () => {
|
|
237
252
|
// GIVEN
|
|
238
253
|
const method = 'GET';
|
|
239
|
-
const url = 'https://api.example.com
|
|
254
|
+
const url = 'https://api.example.com/v2/user';
|
|
240
255
|
xhrProxy.onTrackingStart({
|
|
241
256
|
tracingSamplingRate: 100,
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
257
|
+
firstPartyHostsRegexMap: firstPartyHostsRegexMapBuilder([
|
|
258
|
+
{
|
|
259
|
+
match: 'google.com',
|
|
260
|
+
propagatorTypes: [PropagatorType.DATADOG]
|
|
261
|
+
},
|
|
262
|
+
{
|
|
263
|
+
match: 'api.example.co',
|
|
264
|
+
propagatorTypes: [PropagatorType.DATADOG]
|
|
265
|
+
}
|
|
245
266
|
])
|
|
246
267
|
});
|
|
247
268
|
|
|
@@ -254,18 +275,22 @@ describe('XHRPr', () => {
|
|
|
254
275
|
await flushPromises();
|
|
255
276
|
|
|
256
277
|
// THEN
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
expect(traceId !== spanId).toBeTruthy();
|
|
278
|
+
expect(xhr.requestHeaders[TRACE_ID_HEADER_KEY]).toBeUndefined();
|
|
279
|
+
expect(xhr.requestHeaders[PARENT_ID_HEADER_KEY]).toBeUndefined();
|
|
260
280
|
});
|
|
261
281
|
|
|
262
|
-
it('does not
|
|
282
|
+
it('does not crash when provided URL is not a valid one', async () => {
|
|
263
283
|
// GIVEN
|
|
264
284
|
const method = 'GET';
|
|
265
|
-
const url = '
|
|
285
|
+
const url = 'crash';
|
|
266
286
|
xhrProxy.onTrackingStart({
|
|
267
287
|
tracingSamplingRate: 100,
|
|
268
|
-
|
|
288
|
+
firstPartyHostsRegexMap: firstPartyHostsRegexMapBuilder([
|
|
289
|
+
{
|
|
290
|
+
match: 'example.com',
|
|
291
|
+
propagatorTypes: [PropagatorType.DATADOG]
|
|
292
|
+
}
|
|
293
|
+
])
|
|
269
294
|
});
|
|
270
295
|
|
|
271
296
|
// WHEN
|
|
@@ -281,17 +306,20 @@ describe('XHRPr', () => {
|
|
|
281
306
|
expect(xhr.requestHeaders[PARENT_ID_HEADER_KEY]).toBeUndefined();
|
|
282
307
|
});
|
|
283
308
|
|
|
284
|
-
it('
|
|
309
|
+
it('generates spanId and traceId with 0 sampling priority in request headers when trace is not sampled', async () => {
|
|
285
310
|
// GIVEN
|
|
286
311
|
const method = 'GET';
|
|
287
312
|
const url = 'https://api.example.com/v2/user';
|
|
288
313
|
xhrProxy.onTrackingStart({
|
|
289
|
-
tracingSamplingRate:
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
314
|
+
tracingSamplingRate: 50,
|
|
315
|
+
firstPartyHostsRegexMap: firstPartyHostsRegexMapBuilder([
|
|
316
|
+
{
|
|
317
|
+
match: 'api.example.com',
|
|
318
|
+
propagatorTypes: [PropagatorType.DATADOG]
|
|
319
|
+
}
|
|
293
320
|
])
|
|
294
321
|
});
|
|
322
|
+
jest.spyOn(global.Math, 'random').mockReturnValue(0.7);
|
|
295
323
|
|
|
296
324
|
// WHEN
|
|
297
325
|
const xhr = new XMLHttpRequestMock();
|
|
@@ -302,18 +330,46 @@ describe('XHRPr', () => {
|
|
|
302
330
|
await flushPromises();
|
|
303
331
|
|
|
304
332
|
// THEN
|
|
305
|
-
expect(xhr.requestHeaders[TRACE_ID_HEADER_KEY]).toBeUndefined();
|
|
306
|
-
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);
|
|
307
339
|
});
|
|
308
340
|
|
|
309
|
-
it('does not
|
|
341
|
+
it('does not origin as RUM in the request headers when startTracking() + XHR.open() + XHR.send()', async () => {
|
|
310
342
|
// GIVEN
|
|
311
343
|
const method = 'GET';
|
|
312
|
-
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';
|
|
313
366
|
xhrProxy.onTrackingStart({
|
|
314
367
|
tracingSamplingRate: 100,
|
|
315
|
-
|
|
316
|
-
|
|
368
|
+
firstPartyHostsRegexMap: firstPartyHostsRegexMapBuilder([
|
|
369
|
+
{
|
|
370
|
+
match: 'api.example.com',
|
|
371
|
+
propagatorTypes: [PropagatorType.DATADOG]
|
|
372
|
+
}
|
|
317
373
|
])
|
|
318
374
|
});
|
|
319
375
|
|
|
@@ -326,18 +382,20 @@ describe('XHRPr', () => {
|
|
|
326
382
|
await flushPromises();
|
|
327
383
|
|
|
328
384
|
// THEN
|
|
329
|
-
expect(xhr.requestHeaders[
|
|
330
|
-
expect(xhr.requestHeaders[PARENT_ID_HEADER_KEY]).toBeUndefined();
|
|
385
|
+
expect(xhr.requestHeaders[SAMPLING_PRIORITY_HEADER_KEY]).toBe('1');
|
|
331
386
|
});
|
|
332
387
|
|
|
333
|
-
it('
|
|
388
|
+
it('forces the agent to discard the request generated trace when startTracking when the request is not traced', async () => {
|
|
334
389
|
// GIVEN
|
|
335
390
|
const method = 'GET';
|
|
336
391
|
const url = 'https://api.example.com/v2/user';
|
|
337
392
|
xhrProxy.onTrackingStart({
|
|
338
393
|
tracingSamplingRate: 50,
|
|
339
|
-
|
|
340
|
-
|
|
394
|
+
firstPartyHostsRegexMap: firstPartyHostsRegexMapBuilder([
|
|
395
|
+
{
|
|
396
|
+
match: 'api.example.com',
|
|
397
|
+
propagatorTypes: [PropagatorType.DATADOG]
|
|
398
|
+
}
|
|
341
399
|
])
|
|
342
400
|
});
|
|
343
401
|
jest.spyOn(global.Math, 'random').mockReturnValue(0.7);
|
|
@@ -351,17 +409,25 @@ describe('XHRPr', () => {
|
|
|
351
409
|
await flushPromises();
|
|
352
410
|
|
|
353
411
|
// THEN
|
|
354
|
-
expect(xhr.requestHeaders[
|
|
355
|
-
expect(xhr.requestHeaders[PARENT_ID_HEADER_KEY]).toBeUndefined();
|
|
412
|
+
expect(xhr.requestHeaders[SAMPLING_PRIORITY_HEADER_KEY]).toBe('0');
|
|
356
413
|
});
|
|
357
414
|
|
|
358
|
-
it('adds
|
|
415
|
+
it('adds tracecontext request headers when the host is instrumented with tracecontext and request is sampled', async () => {
|
|
359
416
|
// GIVEN
|
|
360
417
|
const method = 'GET';
|
|
361
|
-
const url = 'https://api.example.com/v2/user';
|
|
418
|
+
const url = 'https://api.example.com:443/v2/user';
|
|
362
419
|
xhrProxy.onTrackingStart({
|
|
363
420
|
tracingSamplingRate: 100,
|
|
364
|
-
|
|
421
|
+
firstPartyHostsRegexMap: firstPartyHostsRegexMapBuilder([
|
|
422
|
+
{
|
|
423
|
+
match: 'something.fr',
|
|
424
|
+
propagatorTypes: [PropagatorType.DATADOG]
|
|
425
|
+
},
|
|
426
|
+
{
|
|
427
|
+
match: 'example.com',
|
|
428
|
+
propagatorTypes: [PropagatorType.TRACECONTEXT]
|
|
429
|
+
}
|
|
430
|
+
])
|
|
365
431
|
});
|
|
366
432
|
|
|
367
433
|
// WHEN
|
|
@@ -373,17 +439,25 @@ describe('XHRPr', () => {
|
|
|
373
439
|
await flushPromises();
|
|
374
440
|
|
|
375
441
|
// THEN
|
|
376
|
-
|
|
442
|
+
const headerValue = xhr.requestHeaders[TRACECONTEXT_HEADER_KEY];
|
|
443
|
+
expect(headerValue).toMatch(/^00-[0-9a-f]{32}-[0-9a-f]{16}-01$/);
|
|
377
444
|
});
|
|
378
445
|
|
|
379
|
-
it('
|
|
446
|
+
it('adds tracecontext request headers when the host is instrumented with tracecontext and request is sampled', async () => {
|
|
380
447
|
// GIVEN
|
|
381
448
|
const method = 'GET';
|
|
382
|
-
const url = 'https://api.example.com/v2/user';
|
|
449
|
+
const url = 'https://api.example.com:443/v2/user';
|
|
383
450
|
xhrProxy.onTrackingStart({
|
|
384
451
|
tracingSamplingRate: 100,
|
|
385
|
-
|
|
386
|
-
|
|
452
|
+
firstPartyHostsRegexMap: firstPartyHostsRegexMapBuilder([
|
|
453
|
+
{
|
|
454
|
+
match: 'something.fr',
|
|
455
|
+
propagatorTypes: [PropagatorType.DATADOG]
|
|
456
|
+
},
|
|
457
|
+
{
|
|
458
|
+
match: 'example.com',
|
|
459
|
+
propagatorTypes: [PropagatorType.B3MULTI]
|
|
460
|
+
}
|
|
387
461
|
])
|
|
388
462
|
});
|
|
389
463
|
|
|
@@ -396,20 +470,31 @@ describe('XHRPr', () => {
|
|
|
396
470
|
await flushPromises();
|
|
397
471
|
|
|
398
472
|
// THEN
|
|
399
|
-
|
|
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');
|
|
400
479
|
});
|
|
401
480
|
|
|
402
|
-
it('
|
|
481
|
+
it('adds tracecontext request headers when the host is instrumented with b3 and request is sampled', async () => {
|
|
403
482
|
// GIVEN
|
|
404
483
|
const method = 'GET';
|
|
405
|
-
const url = 'https://api.example.com/v2/user';
|
|
484
|
+
const url = 'https://api.example.com:443/v2/user';
|
|
406
485
|
xhrProxy.onTrackingStart({
|
|
407
|
-
tracingSamplingRate:
|
|
408
|
-
|
|
409
|
-
|
|
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
|
+
}
|
|
410
496
|
])
|
|
411
497
|
});
|
|
412
|
-
jest.spyOn(global.Math, 'random').mockReturnValue(0.7);
|
|
413
498
|
|
|
414
499
|
// WHEN
|
|
415
500
|
const xhr = new XMLHttpRequestMock();
|
|
@@ -420,7 +505,60 @@ describe('XHRPr', () => {
|
|
|
420
505
|
await flushPromises();
|
|
421
506
|
|
|
422
507
|
// THEN
|
|
423
|
-
|
|
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);
|
|
424
562
|
});
|
|
425
563
|
});
|
|
426
564
|
|
|
@@ -431,8 +569,11 @@ describe('XHRPr', () => {
|
|
|
431
569
|
const url = 'https://api.example.com/v2/user';
|
|
432
570
|
xhrProxy.onTrackingStart({
|
|
433
571
|
tracingSamplingRate: 100,
|
|
434
|
-
|
|
435
|
-
|
|
572
|
+
firstPartyHostsRegexMap: firstPartyHostsRegexMapBuilder([
|
|
573
|
+
{
|
|
574
|
+
match: 'api.example.com',
|
|
575
|
+
propagatorTypes: [PropagatorType.DATADOG]
|
|
576
|
+
}
|
|
436
577
|
])
|
|
437
578
|
});
|
|
438
579
|
|
|
@@ -469,8 +610,46 @@ describe('XHRPr', () => {
|
|
|
469
610
|
const url = 'https://api.example.com/v2/user';
|
|
470
611
|
xhrProxy.onTrackingStart({
|
|
471
612
|
tracingSamplingRate: 50,
|
|
472
|
-
|
|
473
|
-
|
|
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
|
+
}
|
|
474
653
|
])
|
|
475
654
|
});
|
|
476
655
|
jest.spyOn(global.Math, 'random').mockReturnValue(0.7);
|
|
@@ -508,7 +687,7 @@ describe('XHRPr', () => {
|
|
|
508
687
|
const url = 'https://api.example.com/v2/user';
|
|
509
688
|
xhrProxy.onTrackingStart({
|
|
510
689
|
tracingSamplingRate: 100,
|
|
511
|
-
|
|
690
|
+
firstPartyHostsRegexMap: firstPartyHostsRegexMapBuilder([])
|
|
512
691
|
});
|
|
513
692
|
|
|
514
693
|
jest.doMock('react-native/Libraries/Utilities/Platform', () => ({
|
|
@@ -519,7 +698,9 @@ describe('XHRPr', () => {
|
|
|
519
698
|
const xhr = new XMLHttpRequestMock();
|
|
520
699
|
xhr.open(method, url);
|
|
521
700
|
xhr.send();
|
|
701
|
+
jest.advanceTimersByTime(50);
|
|
522
702
|
xhr.notifyResponseArrived();
|
|
703
|
+
jest.advanceTimersByTime(50);
|
|
523
704
|
xhr.complete(200, 'ok');
|
|
524
705
|
await flushPromises();
|
|
525
706
|
|
|
@@ -553,7 +734,7 @@ describe('XHRPr', () => {
|
|
|
553
734
|
const url = 'https://api.example.com/v2/user';
|
|
554
735
|
xhrProxy.onTrackingStart({
|
|
555
736
|
tracingSamplingRate: 100,
|
|
556
|
-
|
|
737
|
+
firstPartyHostsRegexMap: firstPartyHostsRegexMapBuilder([])
|
|
557
738
|
});
|
|
558
739
|
|
|
559
740
|
jest.doMock('react-native/Libraries/Utilities/Platform', () => ({
|
|
@@ -564,7 +745,9 @@ describe('XHRPr', () => {
|
|
|
564
745
|
const xhr = new XMLHttpRequestMock();
|
|
565
746
|
xhr.open(method, url);
|
|
566
747
|
xhr.send();
|
|
748
|
+
jest.advanceTimersByTime(50);
|
|
567
749
|
xhr.notifyResponseArrived();
|
|
750
|
+
jest.advanceTimersByTime(50);
|
|
568
751
|
xhr.abort();
|
|
569
752
|
xhr.complete(0, undefined);
|
|
570
753
|
await flushPromises();
|
|
@@ -601,7 +784,7 @@ describe('XHRPr', () => {
|
|
|
601
784
|
const url = 'https://api.example.com/v2/user';
|
|
602
785
|
xhrProxy.onTrackingStart({
|
|
603
786
|
tracingSamplingRate: 100,
|
|
604
|
-
|
|
787
|
+
firstPartyHostsRegexMap: firstPartyHostsRegexMapBuilder([])
|
|
605
788
|
});
|
|
606
789
|
|
|
607
790
|
// WHEN
|
|
@@ -624,7 +807,7 @@ describe('XHRPr', () => {
|
|
|
624
807
|
const url = 'https://api.example.com/v2/user';
|
|
625
808
|
xhrProxy.onTrackingStart({
|
|
626
809
|
tracingSamplingRate: 100,
|
|
627
|
-
|
|
810
|
+
firstPartyHostsRegexMap: firstPartyHostsRegexMapBuilder([])
|
|
628
811
|
});
|
|
629
812
|
DdRum.registerResourceEventMapper(event => {
|
|
630
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
|
+
};
|
|
@@ -6,7 +6,8 @@
|
|
|
6
6
|
|
|
7
7
|
import { BufferSingleton } from '../BufferSingleton';
|
|
8
8
|
|
|
9
|
-
const flushPromises = () =>
|
|
9
|
+
const flushPromises = () =>
|
|
10
|
+
new Promise<void>(jest.requireActual('timers').setImmediate);
|
|
10
11
|
|
|
11
12
|
describe('BufferSingleton', () => {
|
|
12
13
|
afterEach(() => {
|