@datadog/mobile-react-native 1.0.0-rc8 → 1.0.0-rc9
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 +1 -1
- package/lib/commonjs/DdSdkReactNative.js +2 -2
- package/lib/commonjs/DdSdkReactNative.js.map +1 -1
- package/lib/commonjs/rum/instrumentation/resourceTracking/DdRumResourceTracking.js +73 -0
- package/lib/commonjs/rum/instrumentation/resourceTracking/DdRumResourceTracking.js.map +1 -0
- package/lib/commonjs/rum/instrumentation/{TraceIdentifier.js → resourceTracking/domain/distributedTracing.js} +40 -1
- package/lib/commonjs/rum/instrumentation/resourceTracking/domain/distributedTracing.js.map +1 -0
- package/lib/commonjs/rum/instrumentation/resourceTracking/domain/firstPartyHosts.js +46 -0
- package/lib/commonjs/rum/instrumentation/resourceTracking/domain/firstPartyHosts.js.map +1 -0
- package/lib/commonjs/rum/instrumentation/resourceTracking/domain/interfaces/RequestProxy.js +25 -0
- package/lib/commonjs/rum/instrumentation/resourceTracking/domain/interfaces/RequestProxy.js.map +1 -0
- package/lib/commonjs/rum/instrumentation/resourceTracking/domain/interfaces/RumResource.js +2 -0
- package/lib/commonjs/rum/instrumentation/{DdRumXhr.js.map → resourceTracking/domain/interfaces/RumResource.js.map} +0 -0
- package/lib/commonjs/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/ResourceReporter.js +57 -0
- package/lib/commonjs/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/ResourceReporter.js.map +1 -0
- package/lib/commonjs/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/internalDevResourceBlocklist.js +49 -0
- package/lib/commonjs/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/internalDevResourceBlocklist.js.map +1 -0
- package/lib/commonjs/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/resourceTiming.js +45 -0
- package/lib/commonjs/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/resourceTiming.js.map +1 -0
- package/lib/commonjs/rum/instrumentation/{URLHostParser.js → resourceTracking/implementation/URLHostParser.js} +16 -7
- package/lib/commonjs/rum/instrumentation/resourceTracking/implementation/URLHostParser.js.map +1 -0
- package/lib/commonjs/rum/instrumentation/resourceTracking/implementation/XHRProxy.js +167 -0
- package/lib/commonjs/rum/instrumentation/resourceTracking/implementation/XHRProxy.js.map +1 -0
- package/lib/commonjs/rum/instrumentation/resourceTracking/implementation/responseSize.js +97 -0
- package/lib/commonjs/rum/instrumentation/resourceTracking/implementation/responseSize.js.map +1 -0
- package/lib/commonjs/version.js +1 -1
- package/lib/commonjs/version.js.map +1 -1
- package/lib/module/DdSdkReactNative.js +1 -1
- package/lib/module/DdSdkReactNative.js.map +1 -1
- package/lib/module/rum/instrumentation/resourceTracking/DdRumResourceTracking.js +61 -0
- package/lib/module/rum/instrumentation/resourceTracking/DdRumResourceTracking.js.map +1 -0
- package/lib/module/rum/instrumentation/{TraceIdentifier.js → resourceTracking/domain/distributedTracing.js} +35 -1
- package/lib/module/rum/instrumentation/resourceTracking/domain/distributedTracing.js.map +1 -0
- package/lib/module/rum/instrumentation/resourceTracking/domain/firstPartyHosts.js +29 -0
- package/lib/module/rum/instrumentation/resourceTracking/domain/firstPartyHosts.js.map +1 -0
- package/lib/module/rum/instrumentation/resourceTracking/domain/interfaces/RequestProxy.js +16 -0
- package/lib/module/rum/instrumentation/resourceTracking/domain/interfaces/RequestProxy.js.map +1 -0
- package/lib/module/rum/instrumentation/resourceTracking/domain/interfaces/RumResource.js +2 -0
- package/lib/module/rum/instrumentation/{DdRumXhr.js.map → resourceTracking/domain/interfaces/RumResource.js.map} +0 -0
- package/lib/module/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/ResourceReporter.js +50 -0
- package/lib/module/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/ResourceReporter.js.map +1 -0
- package/lib/module/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/internalDevResourceBlocklist.js +40 -0
- package/lib/module/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/internalDevResourceBlocklist.js.map +1 -0
- package/lib/module/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/resourceTiming.js +36 -0
- package/lib/module/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/resourceTiming.js.map +1 -0
- package/{src/rum/instrumentation/URLHostParser.ts → lib/module/rum/instrumentation/resourceTracking/implementation/URLHostParser.js} +15 -8
- package/lib/module/rum/instrumentation/resourceTracking/implementation/URLHostParser.js.map +1 -0
- package/lib/module/rum/instrumentation/resourceTracking/implementation/XHRProxy.js +151 -0
- package/lib/module/rum/instrumentation/resourceTracking/implementation/XHRProxy.js.map +1 -0
- package/lib/module/rum/instrumentation/resourceTracking/implementation/responseSize.js +86 -0
- package/lib/module/rum/instrumentation/resourceTracking/implementation/responseSize.js.map +1 -0
- package/lib/module/version.js +1 -1
- package/lib/module/version.js.map +1 -1
- package/lib/typescript/rum/instrumentation/resourceTracking/DdRumResourceTracking.d.ts +15 -0
- package/lib/typescript/rum/instrumentation/resourceTracking/domain/distributedTracing.d.ts +18 -0
- package/lib/typescript/rum/instrumentation/resourceTracking/domain/firstPartyHosts.d.ts +6 -0
- package/lib/typescript/rum/instrumentation/resourceTracking/domain/interfaces/RequestProxy.d.ts +8 -0
- package/lib/typescript/rum/instrumentation/resourceTracking/domain/interfaces/RumResource.d.ts +19 -0
- package/lib/typescript/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/ResourceReporter.d.ts +8 -0
- package/lib/typescript/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/internalDevResourceBlocklist.d.ts +6 -0
- package/lib/typescript/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/resourceTiming.d.ts +17 -0
- package/lib/typescript/rum/instrumentation/resourceTracking/implementation/URLHostParser.d.ts +6 -0
- package/lib/typescript/rum/instrumentation/resourceTracking/implementation/XHRProxy.d.ts +25 -0
- package/lib/typescript/rum/instrumentation/resourceTracking/implementation/responseSize.d.ts +3 -0
- package/lib/typescript/version.d.ts +1 -1
- package/package.json +4 -3
- package/src/DdSdkReactNative.tsx +1 -1
- package/src/__tests__/DdSdkReactNative.test.tsx +11 -8
- package/src/__tests__/rum/instrumentation/DdEventsInterceptor.test.tsx +1 -1
- package/src/__tests__/rum/instrumentation/DdRumUserInteractionTracking.test.tsx +1 -1
- package/src/rum/instrumentation/resourceTracking/DdRumResourceTracking.tsx +67 -0
- package/src/rum/instrumentation/resourceTracking/__tests__/DdRumResourceTracking.test.ts +79 -0
- package/src/{__tests__/rum/instrumentation → rum/instrumentation/resourceTracking/__tests__}/__utils__/XMLHttpRequestMock.ts +0 -0
- package/src/{__tests__/rum/instrumentation/TraceIdentifier.test.tsx → rum/instrumentation/resourceTracking/domain/__tests__/distributedTracing.test.ts} +1 -1
- package/src/rum/instrumentation/resourceTracking/domain/distributedTracing.tsx +87 -0
- package/src/rum/instrumentation/resourceTracking/domain/firstPartyHosts.ts +45 -0
- package/src/rum/instrumentation/resourceTracking/domain/interfaces/RequestProxy.ts +15 -0
- package/src/rum/instrumentation/resourceTracking/domain/interfaces/RumResource.ts +26 -0
- package/src/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/ResourceReporter.ts +78 -0
- package/src/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/__tests__/ResourceReporter.test.ts +83 -0
- package/src/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/__tests__/__utils__/ResourceMockFactory.ts +45 -0
- package/src/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/__tests__/internalDevResourceBlocklist.test.ts +69 -0
- package/src/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/internalDevResourceBlocklist.ts +50 -0
- package/src/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/resourceTiming.ts +70 -0
- package/src/rum/instrumentation/resourceTracking/implementation/URLHostParser.ts +30 -0
- package/src/rum/instrumentation/resourceTracking/implementation/XHRProxy.ts +197 -0
- package/src/{__tests__/rum/instrumentation → rum/instrumentation/resourceTracking/implementation/__tests__}/URLHostParser.test.ts +3 -3
- package/src/{__tests__/rum/instrumentation/DdRumResourceTracking.test.tsx → rum/instrumentation/resourceTracking/implementation/__tests__/XHRProxy.test.ts} +83 -49
- package/src/rum/instrumentation/resourceTracking/implementation/responseSize.ts +83 -0
- package/src/version.ts +1 -1
- package/lib/commonjs/rum/instrumentation/DdRumResourceTracking.js +0 -356
- package/lib/commonjs/rum/instrumentation/DdRumResourceTracking.js.map +0 -1
- package/lib/commonjs/rum/instrumentation/DdRumXhr.js +0 -2
- package/lib/commonjs/rum/instrumentation/TraceIdentifier.js.map +0 -1
- package/lib/commonjs/rum/instrumentation/URLHostParser.js.map +0 -1
- package/lib/module/rum/instrumentation/DdRumResourceTracking.js +0 -331
- package/lib/module/rum/instrumentation/DdRumResourceTracking.js.map +0 -1
- package/lib/module/rum/instrumentation/DdRumXhr.js +0 -2
- package/lib/module/rum/instrumentation/TraceIdentifier.js.map +0 -1
- package/lib/module/rum/instrumentation/URLHostParser.js +0 -24
- package/lib/module/rum/instrumentation/URLHostParser.js.map +0 -1
- package/lib/typescript/rum/instrumentation/DdRumResourceTracking.d.ts +0 -40
- package/lib/typescript/rum/instrumentation/DdRumXhr.d.ts +0 -23
- package/lib/typescript/rum/instrumentation/TraceIdentifier.d.ts +0 -1
- package/lib/typescript/rum/instrumentation/URLHostParser.d.ts +0 -6
- package/src/rum/instrumentation/DdRumResourceTracking.tsx +0 -426
- package/src/rum/instrumentation/DdRumXhr.tsx +0 -33
- package/src/rum/instrumentation/TraceIdentifier.tsx +0 -34
|
@@ -6,23 +6,26 @@
|
|
|
6
6
|
|
|
7
7
|
import { Platform, NativeModules } from 'react-native';
|
|
8
8
|
|
|
9
|
-
import { InternalLog } from '
|
|
10
|
-
import { SdkVerbosity } from '
|
|
9
|
+
import { InternalLog } from '../../../../../InternalLog';
|
|
10
|
+
import { SdkVerbosity } from '../../../../../SdkVerbosity';
|
|
11
|
+
import { XMLHttpRequestMock } from '../../__tests__/__utils__/XMLHttpRequestMock';
|
|
12
|
+
import { firstPartyHostsRegexBuilder } from '../../domain/firstPartyHosts';
|
|
13
|
+
import { ResourceReporter } from '../DatadogRumResource/ResourceReporter';
|
|
11
14
|
import {
|
|
12
|
-
DdRumResourceTracking,
|
|
13
15
|
PARENT_ID_HEADER_KEY,
|
|
14
16
|
TRACE_ID_HEADER_KEY,
|
|
15
17
|
ORIGIN_RUM,
|
|
16
18
|
ORIGIN_HEADER_KEY,
|
|
17
19
|
SAMPLING_PRIORITY_HEADER_KEY,
|
|
20
|
+
XHRProxy
|
|
21
|
+
} from '../XHRProxy';
|
|
22
|
+
import {
|
|
18
23
|
calculateResponseSize,
|
|
19
24
|
RESOURCE_SIZE_ERROR_MESSAGE
|
|
20
|
-
} from '
|
|
21
|
-
|
|
22
|
-
import { XMLHttpRequestMock } from './__utils__/XMLHttpRequestMock';
|
|
25
|
+
} from '../responseSize';
|
|
23
26
|
|
|
24
27
|
jest.useFakeTimers();
|
|
25
|
-
jest.mock('
|
|
28
|
+
jest.mock('../../../../../InternalLog');
|
|
26
29
|
const mockedInternalLog = (InternalLog as unknown) as {
|
|
27
30
|
log: jest.MockedFunction<typeof InternalLog.log>;
|
|
28
31
|
};
|
|
@@ -35,10 +38,15 @@ function randomInt(max: number): number {
|
|
|
35
38
|
}
|
|
36
39
|
|
|
37
40
|
const flushPromises = () => new Promise(setImmediate);
|
|
41
|
+
let xhrProxy;
|
|
38
42
|
|
|
39
43
|
beforeEach(() => {
|
|
40
44
|
DdRum.startResource.mockClear();
|
|
41
45
|
DdRum.stopResource.mockClear();
|
|
46
|
+
xhrProxy = new XHRProxy({
|
|
47
|
+
xhrType: XMLHttpRequestMock,
|
|
48
|
+
resourceReporter: new ResourceReporter([])
|
|
49
|
+
});
|
|
42
50
|
|
|
43
51
|
// we need this because with ms precision between Date.now() calls we can get 0, so we advance
|
|
44
52
|
// it manually with each call
|
|
@@ -52,20 +60,20 @@ beforeEach(() => {
|
|
|
52
60
|
});
|
|
53
61
|
|
|
54
62
|
afterEach(() => {
|
|
55
|
-
|
|
63
|
+
xhrProxy.onTrackingStop();
|
|
56
64
|
(Date.now as jest.MockedFunction<typeof Date.now>).mockClear();
|
|
57
65
|
jest.spyOn(global.Math, 'random').mockRestore();
|
|
58
66
|
});
|
|
59
67
|
|
|
60
|
-
describe('
|
|
68
|
+
describe('XHRPr', () => {
|
|
61
69
|
describe('resource interception', () => {
|
|
62
70
|
it('intercepts XHR request when startTracking() + XHR.open() + XHR.send()', async () => {
|
|
63
71
|
// GIVEN
|
|
64
72
|
const method = 'GET';
|
|
65
73
|
const url = 'https://api.example.com/v2/user';
|
|
66
|
-
|
|
74
|
+
xhrProxy.onTrackingStart({
|
|
67
75
|
tracingSamplingRate: 100,
|
|
68
|
-
|
|
76
|
+
firstPartyHostsRegex: firstPartyHostsRegexBuilder([])
|
|
69
77
|
});
|
|
70
78
|
|
|
71
79
|
// WHEN
|
|
@@ -98,9 +106,9 @@ describe('DdRumResourceTracking', () => {
|
|
|
98
106
|
// GIVEN
|
|
99
107
|
const method = 'GET';
|
|
100
108
|
const url = 'https://api.example.com/v2/user';
|
|
101
|
-
|
|
109
|
+
xhrProxy.onTrackingStart({
|
|
102
110
|
tracingSamplingRate: 100,
|
|
103
|
-
|
|
111
|
+
firstPartyHostsRegex: firstPartyHostsRegexBuilder([])
|
|
104
112
|
});
|
|
105
113
|
|
|
106
114
|
// WHEN
|
|
@@ -133,9 +141,9 @@ describe('DdRumResourceTracking', () => {
|
|
|
133
141
|
// GIVEN
|
|
134
142
|
const method = 'GET';
|
|
135
143
|
const url = 'https://api.example.com/v2/user';
|
|
136
|
-
|
|
144
|
+
xhrProxy.onTrackingStart({
|
|
137
145
|
tracingSamplingRate: 100,
|
|
138
|
-
|
|
146
|
+
firstPartyHostsRegex: firstPartyHostsRegexBuilder([])
|
|
139
147
|
});
|
|
140
148
|
|
|
141
149
|
// WHEN
|
|
@@ -170,9 +178,11 @@ describe('DdRumResourceTracking', () => {
|
|
|
170
178
|
// GIVEN
|
|
171
179
|
const method = 'GET';
|
|
172
180
|
const url = 'https://api.example.com/v2/user';
|
|
173
|
-
|
|
181
|
+
xhrProxy.onTrackingStart({
|
|
174
182
|
tracingSamplingRate: 100,
|
|
175
|
-
|
|
183
|
+
firstPartyHostsRegex: firstPartyHostsRegexBuilder([
|
|
184
|
+
'api.example.com'
|
|
185
|
+
])
|
|
176
186
|
});
|
|
177
187
|
|
|
178
188
|
// WHEN
|
|
@@ -193,9 +203,11 @@ describe('DdRumResourceTracking', () => {
|
|
|
193
203
|
// GIVEN
|
|
194
204
|
const method = 'GET';
|
|
195
205
|
const url = 'https://api.example.com/v2/user';
|
|
196
|
-
|
|
206
|
+
xhrProxy.onTrackingStart({
|
|
197
207
|
tracingSamplingRate: 100,
|
|
198
|
-
|
|
208
|
+
firstPartyHostsRegex: firstPartyHostsRegexBuilder([
|
|
209
|
+
'api.example.com'
|
|
210
|
+
])
|
|
199
211
|
});
|
|
200
212
|
|
|
201
213
|
// WHEN
|
|
@@ -216,9 +228,12 @@ describe('DdRumResourceTracking', () => {
|
|
|
216
228
|
// GIVEN
|
|
217
229
|
const method = 'GET';
|
|
218
230
|
const url = 'https://api.example.com:443/v2/user';
|
|
219
|
-
|
|
231
|
+
xhrProxy.onTrackingStart({
|
|
220
232
|
tracingSamplingRate: 100,
|
|
221
|
-
|
|
233
|
+
firstPartyHostsRegex: firstPartyHostsRegexBuilder([
|
|
234
|
+
'something.fr',
|
|
235
|
+
'example.com'
|
|
236
|
+
])
|
|
222
237
|
});
|
|
223
238
|
|
|
224
239
|
// WHEN
|
|
@@ -239,9 +254,9 @@ describe('DdRumResourceTracking', () => {
|
|
|
239
254
|
// GIVEN
|
|
240
255
|
const method = 'GET';
|
|
241
256
|
const url = 'https://api.example.com/v2/user';
|
|
242
|
-
|
|
257
|
+
xhrProxy.onTrackingStart({
|
|
243
258
|
tracingSamplingRate: 100,
|
|
244
|
-
|
|
259
|
+
firstPartyHostsRegex: firstPartyHostsRegexBuilder([])
|
|
245
260
|
});
|
|
246
261
|
|
|
247
262
|
// WHEN
|
|
@@ -261,9 +276,12 @@ describe('DdRumResourceTracking', () => {
|
|
|
261
276
|
// GIVEN
|
|
262
277
|
const method = 'GET';
|
|
263
278
|
const url = 'https://api.example.com/v2/user';
|
|
264
|
-
|
|
279
|
+
xhrProxy.onTrackingStart({
|
|
265
280
|
tracingSamplingRate: 100,
|
|
266
|
-
|
|
281
|
+
firstPartyHostsRegex: firstPartyHostsRegexBuilder([
|
|
282
|
+
'google.com',
|
|
283
|
+
'api.example.co'
|
|
284
|
+
])
|
|
267
285
|
});
|
|
268
286
|
|
|
269
287
|
// WHEN
|
|
@@ -283,9 +301,11 @@ describe('DdRumResourceTracking', () => {
|
|
|
283
301
|
// GIVEN
|
|
284
302
|
const method = 'GET';
|
|
285
303
|
const url = 'crash';
|
|
286
|
-
|
|
304
|
+
xhrProxy.onTrackingStart({
|
|
287
305
|
tracingSamplingRate: 100,
|
|
288
|
-
|
|
306
|
+
firstPartyHostsRegex: firstPartyHostsRegexBuilder([
|
|
307
|
+
'example.com'
|
|
308
|
+
])
|
|
289
309
|
});
|
|
290
310
|
|
|
291
311
|
// WHEN
|
|
@@ -305,9 +325,11 @@ describe('DdRumResourceTracking', () => {
|
|
|
305
325
|
// GIVEN
|
|
306
326
|
const method = 'GET';
|
|
307
327
|
const url = 'https://api.example.com/v2/user';
|
|
308
|
-
|
|
328
|
+
xhrProxy.onTrackingStart({
|
|
309
329
|
tracingSamplingRate: 50,
|
|
310
|
-
|
|
330
|
+
firstPartyHostsRegex: firstPartyHostsRegexBuilder([
|
|
331
|
+
'api.example.com'
|
|
332
|
+
])
|
|
311
333
|
});
|
|
312
334
|
jest.spyOn(global.Math, 'random').mockReturnValue(0.7);
|
|
313
335
|
|
|
@@ -328,9 +350,9 @@ describe('DdRumResourceTracking', () => {
|
|
|
328
350
|
// GIVEN
|
|
329
351
|
const method = 'GET';
|
|
330
352
|
const url = 'https://api.example.com/v2/user';
|
|
331
|
-
|
|
353
|
+
xhrProxy.onTrackingStart({
|
|
332
354
|
tracingSamplingRate: 100,
|
|
333
|
-
|
|
355
|
+
firstPartyHostsRegex: firstPartyHostsRegexBuilder([])
|
|
334
356
|
});
|
|
335
357
|
|
|
336
358
|
// WHEN
|
|
@@ -349,9 +371,11 @@ describe('DdRumResourceTracking', () => {
|
|
|
349
371
|
// GIVEN
|
|
350
372
|
const method = 'GET';
|
|
351
373
|
const url = 'https://api.example.com/v2/user';
|
|
352
|
-
|
|
374
|
+
xhrProxy.onTrackingStart({
|
|
353
375
|
tracingSamplingRate: 100,
|
|
354
|
-
|
|
376
|
+
firstPartyHostsRegex: firstPartyHostsRegexBuilder([
|
|
377
|
+
'api.example.com'
|
|
378
|
+
])
|
|
355
379
|
});
|
|
356
380
|
|
|
357
381
|
// WHEN
|
|
@@ -370,9 +394,11 @@ describe('DdRumResourceTracking', () => {
|
|
|
370
394
|
// GIVEN
|
|
371
395
|
const method = 'GET';
|
|
372
396
|
const url = 'https://api.example.com/v2/user';
|
|
373
|
-
|
|
397
|
+
xhrProxy.onTrackingStart({
|
|
374
398
|
tracingSamplingRate: 50,
|
|
375
|
-
|
|
399
|
+
firstPartyHostsRegex: firstPartyHostsRegexBuilder([
|
|
400
|
+
'api.example.com'
|
|
401
|
+
])
|
|
376
402
|
});
|
|
377
403
|
jest.spyOn(global.Math, 'random').mockReturnValue(0.7);
|
|
378
404
|
|
|
@@ -394,9 +420,11 @@ describe('DdRumResourceTracking', () => {
|
|
|
394
420
|
// GIVEN
|
|
395
421
|
const method = 'GET';
|
|
396
422
|
const url = 'https://api.example.com/v2/user';
|
|
397
|
-
|
|
423
|
+
xhrProxy.onTrackingStart({
|
|
398
424
|
tracingSamplingRate: 100,
|
|
399
|
-
|
|
425
|
+
firstPartyHostsRegex: firstPartyHostsRegexBuilder([
|
|
426
|
+
'api.example.com'
|
|
427
|
+
])
|
|
400
428
|
});
|
|
401
429
|
|
|
402
430
|
// WHEN
|
|
@@ -417,9 +445,11 @@ describe('DdRumResourceTracking', () => {
|
|
|
417
445
|
// GIVEN
|
|
418
446
|
const method = 'GET';
|
|
419
447
|
const url = 'https://api.example.com/v2/user';
|
|
420
|
-
|
|
448
|
+
xhrProxy.onTrackingStart({
|
|
421
449
|
tracingSamplingRate: 100,
|
|
422
|
-
|
|
450
|
+
firstPartyHostsRegex: firstPartyHostsRegexBuilder([
|
|
451
|
+
'api.example.com'
|
|
452
|
+
])
|
|
423
453
|
});
|
|
424
454
|
|
|
425
455
|
// WHEN
|
|
@@ -441,9 +471,11 @@ describe('DdRumResourceTracking', () => {
|
|
|
441
471
|
// GIVEN
|
|
442
472
|
const method = 'GET';
|
|
443
473
|
const url = 'https://api.example.com/v2/user';
|
|
444
|
-
|
|
474
|
+
xhrProxy.onTrackingStart({
|
|
445
475
|
tracingSamplingRate: 100,
|
|
446
|
-
|
|
476
|
+
firstPartyHostsRegex: firstPartyHostsRegexBuilder([
|
|
477
|
+
'api.example.com'
|
|
478
|
+
])
|
|
447
479
|
});
|
|
448
480
|
|
|
449
481
|
// WHEN
|
|
@@ -465,9 +497,11 @@ describe('DdRumResourceTracking', () => {
|
|
|
465
497
|
// GIVEN
|
|
466
498
|
const method = 'GET';
|
|
467
499
|
const url = 'https://api.example.com/v2/user';
|
|
468
|
-
|
|
500
|
+
xhrProxy.onTrackingStart({
|
|
469
501
|
tracingSamplingRate: 50,
|
|
470
|
-
|
|
502
|
+
firstPartyHostsRegex: firstPartyHostsRegexBuilder([
|
|
503
|
+
'api.example.com'
|
|
504
|
+
])
|
|
471
505
|
});
|
|
472
506
|
jest.spyOn(global.Math, 'random').mockReturnValue(0.7);
|
|
473
507
|
|
|
@@ -498,9 +532,9 @@ describe('DdRumResourceTracking', () => {
|
|
|
498
532
|
// GIVEN
|
|
499
533
|
const method = 'GET';
|
|
500
534
|
const url = 'https://api.example.com/v2/user';
|
|
501
|
-
|
|
535
|
+
xhrProxy.onTrackingStart({
|
|
502
536
|
tracingSamplingRate: 100,
|
|
503
|
-
|
|
537
|
+
firstPartyHostsRegex: firstPartyHostsRegexBuilder([])
|
|
504
538
|
});
|
|
505
539
|
|
|
506
540
|
jest.doMock('react-native/Libraries/Utilities/Platform', () => ({
|
|
@@ -541,9 +575,9 @@ describe('DdRumResourceTracking', () => {
|
|
|
541
575
|
// GIVEN
|
|
542
576
|
const method = 'GET';
|
|
543
577
|
const url = 'https://api.example.com/v2/user';
|
|
544
|
-
|
|
578
|
+
xhrProxy.onTrackingStart({
|
|
545
579
|
tracingSamplingRate: 100,
|
|
546
|
-
|
|
580
|
+
firstPartyHostsRegex: firstPartyHostsRegexBuilder([])
|
|
547
581
|
});
|
|
548
582
|
|
|
549
583
|
jest.doMock('react-native/Libraries/Utilities/Platform', () => ({
|
|
@@ -587,9 +621,9 @@ describe('DdRumResourceTracking', () => {
|
|
|
587
621
|
// GIVEN
|
|
588
622
|
const method = 'GET';
|
|
589
623
|
const url = 'https://api.example.com/v2/user';
|
|
590
|
-
|
|
624
|
+
xhrProxy.onTrackingStart({
|
|
591
625
|
tracingSamplingRate: 100,
|
|
592
|
-
|
|
626
|
+
firstPartyHostsRegex: firstPartyHostsRegexBuilder([])
|
|
593
627
|
});
|
|
594
628
|
|
|
595
629
|
// WHEN
|
|
@@ -0,0 +1,83 @@
|
|
|
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 { InternalLog } from '../../../../InternalLog';
|
|
8
|
+
import { SdkVerbosity } from '../../../../SdkVerbosity';
|
|
9
|
+
|
|
10
|
+
const MISSING_RESOURCE_SIZE = -1;
|
|
11
|
+
export const RESOURCE_SIZE_ERROR_MESSAGE =
|
|
12
|
+
"Couldn't get resource size, because an error occured: ";
|
|
13
|
+
|
|
14
|
+
function byteLength(str: string): number {
|
|
15
|
+
// This is a weird trick, but it works.
|
|
16
|
+
// Output is the same as TextEncoder.encode(...).length
|
|
17
|
+
return unescape(encodeURI(str)).length;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function getResponseContentLengthFromHeader(
|
|
21
|
+
xhr: XMLHttpRequest
|
|
22
|
+
): number | null {
|
|
23
|
+
const contentLengthHeader = parseInt(
|
|
24
|
+
xhr.getResponseHeader('Content-Length') ?? '',
|
|
25
|
+
10
|
|
26
|
+
);
|
|
27
|
+
if (!isNaN(contentLengthHeader)) {
|
|
28
|
+
return contentLengthHeader;
|
|
29
|
+
}
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function calculateResponseSize(xhr: XMLHttpRequest): number {
|
|
34
|
+
const contentLengthHeader = getResponseContentLengthFromHeader(xhr);
|
|
35
|
+
if (contentLengthHeader != null) {
|
|
36
|
+
return contentLengthHeader as number;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const response = xhr.response;
|
|
40
|
+
if (!response) {
|
|
41
|
+
return MISSING_RESOURCE_SIZE;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
let size;
|
|
45
|
+
try {
|
|
46
|
+
switch (xhr.responseType) {
|
|
47
|
+
case '':
|
|
48
|
+
case 'text':
|
|
49
|
+
// String
|
|
50
|
+
size = byteLength(response);
|
|
51
|
+
break;
|
|
52
|
+
case 'blob':
|
|
53
|
+
size = response.size;
|
|
54
|
+
break;
|
|
55
|
+
case 'arraybuffer':
|
|
56
|
+
size = response.byteLength;
|
|
57
|
+
break;
|
|
58
|
+
case 'document':
|
|
59
|
+
// currently not supported by RN as of 0.66
|
|
60
|
+
// HTML Document or XML Document
|
|
61
|
+
break;
|
|
62
|
+
case 'json':
|
|
63
|
+
// plain JS object
|
|
64
|
+
// original size was lost, because this is the object which was parsed.
|
|
65
|
+
// We can only convert back to the string and calculate the size,
|
|
66
|
+
// which will roughly match original.
|
|
67
|
+
size = byteLength(JSON.stringify(response));
|
|
68
|
+
break;
|
|
69
|
+
default:
|
|
70
|
+
break;
|
|
71
|
+
}
|
|
72
|
+
} catch (e) {
|
|
73
|
+
InternalLog.log(
|
|
74
|
+
`${RESOURCE_SIZE_ERROR_MESSAGE}${e}`,
|
|
75
|
+
SdkVerbosity.ERROR
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
if (typeof size !== 'number') {
|
|
80
|
+
return MISSING_RESOURCE_SIZE;
|
|
81
|
+
}
|
|
82
|
+
return size;
|
|
83
|
+
}
|
package/src/version.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// generated by genversion
|
|
2
|
-
export const version = '1.0.0-
|
|
2
|
+
export const version = '1.0.0-rc9';
|