@datadog/mobile-react-native 1.0.0-rc8 → 1.1.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 -1
- package/android/build.gradle +73 -3
- package/android/gradle.properties +1 -0
- package/android/src/main/kotlin/com/datadog/reactnative/DatadogSDKWrapper.kt +54 -0
- package/android/src/main/kotlin/com/datadog/reactnative/DatadogWrapper.kt +86 -0
- package/android/src/main/{java → kotlin}/com/datadog/reactnative/DdLogs.kt +27 -11
- package/android/src/main/kotlin/com/datadog/reactnative/DdRum.kt +305 -0
- package/android/src/main/kotlin/com/datadog/reactnative/DdSdk.kt +280 -0
- package/android/src/main/{java → kotlin}/com/datadog/reactnative/DdSdkBridgeExt.kt +2 -2
- package/android/src/main/kotlin/com/datadog/reactnative/DdSdkConfiguration.kt +29 -0
- package/android/src/main/{java → kotlin}/com/datadog/reactnative/DdSdkConfigurationExt.kt +2 -4
- package/android/src/main/{java → kotlin}/com/datadog/reactnative/DdSdkReactNativePackage.kt +3 -0
- package/android/src/main/kotlin/com/datadog/reactnative/DdTrace.kt +86 -0
- package/android/src/main/kotlin/com/datadog/reactnative/GlobalState.kt +32 -0
- package/android/src/main/kotlin/com/datadog/reactnative/NoOpViewTrackingStrategy.kt +23 -0
- package/android/src/main/kotlin/com/datadog/reactnative/ProxyAuthenticator.kt +60 -0
- package/android/src/test/kotlin/com/datadog/reactnative/DdLogsTest.kt +170 -0
- package/android/src/test/kotlin/com/datadog/reactnative/DdRumTest.kt +408 -0
- package/android/src/test/kotlin/com/datadog/reactnative/DdSdkTest.kt +1547 -0
- package/android/src/test/kotlin/com/datadog/reactnative/DdTraceTest.kt +306 -0
- package/android/src/test/kotlin/com/datadog/reactnative/GlobalStateTest.kt +118 -0
- package/android/src/test/kotlin/com/datadog/reactnative/ProxyAuthenticatorTest.kt +123 -0
- package/android/src/test/kotlin/com/datadog/tools/unit/DdSdkConfigurationExt.kt +33 -0
- package/android/src/test/kotlin/com/datadog/tools/unit/GenericAssert.kt +43 -0
- package/android/src/test/kotlin/com/datadog/tools/unit/MapExt.kt +22 -0
- package/android/src/test/kotlin/com/datadog/tools/unit/ReflectUtils.kt +267 -0
- package/android/src/test/kotlin/com/datadog/tools/unit/forge/BaseConfigurator.kt +26 -0
- package/android/src/test/kotlin/com/datadog/tools/unit/forge/DdSdkConfigurationForgeryFactory.kt +33 -0
- package/android/src/test/kotlin/com/datadog/tools/unit/forge/PackageInfoForgeryFactory.kt +20 -0
- package/android/src/test/kotlin/com/datadog/tools/unit/forge/Throwable.kt +31 -0
- package/android/src/test/kotlin/com/datadog/tools/unit/forge/ThrowableForgeryFactory.kt +21 -0
- package/android/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker +1 -0
- package/datadog-sourcemaps.gradle +137 -0
- package/ios/Sources/AnyEncodable.swift +138 -0
- package/ios/Sources/Attributes.swift +101 -0
- package/ios/Sources/DdLogs.swift +35 -11
- package/ios/Sources/DdRum.m +3 -1
- package/ios/Sources/DdRum.swift +184 -22
- package/ios/Sources/DdSdk.swift +190 -10
- package/ios/Sources/DdSdkConfiguration.swift +51 -0
- package/ios/Sources/DdTrace.swift +41 -6
- package/ios/Sources/GlobalState.swift +28 -0
- package/ios/Sources/QueueHolder.swift +10 -0
- package/ios/Sources/RNDdSdkConfiguration.swift +5 -6
- package/lib/commonjs/DdSdkReactNative.js +16 -2
- package/lib/commonjs/DdSdkReactNative.js.map +1 -1
- package/lib/commonjs/DdSdkReactNativeConfiguration.js +24 -0
- package/lib/commonjs/DdSdkReactNativeConfiguration.js.map +1 -1
- package/lib/commonjs/foundation.js +36 -2
- package/lib/commonjs/foundation.js.map +1 -1
- package/lib/commonjs/nativeModulesTypes.js +36 -0
- package/lib/commonjs/nativeModulesTypes.js.map +1 -0
- package/lib/commonjs/rum/instrumentation/DdEventsInterceptor.js +4 -17
- package/lib/commonjs/rum/instrumentation/DdEventsInterceptor.js.map +1 -1
- package/lib/commonjs/rum/instrumentation/DdRumErrorTracking.js +4 -4
- package/lib/commonjs/rum/instrumentation/DdRumErrorTracking.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/{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/types.js +26 -1
- package/lib/commonjs/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 +15 -1
- package/lib/module/DdSdkReactNative.js.map +1 -1
- package/lib/module/DdSdkReactNativeConfiguration.js +24 -0
- package/lib/module/DdSdkReactNativeConfiguration.js.map +1 -1
- package/lib/module/foundation.js +36 -2
- package/lib/module/foundation.js.map +1 -1
- package/lib/module/nativeModulesTypes.js +26 -0
- package/lib/module/nativeModulesTypes.js.map +1 -0
- package/lib/module/rum/instrumentation/DdEventsInterceptor.js +2 -14
- package/lib/module/rum/instrumentation/DdEventsInterceptor.js.map +1 -1
- package/lib/module/rum/instrumentation/DdRumErrorTracking.js +3 -4
- package/lib/module/rum/instrumentation/DdRumErrorTracking.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/{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/types.js +23 -0
- package/lib/module/types.js.map +1 -1
- package/lib/module/version.js +1 -1
- package/lib/module/version.js.map +1 -1
- package/lib/typescript/DdSdkReactNative.d.ts +2 -0
- package/lib/typescript/DdSdkReactNativeConfiguration.d.ts +20 -0
- package/lib/typescript/foundation.d.ts +3 -2
- package/lib/typescript/nativeModulesTypes.d.ts +168 -0
- package/lib/typescript/rum/instrumentation/DdEventsInterceptor.d.ts +0 -15
- 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 +20 -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/types.d.ts +42 -7
- package/lib/typescript/version.d.ts +1 -1
- package/package.json +7 -5
- package/src/DdSdkReactNative.tsx +21 -1
- package/src/DdSdkReactNativeConfiguration.tsx +20 -0
- package/src/__tests__/DdSdkReactNative.test.tsx +87 -8
- package/src/__tests__/foundation.test.ts +79 -0
- package/src/__tests__/rum/instrumentation/DdEventsInterceptor.test.tsx +9 -9
- package/src/__tests__/rum/instrumentation/DdRumUserInteractionTracking.test.tsx +1 -1
- package/src/foundation.tsx +40 -11
- package/src/nativeModulesTypes.ts +258 -0
- package/src/rum/instrumentation/DdEventsInterceptor.tsx +2 -17
- package/src/rum/instrumentation/DdRumErrorTracking.tsx +3 -4
- 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 +27 -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/types.tsx +62 -7
- package/src/version.ts +1 -1
- package/android/src/main/java/com/datadog/reactnative/DdRum.kt +0 -142
- package/android/src/main/java/com/datadog/reactnative/DdSdk.kt +0 -67
- package/android/src/main/java/com/datadog/reactnative/DdTrace.kt +0 -51
- 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
|
@@ -0,0 +1,69 @@
|
|
|
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 { filterDevResource } from '../internalDevResourceBlocklist';
|
|
8
|
+
|
|
9
|
+
import { ResourceMockFactory } from './__utils__/ResourceMockFactory';
|
|
10
|
+
|
|
11
|
+
const resourceMockFactory = new ResourceMockFactory();
|
|
12
|
+
|
|
13
|
+
describe('internalDevResourceBlocklist', () => {
|
|
14
|
+
describe('filterDevResource', () => {
|
|
15
|
+
it.each(['192.168.1.20', '10.46.29.155', '172.28.1.20'])(
|
|
16
|
+
'returns null when a expo logs call with ip %s is made',
|
|
17
|
+
ip => {
|
|
18
|
+
const resource = resourceMockFactory.getCustomResource({
|
|
19
|
+
request: {
|
|
20
|
+
method: 'GET',
|
|
21
|
+
url: `http://${ip}:8081/logs`,
|
|
22
|
+
kind: 'xhr'
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
expect(filterDevResource(resource)).toBeNull();
|
|
26
|
+
}
|
|
27
|
+
);
|
|
28
|
+
it('returns null when an expo logs call with custom port is made', () => {
|
|
29
|
+
const resource = resourceMockFactory.getCustomResource({
|
|
30
|
+
request: {
|
|
31
|
+
method: 'GET',
|
|
32
|
+
url: 'http://10.46.29.155:19000/logs',
|
|
33
|
+
kind: 'xhr'
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
expect(filterDevResource(resource)).toBeNull();
|
|
37
|
+
});
|
|
38
|
+
it('returns null when a rn symbolicate call is made', () => {
|
|
39
|
+
const resource = resourceMockFactory.getCustomResource({
|
|
40
|
+
request: {
|
|
41
|
+
method: 'GET',
|
|
42
|
+
url: 'http://localhost:8081/symbolicate',
|
|
43
|
+
kind: 'xhr'
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
expect(filterDevResource(resource)).toBeNull();
|
|
47
|
+
});
|
|
48
|
+
it('returns null when an rn symbolicate call with custom port is made', () => {
|
|
49
|
+
const resource = resourceMockFactory.getCustomResource({
|
|
50
|
+
request: {
|
|
51
|
+
method: 'GET',
|
|
52
|
+
url: 'http://localhost:40/symbolicate',
|
|
53
|
+
kind: 'xhr'
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
expect(filterDevResource(resource)).toBeNull();
|
|
57
|
+
});
|
|
58
|
+
it('returns the resource when the resource is not a dev resource', () => {
|
|
59
|
+
const resource = resourceMockFactory.getCustomResource({
|
|
60
|
+
request: {
|
|
61
|
+
method: 'GET',
|
|
62
|
+
url: 'http://11.22.33.22:443/logs',
|
|
63
|
+
kind: 'xhr'
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
expect(filterDevResource(resource)).not.toBeNull();
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
});
|
|
@@ -0,0 +1,50 @@
|
|
|
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 type { RUMResource } from '../../domain/interfaces/RumResource';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Expo sends all console.* calls to the packager. As we log all API calls
|
|
11
|
+
* when the SDKVerbosity is DEBUG, this would result in an infinite loop of
|
|
12
|
+
* `console.log` and API calls, creating 250 RUM resources per second.
|
|
13
|
+
*
|
|
14
|
+
* The hostname is always going to be localhost or a local IP.
|
|
15
|
+
*
|
|
16
|
+
* An example URL is http://192.168.1.20:8081/logs or http://10.46.29.155:19000/logs
|
|
17
|
+
*/
|
|
18
|
+
const EXPO_DEV_LOGS_REGEX = new RegExp(
|
|
19
|
+
'^http://((10|172|192).[0-9]+.[0-9]+.[0-9]+|localhost):[0-9]+/logs$'
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* This call is made every time the RN packager reloads the js in dev mode.
|
|
24
|
+
*/
|
|
25
|
+
const RN_PACKAGER_SYMBOLICATE_REGEX = new RegExp(
|
|
26
|
+
'^http://localhost:[0-9]+/symbolicate$'
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
const internalResourceBlocklist: RegExp[] = [
|
|
30
|
+
EXPO_DEV_LOGS_REGEX,
|
|
31
|
+
RN_PACKAGER_SYMBOLICATE_REGEX
|
|
32
|
+
];
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Filters RN symbolicate calls and Expo logs calls that happen only in dev.
|
|
36
|
+
* @param resource RUMResource
|
|
37
|
+
*/
|
|
38
|
+
export const filterDevResource = (
|
|
39
|
+
resource: RUMResource
|
|
40
|
+
): RUMResource | null => {
|
|
41
|
+
// TODO: if we get the confirmation by Expo that the
|
|
42
|
+
// logs call is only made when __DEV__ is true, add an
|
|
43
|
+
// early return for when it is false.
|
|
44
|
+
for (const resourceRegex of internalResourceBlocklist) {
|
|
45
|
+
if (resourceRegex.test(resource.request.url)) {
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return resource;
|
|
50
|
+
};
|
package/src/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/resourceTiming.ts
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
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 { Platform } from 'react-native';
|
|
8
|
+
|
|
9
|
+
interface Timing {
|
|
10
|
+
/**
|
|
11
|
+
* Time relative (absolute in case of iOS) to some point, in ns.
|
|
12
|
+
*/
|
|
13
|
+
startTime: number;
|
|
14
|
+
/**
|
|
15
|
+
* Duration in ns.
|
|
16
|
+
*/
|
|
17
|
+
duration: number;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
interface ResourceTimings {
|
|
21
|
+
// unlike in Performance API it is not the time until request
|
|
22
|
+
// starts (requestStart, before it can be connect, SSL, DNS),
|
|
23
|
+
// but the time until the response is first seen
|
|
24
|
+
firstByte: Timing;
|
|
25
|
+
download: Timing;
|
|
26
|
+
// required by iOS, total timing from the beginning to the end
|
|
27
|
+
fetch: Timing;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function createTimings(
|
|
31
|
+
startTime: number,
|
|
32
|
+
responseStartTime: number,
|
|
33
|
+
responseEndTime: number
|
|
34
|
+
): ResourceTimings {
|
|
35
|
+
const firstByte = formatTiming(startTime, startTime, responseStartTime);
|
|
36
|
+
const download = formatTiming(
|
|
37
|
+
startTime,
|
|
38
|
+
responseStartTime,
|
|
39
|
+
responseEndTime
|
|
40
|
+
);
|
|
41
|
+
// needed for iOS, simply total duration from start to end
|
|
42
|
+
const fetch = formatTiming(startTime, startTime, responseEndTime);
|
|
43
|
+
|
|
44
|
+
return {
|
|
45
|
+
firstByte,
|
|
46
|
+
download,
|
|
47
|
+
fetch
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* @param origin Start time (absolute) of the request
|
|
53
|
+
* @param start Start time (absolute) of the timing
|
|
54
|
+
* @param end End time (absolute) of the timing
|
|
55
|
+
*/
|
|
56
|
+
function formatTiming(origin: number, start: number, end: number): Timing {
|
|
57
|
+
return {
|
|
58
|
+
duration: timeToNanos(end - start),
|
|
59
|
+
// if it is Android, startTime should be relative to the origin,
|
|
60
|
+
// if it is iOS - absolute (unix timestamp)
|
|
61
|
+
startTime:
|
|
62
|
+
Platform.OS === 'ios'
|
|
63
|
+
? timeToNanos(start)
|
|
64
|
+
: timeToNanos(start - origin)
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function timeToNanos(durationMs: number): number {
|
|
69
|
+
return +(durationMs * 1e6).toFixed(0);
|
|
70
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
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
|
+
import type { Hostname } from '../domain/firstPartyHosts';
|
|
10
|
+
|
|
11
|
+
// matches what is between the first "://" and the next "/", ":" or whitespace
|
|
12
|
+
const hostRegex = '^.+://([^:/\\s]+)';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Returns the host from an URL.
|
|
16
|
+
* @returns the host (without the port) or null if could not cast the URL as host
|
|
17
|
+
*/
|
|
18
|
+
export const URLHostParser = (url: string): Hostname | null => {
|
|
19
|
+
try {
|
|
20
|
+
const matchedHost = url.match(hostRegex);
|
|
21
|
+
if (matchedHost === null) {
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
// [0] is the input, [1] is the captured group
|
|
25
|
+
return matchedHost[1] as Hostname;
|
|
26
|
+
} catch (e) {
|
|
27
|
+
InternalLog.log(`Impossible to cast ${url} as URL`, SdkVerbosity.WARN);
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
};
|
|
@@ -0,0 +1,197 @@
|
|
|
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 Timer from '../../../../Timer';
|
|
8
|
+
import type { DdRumResourceTracingAttributes } from '../domain/distributedTracing';
|
|
9
|
+
import { getTracingAttributes } from '../domain/distributedTracing';
|
|
10
|
+
import type { RequestProxyOptions } from '../domain/interfaces/RequestProxy';
|
|
11
|
+
import { RequestProxy } from '../domain/interfaces/RequestProxy';
|
|
12
|
+
|
|
13
|
+
import type { ResourceReporter } from './DatadogRumResource/ResourceReporter';
|
|
14
|
+
import { URLHostParser } from './URLHostParser';
|
|
15
|
+
import { calculateResponseSize } from './responseSize';
|
|
16
|
+
|
|
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
|
+
const RESPONSE_START_LABEL = 'response_start';
|
|
24
|
+
|
|
25
|
+
interface DdRumXhr extends XMLHttpRequest {
|
|
26
|
+
_datadog_xhr: DdRumXhrContext;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
interface DdRumXhrContext {
|
|
30
|
+
method: string;
|
|
31
|
+
url: string;
|
|
32
|
+
reported: boolean;
|
|
33
|
+
timer: Timer;
|
|
34
|
+
tracingAttributes: DdRumResourceTracingAttributes;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
interface XHRProxyProviders {
|
|
38
|
+
xhrType: typeof XMLHttpRequest;
|
|
39
|
+
resourceReporter: ResourceReporter;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Proxies XMLHTTPRequest to track resources.
|
|
44
|
+
*/
|
|
45
|
+
export class XHRProxy extends RequestProxy {
|
|
46
|
+
private providers: XHRProxyProviders;
|
|
47
|
+
private static originalXhrOpen: typeof XMLHttpRequest.prototype.open;
|
|
48
|
+
private static originalXhrSend: typeof XMLHttpRequest.prototype.send;
|
|
49
|
+
|
|
50
|
+
constructor(providers: XHRProxyProviders) {
|
|
51
|
+
super();
|
|
52
|
+
this.providers = providers;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
onTrackingStart = (context: RequestProxyOptions) => {
|
|
56
|
+
XHRProxy.originalXhrOpen = this.providers.xhrType.prototype.open;
|
|
57
|
+
XHRProxy.originalXhrSend = this.providers.xhrType.prototype.send;
|
|
58
|
+
proxyRequests(this.providers, context);
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
onTrackingStop = () => {
|
|
62
|
+
this.providers.xhrType.prototype.open = XHRProxy.originalXhrOpen;
|
|
63
|
+
this.providers.xhrType.prototype.send = XHRProxy.originalXhrSend;
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const proxyRequests = (
|
|
68
|
+
providers: XHRProxyProviders,
|
|
69
|
+
context: RequestProxyOptions
|
|
70
|
+
): void => {
|
|
71
|
+
proxyOpen(providers, context);
|
|
72
|
+
proxySend(providers);
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
const proxyOpen = (
|
|
76
|
+
{ xhrType }: XHRProxyProviders,
|
|
77
|
+
context: RequestProxyOptions
|
|
78
|
+
): void => {
|
|
79
|
+
const originalXhrOpen = xhrType.prototype.open;
|
|
80
|
+
const firstPartyHostsRegex = context.firstPartyHostsRegex;
|
|
81
|
+
const tracingSamplingRate = context.tracingSamplingRate;
|
|
82
|
+
|
|
83
|
+
xhrType.prototype.open = function (
|
|
84
|
+
this: DdRumXhr,
|
|
85
|
+
method: string,
|
|
86
|
+
url: string
|
|
87
|
+
) {
|
|
88
|
+
const hostname = URLHostParser(url);
|
|
89
|
+
// Keep track of the method and url
|
|
90
|
+
// start time is tracked by the `send` method
|
|
91
|
+
this._datadog_xhr = {
|
|
92
|
+
method,
|
|
93
|
+
url,
|
|
94
|
+
reported: false,
|
|
95
|
+
timer: new Timer(),
|
|
96
|
+
tracingAttributes: getTracingAttributes({
|
|
97
|
+
hostname,
|
|
98
|
+
firstPartyHostsRegex,
|
|
99
|
+
tracingSamplingRate
|
|
100
|
+
})
|
|
101
|
+
};
|
|
102
|
+
// eslint-disable-next-line prefer-rest-params
|
|
103
|
+
return originalXhrOpen.apply(this, arguments as any);
|
|
104
|
+
};
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
const proxySend = (providers: XHRProxyProviders): void => {
|
|
108
|
+
const xhrType = providers.xhrType;
|
|
109
|
+
const originalXhrSend = xhrType.prototype.send;
|
|
110
|
+
|
|
111
|
+
xhrType.prototype.send = function (this: DdRumXhr) {
|
|
112
|
+
if (this._datadog_xhr) {
|
|
113
|
+
// keep track of start time
|
|
114
|
+
this._datadog_xhr.timer.start();
|
|
115
|
+
this.setRequestHeader(ORIGIN_HEADER_KEY, ORIGIN_RUM);
|
|
116
|
+
|
|
117
|
+
const tracingAttributes = this._datadog_xhr.tracingAttributes;
|
|
118
|
+
this.setRequestHeader(
|
|
119
|
+
SAMPLING_PRIORITY_HEADER_KEY,
|
|
120
|
+
tracingAttributes.samplingPriorityHeader
|
|
121
|
+
);
|
|
122
|
+
if (tracingAttributes.tracingStrategy !== 'DISCARD') {
|
|
123
|
+
this.setRequestHeader(
|
|
124
|
+
TRACE_ID_HEADER_KEY,
|
|
125
|
+
tracingAttributes.traceId
|
|
126
|
+
);
|
|
127
|
+
this.setRequestHeader(
|
|
128
|
+
PARENT_ID_HEADER_KEY,
|
|
129
|
+
tracingAttributes.spanId
|
|
130
|
+
);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
proxyOnReadyStateChange(this, providers);
|
|
135
|
+
|
|
136
|
+
// eslint-disable-next-line prefer-rest-params
|
|
137
|
+
return originalXhrSend.apply(this, arguments as any);
|
|
138
|
+
};
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
const proxyOnReadyStateChange = (
|
|
142
|
+
xhrProxy: DdRumXhr,
|
|
143
|
+
providers: XHRProxyProviders
|
|
144
|
+
): void => {
|
|
145
|
+
const xhrType = providers.xhrType;
|
|
146
|
+
const originalOnreadystatechange = xhrProxy.onreadystatechange;
|
|
147
|
+
|
|
148
|
+
xhrProxy.onreadystatechange = function () {
|
|
149
|
+
if (xhrProxy.readyState === xhrType.DONE) {
|
|
150
|
+
if (!xhrProxy._datadog_xhr.reported) {
|
|
151
|
+
reportXhr(xhrProxy, providers.resourceReporter);
|
|
152
|
+
xhrProxy._datadog_xhr.reported = true;
|
|
153
|
+
}
|
|
154
|
+
} else if (xhrProxy.readyState === xhrType.HEADERS_RECEIVED) {
|
|
155
|
+
xhrProxy._datadog_xhr.timer.recordTick(RESPONSE_START_LABEL);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
if (originalOnreadystatechange) {
|
|
159
|
+
// eslint-disable-next-line prefer-rest-params
|
|
160
|
+
originalOnreadystatechange.apply(xhrProxy, arguments as any);
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
const reportXhr = async (
|
|
166
|
+
xhrProxy: DdRumXhr,
|
|
167
|
+
resourceReporter: ResourceReporter
|
|
168
|
+
): Promise<void> => {
|
|
169
|
+
const responseSize = calculateResponseSize(xhrProxy);
|
|
170
|
+
|
|
171
|
+
const context = xhrProxy._datadog_xhr;
|
|
172
|
+
|
|
173
|
+
const key = `${context.timer.startTime}/${context.method}`;
|
|
174
|
+
|
|
175
|
+
context.timer.stop();
|
|
176
|
+
|
|
177
|
+
resourceReporter.reportResource({
|
|
178
|
+
key,
|
|
179
|
+
request: {
|
|
180
|
+
method: context.method,
|
|
181
|
+
url: context.url,
|
|
182
|
+
kind: 'xhr'
|
|
183
|
+
},
|
|
184
|
+
tracingAttributes: context.tracingAttributes,
|
|
185
|
+
response: {
|
|
186
|
+
statusCode: xhrProxy.status,
|
|
187
|
+
size: responseSize
|
|
188
|
+
},
|
|
189
|
+
timings: {
|
|
190
|
+
startTime: context.timer.startTime,
|
|
191
|
+
stopTime: context.timer.stopTime,
|
|
192
|
+
responseStartTime: context.timer.hasTickFor(RESPONSE_START_LABEL)
|
|
193
|
+
? context.timer.timeAt(RESPONSE_START_LABEL)
|
|
194
|
+
: undefined
|
|
195
|
+
}
|
|
196
|
+
});
|
|
197
|
+
};
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* Copyright 2016-Present Datadog, Inc.
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
import { URLHostParser } from '
|
|
7
|
+
import { URLHostParser } from '../URLHostParser';
|
|
8
8
|
|
|
9
9
|
describe('URLHostParser', () => {
|
|
10
10
|
it('returns the host when a classic URL is provided', () => {
|
|
@@ -33,8 +33,8 @@ describe('URLHostParser', () => {
|
|
|
33
33
|
const egyptianURL = 'https://api.example.مصر./api.json';
|
|
34
34
|
expect(URLHostParser(egyptianURL)).toBe('api.example.مصر.');
|
|
35
35
|
});
|
|
36
|
-
it('
|
|
36
|
+
it('returns null if not given an URL', () => {
|
|
37
37
|
const url = 'crash';
|
|
38
|
-
expect(
|
|
38
|
+
expect(URLHostParser(url)).toBeNull();
|
|
39
39
|
});
|
|
40
40
|
});
|