@datadog/mobile-react-native 1.0.0-rc7 → 1.0.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 +1 -1
- package/README.md +2 -0
- package/android/build.gradle +1 -1
- package/datadog-sourcemaps.gradle +137 -0
- package/ios/Sources/DdSdk.swift +6 -3
- package/lib/commonjs/DdSdkReactNative.js +7 -3
- package/lib/commonjs/DdSdkReactNative.js.map +1 -1
- package/lib/commonjs/DdSdkReactNativeConfiguration.js +2 -0
- package/lib/commonjs/DdSdkReactNativeConfiguration.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 +51 -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/resourceTracking/implementation/URLHostParser.js +42 -0
- 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 +6 -2
- package/lib/module/DdSdkReactNative.js.map +1 -1
- package/lib/module/DdSdkReactNativeConfiguration.js +2 -0
- package/lib/module/DdSdkReactNativeConfiguration.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 +34 -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/lib/module/rum/instrumentation/resourceTracking/implementation/URLHostParser.js +30 -0
- 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/DdSdkReactNativeConfiguration.d.ts +1 -0
- 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 +6 -4
- package/src/DdSdkReactNative.tsx +8 -4
- package/src/DdSdkReactNativeConfiguration.tsx +1 -0
- package/src/__tests__/DdSdkReactNative.test.tsx +42 -24
- 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/__tests__/firstPartyHosts.test.ts +22 -0
- package/src/rum/instrumentation/resourceTracking/domain/distributedTracing.tsx +87 -0
- package/src/rum/instrumentation/resourceTracking/domain/firstPartyHosts.ts +52 -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/rum/instrumentation/resourceTracking/implementation/__tests__/URLHostParser.test.ts +40 -0
- package/src/{__tests__/rum/instrumentation/DdRumResourceTracking.test.tsx → rum/instrumentation/resourceTracking/implementation/__tests__/XHRProxy.test.ts} +178 -69
- package/src/rum/instrumentation/resourceTracking/implementation/responseSize.ts +83 -0
- package/src/version.ts +1 -1
- package/lib/commonjs/rum/instrumentation/DdRumResourceTracking.js +0 -298
- 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/module/rum/instrumentation/DdRumResourceTracking.js +0 -276
- 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/typescript/rum/instrumentation/DdRumResourceTracking.d.ts +0 -31
- package/lib/typescript/rum/instrumentation/DdRumXhr.d.ts +0 -23
- package/lib/typescript/rum/instrumentation/TraceIdentifier.d.ts +0 -1
- package/src/rum/instrumentation/DdRumResourceTracking.tsx +0 -361
- 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,21 +60,21 @@ 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
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
);
|
|
74
|
+
xhrProxy.onTrackingStart({
|
|
75
|
+
tracingSamplingRate: 100,
|
|
76
|
+
firstPartyHostsRegex: firstPartyHostsRegexBuilder([])
|
|
77
|
+
});
|
|
70
78
|
|
|
71
79
|
// WHEN
|
|
72
80
|
const xhr = new XMLHttpRequestMock();
|
|
@@ -98,10 +106,10 @@ describe('DdRumResourceTracking', () => {
|
|
|
98
106
|
// GIVEN
|
|
99
107
|
const method = 'GET';
|
|
100
108
|
const url = 'https://api.example.com/v2/user';
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
);
|
|
109
|
+
xhrProxy.onTrackingStart({
|
|
110
|
+
tracingSamplingRate: 100,
|
|
111
|
+
firstPartyHostsRegex: firstPartyHostsRegexBuilder([])
|
|
112
|
+
});
|
|
105
113
|
|
|
106
114
|
// WHEN
|
|
107
115
|
const xhr = new XMLHttpRequestMock();
|
|
@@ -133,10 +141,10 @@ describe('DdRumResourceTracking', () => {
|
|
|
133
141
|
// GIVEN
|
|
134
142
|
const method = 'GET';
|
|
135
143
|
const url = 'https://api.example.com/v2/user';
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
);
|
|
144
|
+
xhrProxy.onTrackingStart({
|
|
145
|
+
tracingSamplingRate: 100,
|
|
146
|
+
firstPartyHostsRegex: firstPartyHostsRegexBuilder([])
|
|
147
|
+
});
|
|
140
148
|
|
|
141
149
|
// WHEN
|
|
142
150
|
const xhr = new XMLHttpRequestMock();
|
|
@@ -170,10 +178,12 @@ describe('DdRumResourceTracking', () => {
|
|
|
170
178
|
// GIVEN
|
|
171
179
|
const method = 'GET';
|
|
172
180
|
const url = 'https://api.example.com/v2/user';
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
181
|
+
xhrProxy.onTrackingStart({
|
|
182
|
+
tracingSamplingRate: 100,
|
|
183
|
+
firstPartyHostsRegex: firstPartyHostsRegexBuilder([
|
|
184
|
+
'api.example.com'
|
|
185
|
+
])
|
|
186
|
+
});
|
|
177
187
|
|
|
178
188
|
// WHEN
|
|
179
189
|
const xhr = new XMLHttpRequestMock();
|
|
@@ -193,10 +203,12 @@ describe('DdRumResourceTracking', () => {
|
|
|
193
203
|
// GIVEN
|
|
194
204
|
const method = 'GET';
|
|
195
205
|
const url = 'https://api.example.com/v2/user';
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
206
|
+
xhrProxy.onTrackingStart({
|
|
207
|
+
tracingSamplingRate: 100,
|
|
208
|
+
firstPartyHostsRegex: firstPartyHostsRegexBuilder([
|
|
209
|
+
'api.example.com'
|
|
210
|
+
])
|
|
211
|
+
});
|
|
200
212
|
|
|
201
213
|
// WHEN
|
|
202
214
|
const xhr = new XMLHttpRequestMock();
|
|
@@ -215,11 +227,14 @@ describe('DdRumResourceTracking', () => {
|
|
|
215
227
|
it('generates different ids for spanId and traceId in request headers', async () => {
|
|
216
228
|
// GIVEN
|
|
217
229
|
const method = 'GET';
|
|
218
|
-
const url = 'https://api.example.com/v2/user';
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
230
|
+
const url = 'https://api.example.com:443/v2/user';
|
|
231
|
+
xhrProxy.onTrackingStart({
|
|
232
|
+
tracingSamplingRate: 100,
|
|
233
|
+
firstPartyHostsRegex: firstPartyHostsRegexBuilder([
|
|
234
|
+
'something.fr',
|
|
235
|
+
'example.com'
|
|
236
|
+
])
|
|
237
|
+
});
|
|
223
238
|
|
|
224
239
|
// WHEN
|
|
225
240
|
const xhr = new XMLHttpRequestMock();
|
|
@@ -235,11 +250,87 @@ describe('DdRumResourceTracking', () => {
|
|
|
235
250
|
expect(traceId !== spanId).toBeTruthy();
|
|
236
251
|
});
|
|
237
252
|
|
|
253
|
+
it('does not generate spanId and traceId in request headers when no first party hosts are provided', async () => {
|
|
254
|
+
// GIVEN
|
|
255
|
+
const method = 'GET';
|
|
256
|
+
const url = 'https://api.example.com/v2/user';
|
|
257
|
+
xhrProxy.onTrackingStart({
|
|
258
|
+
tracingSamplingRate: 100,
|
|
259
|
+
firstPartyHostsRegex: firstPartyHostsRegexBuilder([])
|
|
260
|
+
});
|
|
261
|
+
|
|
262
|
+
// WHEN
|
|
263
|
+
const xhr = new XMLHttpRequestMock();
|
|
264
|
+
xhr.open(method, url);
|
|
265
|
+
xhr.send();
|
|
266
|
+
xhr.notifyResponseArrived();
|
|
267
|
+
xhr.complete(200, 'ok');
|
|
268
|
+
await flushPromises();
|
|
269
|
+
|
|
270
|
+
// THEN
|
|
271
|
+
expect(xhr.requestHeaders[TRACE_ID_HEADER_KEY]).toBeUndefined();
|
|
272
|
+
expect(xhr.requestHeaders[PARENT_ID_HEADER_KEY]).toBeUndefined();
|
|
273
|
+
});
|
|
274
|
+
|
|
275
|
+
it('does not generate spanId and traceId in request headers when no the url does not match first party hosts', async () => {
|
|
276
|
+
// GIVEN
|
|
277
|
+
const method = 'GET';
|
|
278
|
+
const url = 'https://api.example.com/v2/user';
|
|
279
|
+
xhrProxy.onTrackingStart({
|
|
280
|
+
tracingSamplingRate: 100,
|
|
281
|
+
firstPartyHostsRegex: firstPartyHostsRegexBuilder([
|
|
282
|
+
'google.com',
|
|
283
|
+
'api.example.co'
|
|
284
|
+
])
|
|
285
|
+
});
|
|
286
|
+
|
|
287
|
+
// WHEN
|
|
288
|
+
const xhr = new XMLHttpRequestMock();
|
|
289
|
+
xhr.open(method, url);
|
|
290
|
+
xhr.send();
|
|
291
|
+
xhr.notifyResponseArrived();
|
|
292
|
+
xhr.complete(200, 'ok');
|
|
293
|
+
await flushPromises();
|
|
294
|
+
|
|
295
|
+
// THEN
|
|
296
|
+
expect(xhr.requestHeaders[TRACE_ID_HEADER_KEY]).toBeUndefined();
|
|
297
|
+
expect(xhr.requestHeaders[PARENT_ID_HEADER_KEY]).toBeUndefined();
|
|
298
|
+
});
|
|
299
|
+
|
|
300
|
+
it('does not crash when provided URL is not a valid one', async () => {
|
|
301
|
+
// GIVEN
|
|
302
|
+
const method = 'GET';
|
|
303
|
+
const url = 'crash';
|
|
304
|
+
xhrProxy.onTrackingStart({
|
|
305
|
+
tracingSamplingRate: 100,
|
|
306
|
+
firstPartyHostsRegex: firstPartyHostsRegexBuilder([
|
|
307
|
+
'example.com'
|
|
308
|
+
])
|
|
309
|
+
});
|
|
310
|
+
|
|
311
|
+
// WHEN
|
|
312
|
+
const xhr = new XMLHttpRequestMock();
|
|
313
|
+
xhr.open(method, url);
|
|
314
|
+
xhr.send();
|
|
315
|
+
xhr.notifyResponseArrived();
|
|
316
|
+
xhr.complete(200, 'ok');
|
|
317
|
+
await flushPromises();
|
|
318
|
+
|
|
319
|
+
// THEN
|
|
320
|
+
expect(xhr.requestHeaders[TRACE_ID_HEADER_KEY]).toBeUndefined();
|
|
321
|
+
expect(xhr.requestHeaders[PARENT_ID_HEADER_KEY]).toBeUndefined();
|
|
322
|
+
});
|
|
323
|
+
|
|
238
324
|
it('does not generate spanId and traceId in request headers when tracing is disabled', async () => {
|
|
239
325
|
// GIVEN
|
|
240
326
|
const method = 'GET';
|
|
241
327
|
const url = 'https://api.example.com/v2/user';
|
|
242
|
-
|
|
328
|
+
xhrProxy.onTrackingStart({
|
|
329
|
+
tracingSamplingRate: 50,
|
|
330
|
+
firstPartyHostsRegex: firstPartyHostsRegexBuilder([
|
|
331
|
+
'api.example.com'
|
|
332
|
+
])
|
|
333
|
+
});
|
|
243
334
|
jest.spyOn(global.Math, 'random').mockReturnValue(0.7);
|
|
244
335
|
|
|
245
336
|
// WHEN
|
|
@@ -259,10 +350,10 @@ describe('DdRumResourceTracking', () => {
|
|
|
259
350
|
// GIVEN
|
|
260
351
|
const method = 'GET';
|
|
261
352
|
const url = 'https://api.example.com/v2/user';
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
);
|
|
353
|
+
xhrProxy.onTrackingStart({
|
|
354
|
+
tracingSamplingRate: 100,
|
|
355
|
+
firstPartyHostsRegex: firstPartyHostsRegexBuilder([])
|
|
356
|
+
});
|
|
266
357
|
|
|
267
358
|
// WHEN
|
|
268
359
|
const xhr = new XMLHttpRequestMock();
|
|
@@ -280,10 +371,12 @@ describe('DdRumResourceTracking', () => {
|
|
|
280
371
|
// GIVEN
|
|
281
372
|
const method = 'GET';
|
|
282
373
|
const url = 'https://api.example.com/v2/user';
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
374
|
+
xhrProxy.onTrackingStart({
|
|
375
|
+
tracingSamplingRate: 100,
|
|
376
|
+
firstPartyHostsRegex: firstPartyHostsRegexBuilder([
|
|
377
|
+
'api.example.com'
|
|
378
|
+
])
|
|
379
|
+
});
|
|
287
380
|
|
|
288
381
|
// WHEN
|
|
289
382
|
const xhr = new XMLHttpRequestMock();
|
|
@@ -301,7 +394,12 @@ describe('DdRumResourceTracking', () => {
|
|
|
301
394
|
// GIVEN
|
|
302
395
|
const method = 'GET';
|
|
303
396
|
const url = 'https://api.example.com/v2/user';
|
|
304
|
-
|
|
397
|
+
xhrProxy.onTrackingStart({
|
|
398
|
+
tracingSamplingRate: 50,
|
|
399
|
+
firstPartyHostsRegex: firstPartyHostsRegexBuilder([
|
|
400
|
+
'api.example.com'
|
|
401
|
+
])
|
|
402
|
+
});
|
|
305
403
|
jest.spyOn(global.Math, 'random').mockReturnValue(0.7);
|
|
306
404
|
|
|
307
405
|
// WHEN
|
|
@@ -322,10 +420,12 @@ describe('DdRumResourceTracking', () => {
|
|
|
322
420
|
// GIVEN
|
|
323
421
|
const method = 'GET';
|
|
324
422
|
const url = 'https://api.example.com/v2/user';
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
423
|
+
xhrProxy.onTrackingStart({
|
|
424
|
+
tracingSamplingRate: 100,
|
|
425
|
+
firstPartyHostsRegex: firstPartyHostsRegexBuilder([
|
|
426
|
+
'api.example.com'
|
|
427
|
+
])
|
|
428
|
+
});
|
|
329
429
|
|
|
330
430
|
// WHEN
|
|
331
431
|
const xhr = new XMLHttpRequestMock();
|
|
@@ -345,10 +445,12 @@ describe('DdRumResourceTracking', () => {
|
|
|
345
445
|
// GIVEN
|
|
346
446
|
const method = 'GET';
|
|
347
447
|
const url = 'https://api.example.com/v2/user';
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
448
|
+
xhrProxy.onTrackingStart({
|
|
449
|
+
tracingSamplingRate: 100,
|
|
450
|
+
firstPartyHostsRegex: firstPartyHostsRegexBuilder([
|
|
451
|
+
'api.example.com'
|
|
452
|
+
])
|
|
453
|
+
});
|
|
352
454
|
|
|
353
455
|
// WHEN
|
|
354
456
|
const xhr = new XMLHttpRequestMock();
|
|
@@ -369,10 +471,12 @@ describe('DdRumResourceTracking', () => {
|
|
|
369
471
|
// GIVEN
|
|
370
472
|
const method = 'GET';
|
|
371
473
|
const url = 'https://api.example.com/v2/user';
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
474
|
+
xhrProxy.onTrackingStart({
|
|
475
|
+
tracingSamplingRate: 100,
|
|
476
|
+
firstPartyHostsRegex: firstPartyHostsRegexBuilder([
|
|
477
|
+
'api.example.com'
|
|
478
|
+
])
|
|
479
|
+
});
|
|
376
480
|
|
|
377
481
|
// WHEN
|
|
378
482
|
const xhr = new XMLHttpRequestMock();
|
|
@@ -393,7 +497,12 @@ describe('DdRumResourceTracking', () => {
|
|
|
393
497
|
// GIVEN
|
|
394
498
|
const method = 'GET';
|
|
395
499
|
const url = 'https://api.example.com/v2/user';
|
|
396
|
-
|
|
500
|
+
xhrProxy.onTrackingStart({
|
|
501
|
+
tracingSamplingRate: 50,
|
|
502
|
+
firstPartyHostsRegex: firstPartyHostsRegexBuilder([
|
|
503
|
+
'api.example.com'
|
|
504
|
+
])
|
|
505
|
+
});
|
|
397
506
|
jest.spyOn(global.Math, 'random').mockReturnValue(0.7);
|
|
398
507
|
|
|
399
508
|
// WHEN
|
|
@@ -423,10 +532,10 @@ describe('DdRumResourceTracking', () => {
|
|
|
423
532
|
// GIVEN
|
|
424
533
|
const method = 'GET';
|
|
425
534
|
const url = 'https://api.example.com/v2/user';
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
);
|
|
535
|
+
xhrProxy.onTrackingStart({
|
|
536
|
+
tracingSamplingRate: 100,
|
|
537
|
+
firstPartyHostsRegex: firstPartyHostsRegexBuilder([])
|
|
538
|
+
});
|
|
430
539
|
|
|
431
540
|
jest.doMock('react-native/Libraries/Utilities/Platform', () => ({
|
|
432
541
|
OS: platform
|
|
@@ -466,10 +575,10 @@ describe('DdRumResourceTracking', () => {
|
|
|
466
575
|
// GIVEN
|
|
467
576
|
const method = 'GET';
|
|
468
577
|
const url = 'https://api.example.com/v2/user';
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
);
|
|
578
|
+
xhrProxy.onTrackingStart({
|
|
579
|
+
tracingSamplingRate: 100,
|
|
580
|
+
firstPartyHostsRegex: firstPartyHostsRegexBuilder([])
|
|
581
|
+
});
|
|
473
582
|
|
|
474
583
|
jest.doMock('react-native/Libraries/Utilities/Platform', () => ({
|
|
475
584
|
OS: platform
|
|
@@ -512,10 +621,10 @@ describe('DdRumResourceTracking', () => {
|
|
|
512
621
|
// GIVEN
|
|
513
622
|
const method = 'GET';
|
|
514
623
|
const url = 'https://api.example.com/v2/user';
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
);
|
|
624
|
+
xhrProxy.onTrackingStart({
|
|
625
|
+
tracingSamplingRate: 100,
|
|
626
|
+
firstPartyHostsRegex: firstPartyHostsRegexBuilder([])
|
|
627
|
+
});
|
|
519
628
|
|
|
520
629
|
// WHEN
|
|
521
630
|
const xhr = new XMLHttpRequestMock();
|
|
@@ -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';
|