@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,34 @@
|
|
|
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
|
+
import { InternalLog } from '../../../../InternalLog';
|
|
7
|
+
import { SdkVerbosity } from '../../../../SdkVerbosity';
|
|
8
|
+
// This regex does not match anything
|
|
9
|
+
export const NO_MATCH_REGEX = new RegExp('a^'); // From https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions
|
|
10
|
+
|
|
11
|
+
const escapeRegExp = string => {
|
|
12
|
+
return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); // $& means the whole matched string
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export const firstPartyHostsRegexBuilder = firstPartyHosts => {
|
|
16
|
+
if (firstPartyHosts.length === 0) {
|
|
17
|
+
return NO_MATCH_REGEX;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
try {
|
|
21
|
+
// A regexp for matching hosts, e.g. when `hosts` is "example.com", it will match
|
|
22
|
+
// "example.com", "api.example.com", but not "foo.com".
|
|
23
|
+
const firstPartyHostsRegex = new RegExp(`^(.*\\.)*(${firstPartyHosts.map(host => `${escapeRegExp(host)}$`).join('|')})`);
|
|
24
|
+
firstPartyHostsRegex.test('test_the_regex_is_valid');
|
|
25
|
+
return firstPartyHostsRegex;
|
|
26
|
+
} catch (e) {
|
|
27
|
+
InternalLog.log(`Invalid first party hosts list ${JSON.stringify(firstPartyHosts)}. Regular expressions are not allowed.`, SdkVerbosity.WARN);
|
|
28
|
+
return NO_MATCH_REGEX;
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
export const isHostFirstParty = (hostname, firstPartyHostsRegex) => {
|
|
32
|
+
return firstPartyHostsRegex.test(hostname);
|
|
33
|
+
};
|
|
34
|
+
//# sourceMappingURL=firstPartyHosts.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["firstPartyHosts.ts"],"names":["InternalLog","SdkVerbosity","NO_MATCH_REGEX","RegExp","escapeRegExp","string","replace","firstPartyHostsRegexBuilder","firstPartyHosts","length","firstPartyHostsRegex","map","host","join","test","e","log","JSON","stringify","WARN","isHostFirstParty","hostname"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AAEA,SAASA,WAAT,QAA4B,yBAA5B;AACA,SAASC,YAAT,QAA6B,0BAA7B;AAIA;AACA,OAAO,MAAMC,cAAc,GAAG,IAAIC,MAAJ,CAAW,IAAX,CAAvB,C,CAEP;;AACA,MAAMC,YAAY,GAAIC,MAAD,IAAoB;AACrC,SAAOA,MAAM,CAACC,OAAP,CAAe,qBAAf,EAAsC,MAAtC,CAAP,CADqC,CACiB;AACzD,CAFD;;AAIA,OAAO,MAAMC,2BAA2B,GACpCC,eADuC,IAE9B;AACT,MAAIA,eAAe,CAACC,MAAhB,KAA2B,CAA/B,EAAkC;AAC9B,WAAOP,cAAP;AACH;;AACD,MAAI;AACA;AACA;AACA,UAAMQ,oBAAoB,GAAG,IAAIP,MAAJ,CACxB,aAAYK,eAAe,CACvBG,GADQ,CACJC,IAAI,IAAK,GAAER,YAAY,CAACQ,IAAD,CAAO,GAD1B,EAERC,IAFQ,CAEH,GAFG,CAEE,GAHU,CAA7B;AAKAH,IAAAA,oBAAoB,CAACI,IAArB,CAA0B,yBAA1B;AACA,WAAOJ,oBAAP;AACH,GAVD,CAUE,OAAOK,CAAP,EAAU;AACRf,IAAAA,WAAW,CAACgB,GAAZ,CACK,kCAAiCC,IAAI,CAACC,SAAL,CAC9BV,eAD8B,CAEhC,wCAHN,EAIIP,YAAY,CAACkB,IAJjB;AAMA,WAAOjB,cAAP;AACH;AACJ,CAzBM;AA2BP,OAAO,MAAMkB,gBAAgB,GAAG,CAC5BC,QAD4B,EAE5BX,oBAF4B,KAGlB;AACV,SAAOA,oBAAoB,CAACI,IAArB,CAA0BO,QAA1B,CAAP;AACH,CALM","sourcesContent":["/*\n * Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.\n * This product includes software developed at Datadog (https://www.datadoghq.com/).\n * Copyright 2016-Present Datadog, Inc.\n */\n\nimport { InternalLog } from '../../../../InternalLog';\nimport { SdkVerbosity } from '../../../../SdkVerbosity';\n\nexport type Hostname = { _type: 'Hostname' } & string;\n\n// This regex does not match anything\nexport const NO_MATCH_REGEX = new RegExp('a^');\n\n// From https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions\nconst escapeRegExp = (string: string) => {\n return string.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&'); // $& means the whole matched string\n};\n\nexport const firstPartyHostsRegexBuilder = (\n firstPartyHosts: string[]\n): RegExp => {\n if (firstPartyHosts.length === 0) {\n return NO_MATCH_REGEX;\n }\n try {\n // A regexp for matching hosts, e.g. when `hosts` is \"example.com\", it will match\n // \"example.com\", \"api.example.com\", but not \"foo.com\".\n const firstPartyHostsRegex = new RegExp(\n `^(.*\\\\.)*(${firstPartyHosts\n .map(host => `${escapeRegExp(host)}$`)\n .join('|')})`\n );\n firstPartyHostsRegex.test('test_the_regex_is_valid');\n return firstPartyHostsRegex;\n } catch (e) {\n InternalLog.log(\n `Invalid first party hosts list ${JSON.stringify(\n firstPartyHosts\n )}. Regular expressions are not allowed.`,\n SdkVerbosity.WARN\n );\n return NO_MATCH_REGEX;\n }\n};\n\nexport const isHostFirstParty = (\n hostname: Hostname,\n firstPartyHostsRegex: RegExp\n): boolean => {\n return firstPartyHostsRegex.test(hostname);\n};\n"]}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
|
|
5
|
+
* This product includes software developed at Datadog (https://www.datadoghq.com/).
|
|
6
|
+
* Copyright 2016-Present Datadog, Inc.
|
|
7
|
+
*/
|
|
8
|
+
export class RequestProxy {
|
|
9
|
+
constructor() {
|
|
10
|
+
_defineProperty(this, "onTrackingStart", void 0);
|
|
11
|
+
|
|
12
|
+
_defineProperty(this, "onTrackingStop", void 0);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=RequestProxy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["RequestProxy.ts"],"names":["RequestProxy"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AAOA,OAAO,MAAeA,YAAf,CAA4B;AAAA;AAAA;;AAAA;AAAA;;AAAA","sourcesContent":["/*\n * Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.\n * This product includes software developed at Datadog (https://www.datadoghq.com/).\n * Copyright 2016-Present Datadog, Inc.\n */\n\nexport interface RequestProxyOptions {\n tracingSamplingRate: number;\n firstPartyHostsRegex: RegExp;\n}\n\nexport abstract class RequestProxy {\n abstract onTrackingStart: (context: RequestProxyOptions) => void;\n abstract onTrackingStop: () => void;\n}\n"]}
|
|
File without changes
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
|
|
5
|
+
* This product includes software developed at Datadog (https://www.datadoghq.com/).
|
|
6
|
+
* Copyright 2016-Present Datadog, Inc.
|
|
7
|
+
*/
|
|
8
|
+
import { DdRum } from '../../../../../foundation';
|
|
9
|
+
import { createTimings } from './resourceTiming';
|
|
10
|
+
export class ResourceReporter {
|
|
11
|
+
constructor(resourceMappers) {
|
|
12
|
+
_defineProperty(this, "mappers", void 0);
|
|
13
|
+
|
|
14
|
+
_defineProperty(this, "reportResource", resource => {
|
|
15
|
+
let modifiedResource = resource;
|
|
16
|
+
|
|
17
|
+
for (const mapper of this.mappers) {
|
|
18
|
+
modifiedResource = mapper(resource);
|
|
19
|
+
|
|
20
|
+
if (modifiedResource === null) {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
reportResource(modifiedResource);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
this.mappers = resourceMappers;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const formatResourceStartContext = tracingAttributes => {
|
|
34
|
+
return tracingAttributes.tracingStrategy === 'DISCARD' ? undefined : {
|
|
35
|
+
'_dd.span_id': tracingAttributes.spanId,
|
|
36
|
+
'_dd.trace_id': tracingAttributes.traceId
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
const formatResourceStopContext = timings => {
|
|
41
|
+
return {
|
|
42
|
+
'_dd.resource_timings': timings.responseStartTime !== undefined ? createTimings(timings.startTime, timings.responseStartTime, timings.stopTime) : null
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
const reportResource = async resource => {
|
|
47
|
+
await DdRum.startResource(resource.key, resource.request.method, resource.request.url, formatResourceStartContext(resource.tracingAttributes), resource.timings.startTime);
|
|
48
|
+
DdRum.stopResource(resource.key, resource.response.statusCode, resource.request.kind, resource.response.size, formatResourceStopContext(resource.timings), resource.timings.stopTime);
|
|
49
|
+
};
|
|
50
|
+
//# sourceMappingURL=ResourceReporter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["ResourceReporter.ts"],"names":["DdRum","createTimings","ResourceReporter","constructor","resourceMappers","resource","modifiedResource","mapper","mappers","reportResource","formatResourceStartContext","tracingAttributes","tracingStrategy","undefined","spanId","traceId","formatResourceStopContext","timings","responseStartTime","startTime","stopTime","startResource","key","request","method","url","stopResource","response","statusCode","kind","size"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AAEA,SAASA,KAAT,QAAsB,2BAAtB;AAGA,SAASC,aAAT,QAA8B,kBAA9B;AAIA,OAAO,MAAMC,gBAAN,CAAuB;AAG1BC,EAAAA,WAAW,CAACC,eAAD,EAAoC;AAAA;;AAAA,4CAI7BC,QAAD,IAA2B;AACxC,UAAIC,gBAAoC,GAAGD,QAA3C;;AAEA,WAAK,MAAME,MAAX,IAAqB,KAAKC,OAA1B,EAAmC;AAC/BF,QAAAA,gBAAgB,GAAGC,MAAM,CAACF,QAAD,CAAzB;;AACA,YAAIC,gBAAgB,KAAK,IAAzB,EAA+B;AAC3B;AACH;AACJ;;AAEDG,MAAAA,cAAc,CAACH,gBAAD,CAAd;AACH,KAf8C;;AAC3C,SAAKE,OAAL,GAAeJ,eAAf;AACH;;AALyB;;AAqB9B,MAAMM,0BAA0B,GAC5BC,iBAD+B,IAEO;AACtC,SAAOA,iBAAiB,CAACC,eAAlB,KAAsC,SAAtC,GACDC,SADC,GAED;AACI,mBAAeF,iBAAiB,CAACG,MADrC;AAEI,oBAAgBH,iBAAiB,CAACI;AAFtC,GAFN;AAMH,CATD;;AAWA,MAAMC,yBAAyB,GAC3BC,OAD8B,IAEJ;AAC1B,SAAO;AACH,4BACIA,OAAO,CAACC,iBAAR,KAA8BL,SAA9B,GACMZ,aAAa,CACTgB,OAAO,CAACE,SADC,EAETF,OAAO,CAACC,iBAFC,EAGTD,OAAO,CAACG,QAHC,CADnB,GAMM;AARP,GAAP;AAUH,CAbD;;AAeA,MAAMX,cAAc,GAAG,MAAOJ,QAAP,IAAiC;AACpD,QAAML,KAAK,CAACqB,aAAN,CACFhB,QAAQ,CAACiB,GADP,EAEFjB,QAAQ,CAACkB,OAAT,CAAiBC,MAFf,EAGFnB,QAAQ,CAACkB,OAAT,CAAiBE,GAHf,EAIFf,0BAA0B,CAACL,QAAQ,CAACM,iBAAV,CAJxB,EAKFN,QAAQ,CAACY,OAAT,CAAiBE,SALf,CAAN;AAQAnB,EAAAA,KAAK,CAAC0B,YAAN,CACIrB,QAAQ,CAACiB,GADb,EAEIjB,QAAQ,CAACsB,QAAT,CAAkBC,UAFtB,EAGIvB,QAAQ,CAACkB,OAAT,CAAiBM,IAHrB,EAIIxB,QAAQ,CAACsB,QAAT,CAAkBG,IAJtB,EAKId,yBAAyB,CAACX,QAAQ,CAACY,OAAV,CAL7B,EAMIZ,QAAQ,CAACY,OAAT,CAAiBG,QANrB;AAQH,CAjBD","sourcesContent":["/*\n * Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.\n * This product includes software developed at Datadog (https://www.datadoghq.com/).\n * Copyright 2016-Present Datadog, Inc.\n */\n\nimport { DdRum } from '../../../../../foundation';\nimport type { RUMResource } from '../../domain/interfaces/RumResource';\n\nimport { createTimings } from './resourceTiming';\n\ntype ResourceMapper = (resource: RUMResource) => RUMResource | null;\n\nexport class ResourceReporter {\n private mappers: ResourceMapper[];\n\n constructor(resourceMappers: ResourceMapper[]) {\n this.mappers = resourceMappers;\n }\n\n reportResource = (resource: RUMResource) => {\n let modifiedResource: RUMResource | null = resource;\n\n for (const mapper of this.mappers) {\n modifiedResource = mapper(resource);\n if (modifiedResource === null) {\n return;\n }\n }\n\n reportResource(modifiedResource);\n };\n}\n\nconst formatResourceStartContext = (\n tracingAttributes: RUMResource['tracingAttributes']\n): Record<string, unknown> | undefined => {\n return tracingAttributes.tracingStrategy === 'DISCARD'\n ? undefined\n : {\n '_dd.span_id': tracingAttributes.spanId,\n '_dd.trace_id': tracingAttributes.traceId\n };\n};\n\nconst formatResourceStopContext = (\n timings: RUMResource['timings']\n): Record<string, unknown> => {\n return {\n '_dd.resource_timings':\n timings.responseStartTime !== undefined\n ? createTimings(\n timings.startTime,\n timings.responseStartTime,\n timings.stopTime\n )\n : null\n };\n};\n\nconst reportResource = async (resource: RUMResource) => {\n await DdRum.startResource(\n resource.key,\n resource.request.method,\n resource.request.url,\n formatResourceStartContext(resource.tracingAttributes),\n resource.timings.startTime\n );\n\n DdRum.stopResource(\n resource.key,\n resource.response.statusCode,\n resource.request.kind,\n resource.response.size,\n formatResourceStopContext(resource.timings),\n resource.timings.stopTime\n );\n};\n"]}
|
|
@@ -0,0 +1,40 @@
|
|
|
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
|
+
/**
|
|
8
|
+
* Expo sends all console.* calls to the packager. As we log all API calls
|
|
9
|
+
* when the SDKVerbosity is DEBUG, this would result in an infinite loop of
|
|
10
|
+
* `console.log` and API calls, creating 250 RUM resources per second.
|
|
11
|
+
*
|
|
12
|
+
* The hostname is always going to be localhost or a local IP.
|
|
13
|
+
*
|
|
14
|
+
* An example URL is http://192.168.1.20:8081/logs or http://10.46.29.155:19000/logs
|
|
15
|
+
*/
|
|
16
|
+
const EXPO_DEV_LOGS_REGEX = new RegExp('^http://((10|172|192).[0-9]+.[0-9]+.[0-9]+|localhost):[0-9]+/logs$');
|
|
17
|
+
/**
|
|
18
|
+
* This call is made every time the RN packager reloads the js in dev mode.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
const RN_PACKAGER_SYMBOLICATE_REGEX = new RegExp('^http://localhost:[0-9]+/symbolicate$');
|
|
22
|
+
const internalResourceBlocklist = [EXPO_DEV_LOGS_REGEX, RN_PACKAGER_SYMBOLICATE_REGEX];
|
|
23
|
+
/**
|
|
24
|
+
* Filters RN symbolicate calls and Expo logs calls that happen only in dev.
|
|
25
|
+
* @param resource RUMResource
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
export const filterDevResource = resource => {
|
|
29
|
+
// TODO: if we get the confirmation by Expo that the
|
|
30
|
+
// logs call is only made when __DEV__ is true, add an
|
|
31
|
+
// early return for when it is false.
|
|
32
|
+
for (const resourceRegex of internalResourceBlocklist) {
|
|
33
|
+
if (resourceRegex.test(resource.request.url)) {
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return resource;
|
|
39
|
+
};
|
|
40
|
+
//# sourceMappingURL=internalDevResourceBlocklist.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["internalDevResourceBlocklist.ts"],"names":["EXPO_DEV_LOGS_REGEX","RegExp","RN_PACKAGER_SYMBOLICATE_REGEX","internalResourceBlocklist","filterDevResource","resource","resourceRegex","test","request","url"],"mappings":"AAAA;AACA;AACA;AACA;AACA;;AAIA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMA,mBAAmB,GAAG,IAAIC,MAAJ,CACxB,oEADwB,CAA5B;AAIA;AACA;AACA;;AACA,MAAMC,6BAA6B,GAAG,IAAID,MAAJ,CAClC,uCADkC,CAAtC;AAIA,MAAME,yBAAmC,GAAG,CACxCH,mBADwC,EAExCE,6BAFwC,CAA5C;AAKA;AACA;AACA;AACA;;AACA,OAAO,MAAME,iBAAiB,GAC1BC,QAD6B,IAER;AACrB;AACA;AACA;AACA,OAAK,MAAMC,aAAX,IAA4BH,yBAA5B,EAAuD;AACnD,QAAIG,aAAa,CAACC,IAAd,CAAmBF,QAAQ,CAACG,OAAT,CAAiBC,GAApC,CAAJ,EAA8C;AAC1C,aAAO,IAAP;AACH;AACJ;;AACD,SAAOJ,QAAP;AACH,CAZM","sourcesContent":["/*\n * Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.\n * This product includes software developed at Datadog (https://www.datadoghq.com/).\n * Copyright 2016-Present Datadog, Inc.\n */\n\nimport type { RUMResource } from '../../domain/interfaces/RumResource';\n\n/**\n * Expo sends all console.* calls to the packager. As we log all API calls\n * when the SDKVerbosity is DEBUG, this would result in an infinite loop of\n * `console.log` and API calls, creating 250 RUM resources per second.\n *\n * The hostname is always going to be localhost or a local IP.\n *\n * An example URL is http://192.168.1.20:8081/logs or http://10.46.29.155:19000/logs\n */\nconst EXPO_DEV_LOGS_REGEX = new RegExp(\n '^http://((10|172|192).[0-9]+.[0-9]+.[0-9]+|localhost):[0-9]+/logs$'\n);\n\n/**\n * This call is made every time the RN packager reloads the js in dev mode.\n */\nconst RN_PACKAGER_SYMBOLICATE_REGEX = new RegExp(\n '^http://localhost:[0-9]+/symbolicate$'\n);\n\nconst internalResourceBlocklist: RegExp[] = [\n EXPO_DEV_LOGS_REGEX,\n RN_PACKAGER_SYMBOLICATE_REGEX\n];\n\n/**\n * Filters RN symbolicate calls and Expo logs calls that happen only in dev.\n * @param resource RUMResource\n */\nexport const filterDevResource = (\n resource: RUMResource\n): RUMResource | null => {\n // TODO: if we get the confirmation by Expo that the\n // logs call is only made when __DEV__ is true, add an\n // early return for when it is false.\n for (const resourceRegex of internalResourceBlocklist) {\n if (resourceRegex.test(resource.request.url)) {\n return null;\n }\n }\n return resource;\n};\n"]}
|
|
@@ -0,0 +1,36 @@
|
|
|
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
|
+
import { Platform } from 'react-native';
|
|
7
|
+
export function createTimings(startTime, responseStartTime, responseEndTime) {
|
|
8
|
+
const firstByte = formatTiming(startTime, startTime, responseStartTime);
|
|
9
|
+
const download = formatTiming(startTime, responseStartTime, responseEndTime); // needed for iOS, simply total duration from start to end
|
|
10
|
+
|
|
11
|
+
const fetch = formatTiming(startTime, startTime, responseEndTime);
|
|
12
|
+
return {
|
|
13
|
+
firstByte,
|
|
14
|
+
download,
|
|
15
|
+
fetch
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* @param origin Start time (absolute) of the request
|
|
20
|
+
* @param start Start time (absolute) of the timing
|
|
21
|
+
* @param end End time (absolute) of the timing
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
function formatTiming(origin, start, end) {
|
|
25
|
+
return {
|
|
26
|
+
duration: timeToNanos(end - start),
|
|
27
|
+
// if it is Android, startTime should be relative to the origin,
|
|
28
|
+
// if it is iOS - absolute (unix timestamp)
|
|
29
|
+
startTime: Platform.OS === 'ios' ? timeToNanos(start) : timeToNanos(start - origin)
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function timeToNanos(durationMs) {
|
|
34
|
+
return +(durationMs * 1e6).toFixed(0);
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=resourceTiming.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["resourceTiming.ts"],"names":["Platform","createTimings","startTime","responseStartTime","responseEndTime","firstByte","formatTiming","download","fetch","origin","start","end","duration","timeToNanos","OS","durationMs","toFixed"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AAEA,SAASA,QAAT,QAAyB,cAAzB;AAuBA,OAAO,SAASC,aAAT,CACHC,SADG,EAEHC,iBAFG,EAGHC,eAHG,EAIY;AACf,QAAMC,SAAS,GAAGC,YAAY,CAACJ,SAAD,EAAYA,SAAZ,EAAuBC,iBAAvB,CAA9B;AACA,QAAMI,QAAQ,GAAGD,YAAY,CACzBJ,SADyB,EAEzBC,iBAFyB,EAGzBC,eAHyB,CAA7B,CAFe,CAOf;;AACA,QAAMI,KAAK,GAAGF,YAAY,CAACJ,SAAD,EAAYA,SAAZ,EAAuBE,eAAvB,CAA1B;AAEA,SAAO;AACHC,IAAAA,SADG;AAEHE,IAAAA,QAFG;AAGHC,IAAAA;AAHG,GAAP;AAKH;AAED;AACA;AACA;AACA;AACA;;AACA,SAASF,YAAT,CAAsBG,MAAtB,EAAsCC,KAAtC,EAAqDC,GAArD,EAA0E;AACtE,SAAO;AACHC,IAAAA,QAAQ,EAAEC,WAAW,CAACF,GAAG,GAAGD,KAAP,CADlB;AAEH;AACA;AACAR,IAAAA,SAAS,EACLF,QAAQ,CAACc,EAAT,KAAgB,KAAhB,GACMD,WAAW,CAACH,KAAD,CADjB,GAEMG,WAAW,CAACH,KAAK,GAAGD,MAAT;AAPlB,GAAP;AASH;;AAED,SAASI,WAAT,CAAqBE,UAArB,EAAiD;AAC7C,SAAO,CAAC,CAACA,UAAU,GAAG,GAAd,EAAmBC,OAAnB,CAA2B,CAA3B,CAAR;AACH","sourcesContent":["/*\n * Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.\n * This product includes software developed at Datadog (https://www.datadoghq.com/).\n * Copyright 2016-Present Datadog, Inc.\n */\n\nimport { Platform } from 'react-native';\n\ninterface Timing {\n /**\n * Time relative (absolute in case of iOS) to some point, in ns.\n */\n startTime: number;\n /**\n * Duration in ns.\n */\n duration: number;\n}\n\ninterface ResourceTimings {\n // unlike in Performance API it is not the time until request\n // starts (requestStart, before it can be connect, SSL, DNS),\n // but the time until the response is first seen\n firstByte: Timing;\n download: Timing;\n // required by iOS, total timing from the beginning to the end\n fetch: Timing;\n}\n\nexport function createTimings(\n startTime: number,\n responseStartTime: number,\n responseEndTime: number\n): ResourceTimings {\n const firstByte = formatTiming(startTime, startTime, responseStartTime);\n const download = formatTiming(\n startTime,\n responseStartTime,\n responseEndTime\n );\n // needed for iOS, simply total duration from start to end\n const fetch = formatTiming(startTime, startTime, responseEndTime);\n\n return {\n firstByte,\n download,\n fetch\n };\n}\n\n/**\n * @param origin Start time (absolute) of the request\n * @param start Start time (absolute) of the timing\n * @param end End time (absolute) of the timing\n */\nfunction formatTiming(origin: number, start: number, end: number): Timing {\n return {\n duration: timeToNanos(end - start),\n // if it is Android, startTime should be relative to the origin,\n // if it is iOS - absolute (unix timestamp)\n startTime:\n Platform.OS === 'ios'\n ? timeToNanos(start)\n : timeToNanos(start - origin)\n };\n}\n\nfunction timeToNanos(durationMs: number): number {\n return +(durationMs * 1e6).toFixed(0);\n}\n"]}
|
|
@@ -3,21 +3,28 @@
|
|
|
3
3
|
* This product includes software developed at Datadog (https://www.datadoghq.com/).
|
|
4
4
|
* Copyright 2016-Present Datadog, Inc.
|
|
5
5
|
*/
|
|
6
|
-
|
|
6
|
+
import { InternalLog } from '../../../../InternalLog';
|
|
7
|
+
import { SdkVerbosity } from '../../../../SdkVerbosity';
|
|
7
8
|
// matches what is between the first "://" and the next "/", ":" or whitespace
|
|
8
9
|
const hostRegex = '^.+://([^:/\\s]+)';
|
|
9
|
-
|
|
10
10
|
/**
|
|
11
11
|
* Returns the host from an URL.
|
|
12
|
-
* @returns the host (without the port)
|
|
13
|
-
* @throws if URL is not well formatted
|
|
12
|
+
* @returns the host (without the port) or null if could not cast the URL as host
|
|
14
13
|
*/
|
|
15
|
-
|
|
14
|
+
|
|
15
|
+
export const URLHostParser = url => {
|
|
16
|
+
try {
|
|
16
17
|
const matchedHost = url.match(hostRegex);
|
|
18
|
+
|
|
17
19
|
if (matchedHost === null) {
|
|
18
|
-
|
|
19
|
-
}
|
|
20
|
+
return null;
|
|
21
|
+
} // [0] is the input, [1] is the captured group
|
|
22
|
+
|
|
20
23
|
|
|
21
|
-
// [0] is the input, [1] is the captured group
|
|
22
24
|
return matchedHost[1];
|
|
25
|
+
} catch (e) {
|
|
26
|
+
InternalLog.log(`Impossible to cast ${url} as URL`, SdkVerbosity.WARN);
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
23
29
|
};
|
|
30
|
+
//# sourceMappingURL=URLHostParser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["URLHostParser.ts"],"names":["InternalLog","SdkVerbosity","hostRegex","URLHostParser","url","matchedHost","match","e","log","WARN"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AAEA,SAASA,WAAT,QAA4B,yBAA5B;AACA,SAASC,YAAT,QAA6B,0BAA7B;AAGA;AACA,MAAMC,SAAS,GAAG,mBAAlB;AAEA;AACA;AACA;AACA;;AACA,OAAO,MAAMC,aAAa,GAAIC,GAAD,IAAkC;AAC3D,MAAI;AACA,UAAMC,WAAW,GAAGD,GAAG,CAACE,KAAJ,CAAUJ,SAAV,CAApB;;AACA,QAAIG,WAAW,KAAK,IAApB,EAA0B;AACtB,aAAO,IAAP;AACH,KAJD,CAKA;;;AACA,WAAOA,WAAW,CAAC,CAAD,CAAlB;AACH,GAPD,CAOE,OAAOE,CAAP,EAAU;AACRP,IAAAA,WAAW,CAACQ,GAAZ,CAAiB,sBAAqBJ,GAAI,SAA1C,EAAoDH,YAAY,CAACQ,IAAjE;AACA,WAAO,IAAP;AACH;AACJ,CAZM","sourcesContent":["/*\n * Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.\n * This product includes software developed at Datadog (https://www.datadoghq.com/).\n * Copyright 2016-Present Datadog, Inc.\n */\n\nimport { InternalLog } from '../../../../InternalLog';\nimport { SdkVerbosity } from '../../../../SdkVerbosity';\nimport type { Hostname } from '../domain/firstPartyHosts';\n\n// matches what is between the first \"://\" and the next \"/\", \":\" or whitespace\nconst hostRegex = '^.+://([^:/\\\\s]+)';\n\n/**\n * Returns the host from an URL.\n * @returns the host (without the port) or null if could not cast the URL as host\n */\nexport const URLHostParser = (url: string): Hostname | null => {\n try {\n const matchedHost = url.match(hostRegex);\n if (matchedHost === null) {\n return null;\n }\n // [0] is the input, [1] is the captured group\n return matchedHost[1] as Hostname;\n } catch (e) {\n InternalLog.log(`Impossible to cast ${url} as URL`, SdkVerbosity.WARN);\n return null;\n }\n};\n"]}
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
|
|
5
|
+
* This product includes software developed at Datadog (https://www.datadoghq.com/).
|
|
6
|
+
* Copyright 2016-Present Datadog, Inc.
|
|
7
|
+
*/
|
|
8
|
+
import Timer from '../../../../Timer';
|
|
9
|
+
import { getTracingAttributes } from '../domain/distributedTracing';
|
|
10
|
+
import { RequestProxy } from '../domain/interfaces/RequestProxy';
|
|
11
|
+
import { URLHostParser } from './URLHostParser';
|
|
12
|
+
import { calculateResponseSize } from './responseSize';
|
|
13
|
+
export const TRACE_ID_HEADER_KEY = 'x-datadog-trace-id';
|
|
14
|
+
export const PARENT_ID_HEADER_KEY = 'x-datadog-parent-id';
|
|
15
|
+
export const ORIGIN_HEADER_KEY = 'x-datadog-origin';
|
|
16
|
+
export const SAMPLING_PRIORITY_HEADER_KEY = 'x-datadog-sampling-priority';
|
|
17
|
+
export const ORIGIN_RUM = 'rum';
|
|
18
|
+
const RESPONSE_START_LABEL = 'response_start';
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Proxies XMLHTTPRequest to track resources.
|
|
22
|
+
*/
|
|
23
|
+
export class XHRProxy extends RequestProxy {
|
|
24
|
+
constructor(providers) {
|
|
25
|
+
super();
|
|
26
|
+
|
|
27
|
+
_defineProperty(this, "providers", void 0);
|
|
28
|
+
|
|
29
|
+
_defineProperty(this, "onTrackingStart", context => {
|
|
30
|
+
XHRProxy.originalXhrOpen = this.providers.xhrType.prototype.open;
|
|
31
|
+
XHRProxy.originalXhrSend = this.providers.xhrType.prototype.send;
|
|
32
|
+
proxyRequests(this.providers, context);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
_defineProperty(this, "onTrackingStop", () => {
|
|
36
|
+
this.providers.xhrType.prototype.open = XHRProxy.originalXhrOpen;
|
|
37
|
+
this.providers.xhrType.prototype.send = XHRProxy.originalXhrSend;
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
this.providers = providers;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
_defineProperty(XHRProxy, "originalXhrOpen", void 0);
|
|
46
|
+
|
|
47
|
+
_defineProperty(XHRProxy, "originalXhrSend", void 0);
|
|
48
|
+
|
|
49
|
+
const proxyRequests = (providers, context) => {
|
|
50
|
+
proxyOpen(providers, context);
|
|
51
|
+
proxySend(providers);
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
const proxyOpen = ({
|
|
55
|
+
xhrType
|
|
56
|
+
}, context) => {
|
|
57
|
+
const originalXhrOpen = xhrType.prototype.open;
|
|
58
|
+
const firstPartyHostsRegex = context.firstPartyHostsRegex;
|
|
59
|
+
const tracingSamplingRate = context.tracingSamplingRate;
|
|
60
|
+
|
|
61
|
+
xhrType.prototype.open = function (method, url) {
|
|
62
|
+
const hostname = URLHostParser(url); // Keep track of the method and url
|
|
63
|
+
// start time is tracked by the `send` method
|
|
64
|
+
|
|
65
|
+
this._datadog_xhr = {
|
|
66
|
+
method,
|
|
67
|
+
url,
|
|
68
|
+
reported: false,
|
|
69
|
+
timer: new Timer(),
|
|
70
|
+
tracingAttributes: getTracingAttributes({
|
|
71
|
+
hostname,
|
|
72
|
+
firstPartyHostsRegex,
|
|
73
|
+
tracingSamplingRate
|
|
74
|
+
})
|
|
75
|
+
}; // eslint-disable-next-line prefer-rest-params
|
|
76
|
+
|
|
77
|
+
return originalXhrOpen.apply(this, arguments);
|
|
78
|
+
};
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
const proxySend = providers => {
|
|
82
|
+
const xhrType = providers.xhrType;
|
|
83
|
+
const originalXhrSend = xhrType.prototype.send;
|
|
84
|
+
|
|
85
|
+
xhrType.prototype.send = function () {
|
|
86
|
+
if (this._datadog_xhr) {
|
|
87
|
+
// keep track of start time
|
|
88
|
+
this._datadog_xhr.timer.start();
|
|
89
|
+
|
|
90
|
+
this.setRequestHeader(ORIGIN_HEADER_KEY, ORIGIN_RUM);
|
|
91
|
+
const tracingAttributes = this._datadog_xhr.tracingAttributes;
|
|
92
|
+
this.setRequestHeader(SAMPLING_PRIORITY_HEADER_KEY, tracingAttributes.samplingPriorityHeader);
|
|
93
|
+
|
|
94
|
+
if (tracingAttributes.tracingStrategy !== 'DISCARD') {
|
|
95
|
+
this.setRequestHeader(TRACE_ID_HEADER_KEY, tracingAttributes.traceId);
|
|
96
|
+
this.setRequestHeader(PARENT_ID_HEADER_KEY, tracingAttributes.spanId);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
proxyOnReadyStateChange(this, providers); // eslint-disable-next-line prefer-rest-params
|
|
101
|
+
|
|
102
|
+
return originalXhrSend.apply(this, arguments);
|
|
103
|
+
};
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
const proxyOnReadyStateChange = (xhrProxy, providers) => {
|
|
107
|
+
const xhrType = providers.xhrType;
|
|
108
|
+
const originalOnreadystatechange = xhrProxy.onreadystatechange;
|
|
109
|
+
|
|
110
|
+
xhrProxy.onreadystatechange = function () {
|
|
111
|
+
if (xhrProxy.readyState === xhrType.DONE) {
|
|
112
|
+
if (!xhrProxy._datadog_xhr.reported) {
|
|
113
|
+
reportXhr(xhrProxy, providers.resourceReporter);
|
|
114
|
+
xhrProxy._datadog_xhr.reported = true;
|
|
115
|
+
}
|
|
116
|
+
} else if (xhrProxy.readyState === xhrType.HEADERS_RECEIVED) {
|
|
117
|
+
xhrProxy._datadog_xhr.timer.recordTick(RESPONSE_START_LABEL);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
if (originalOnreadystatechange) {
|
|
121
|
+
// eslint-disable-next-line prefer-rest-params
|
|
122
|
+
originalOnreadystatechange.apply(xhrProxy, arguments);
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
const reportXhr = async (xhrProxy, resourceReporter) => {
|
|
128
|
+
const responseSize = calculateResponseSize(xhrProxy);
|
|
129
|
+
const context = xhrProxy._datadog_xhr;
|
|
130
|
+
const key = `${context.timer.startTime}/${context.method}`;
|
|
131
|
+
context.timer.stop();
|
|
132
|
+
resourceReporter.reportResource({
|
|
133
|
+
key,
|
|
134
|
+
request: {
|
|
135
|
+
method: context.method,
|
|
136
|
+
url: context.url,
|
|
137
|
+
kind: 'xhr'
|
|
138
|
+
},
|
|
139
|
+
tracingAttributes: context.tracingAttributes,
|
|
140
|
+
response: {
|
|
141
|
+
statusCode: xhrProxy.status,
|
|
142
|
+
size: responseSize
|
|
143
|
+
},
|
|
144
|
+
timings: {
|
|
145
|
+
startTime: context.timer.startTime,
|
|
146
|
+
stopTime: context.timer.stopTime,
|
|
147
|
+
responseStartTime: context.timer.hasTickFor(RESPONSE_START_LABEL) ? context.timer.timeAt(RESPONSE_START_LABEL) : undefined
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
};
|
|
151
|
+
//# sourceMappingURL=XHRProxy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["XHRProxy.ts"],"names":["Timer","getTracingAttributes","RequestProxy","URLHostParser","calculateResponseSize","TRACE_ID_HEADER_KEY","PARENT_ID_HEADER_KEY","ORIGIN_HEADER_KEY","SAMPLING_PRIORITY_HEADER_KEY","ORIGIN_RUM","RESPONSE_START_LABEL","XHRProxy","constructor","providers","context","originalXhrOpen","xhrType","prototype","open","originalXhrSend","send","proxyRequests","proxyOpen","proxySend","firstPartyHostsRegex","tracingSamplingRate","method","url","hostname","_datadog_xhr","reported","timer","tracingAttributes","apply","arguments","start","setRequestHeader","samplingPriorityHeader","tracingStrategy","traceId","spanId","proxyOnReadyStateChange","xhrProxy","originalOnreadystatechange","onreadystatechange","readyState","DONE","reportXhr","resourceReporter","HEADERS_RECEIVED","recordTick","responseSize","key","startTime","stop","reportResource","request","kind","response","statusCode","status","size","timings","stopTime","responseStartTime","hasTickFor","timeAt","undefined"],"mappings":"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","sourcesContent":["/*\n * Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.\n * This product includes software developed at Datadog (https://www.datadoghq.com/).\n * Copyright 2016-Present Datadog, Inc.\n */\n\nimport Timer from '../../../../Timer';\nimport type { DdRumResourceTracingAttributes } from '../domain/distributedTracing';\nimport { getTracingAttributes } from '../domain/distributedTracing';\nimport type { RequestProxyOptions } from '../domain/interfaces/RequestProxy';\nimport { RequestProxy } from '../domain/interfaces/RequestProxy';\n\nimport type { ResourceReporter } from './DatadogRumResource/ResourceReporter';\nimport { URLHostParser } from './URLHostParser';\nimport { calculateResponseSize } from './responseSize';\n\nexport const TRACE_ID_HEADER_KEY = 'x-datadog-trace-id';\nexport const PARENT_ID_HEADER_KEY = 'x-datadog-parent-id';\nexport const ORIGIN_HEADER_KEY = 'x-datadog-origin';\nexport const SAMPLING_PRIORITY_HEADER_KEY = 'x-datadog-sampling-priority';\nexport const ORIGIN_RUM = 'rum';\n\nconst RESPONSE_START_LABEL = 'response_start';\n\ninterface DdRumXhr extends XMLHttpRequest {\n _datadog_xhr: DdRumXhrContext;\n}\n\ninterface DdRumXhrContext {\n method: string;\n url: string;\n reported: boolean;\n timer: Timer;\n tracingAttributes: DdRumResourceTracingAttributes;\n}\n\ninterface XHRProxyProviders {\n xhrType: typeof XMLHttpRequest;\n resourceReporter: ResourceReporter;\n}\n\n/**\n * Proxies XMLHTTPRequest to track resources.\n */\nexport class XHRProxy extends RequestProxy {\n private providers: XHRProxyProviders;\n private static originalXhrOpen: typeof XMLHttpRequest.prototype.open;\n private static originalXhrSend: typeof XMLHttpRequest.prototype.send;\n\n constructor(providers: XHRProxyProviders) {\n super();\n this.providers = providers;\n }\n\n onTrackingStart = (context: RequestProxyOptions) => {\n XHRProxy.originalXhrOpen = this.providers.xhrType.prototype.open;\n XHRProxy.originalXhrSend = this.providers.xhrType.prototype.send;\n proxyRequests(this.providers, context);\n };\n\n onTrackingStop = () => {\n this.providers.xhrType.prototype.open = XHRProxy.originalXhrOpen;\n this.providers.xhrType.prototype.send = XHRProxy.originalXhrSend;\n };\n}\n\nconst proxyRequests = (\n providers: XHRProxyProviders,\n context: RequestProxyOptions\n): void => {\n proxyOpen(providers, context);\n proxySend(providers);\n};\n\nconst proxyOpen = (\n { xhrType }: XHRProxyProviders,\n context: RequestProxyOptions\n): void => {\n const originalXhrOpen = xhrType.prototype.open;\n const firstPartyHostsRegex = context.firstPartyHostsRegex;\n const tracingSamplingRate = context.tracingSamplingRate;\n\n xhrType.prototype.open = function (\n this: DdRumXhr,\n method: string,\n url: string\n ) {\n const hostname = URLHostParser(url);\n // Keep track of the method and url\n // start time is tracked by the `send` method\n this._datadog_xhr = {\n method,\n url,\n reported: false,\n timer: new Timer(),\n tracingAttributes: getTracingAttributes({\n hostname,\n firstPartyHostsRegex,\n tracingSamplingRate\n })\n };\n // eslint-disable-next-line prefer-rest-params\n return originalXhrOpen.apply(this, arguments as any);\n };\n};\n\nconst proxySend = (providers: XHRProxyProviders): void => {\n const xhrType = providers.xhrType;\n const originalXhrSend = xhrType.prototype.send;\n\n xhrType.prototype.send = function (this: DdRumXhr) {\n if (this._datadog_xhr) {\n // keep track of start time\n this._datadog_xhr.timer.start();\n this.setRequestHeader(ORIGIN_HEADER_KEY, ORIGIN_RUM);\n\n const tracingAttributes = this._datadog_xhr.tracingAttributes;\n this.setRequestHeader(\n SAMPLING_PRIORITY_HEADER_KEY,\n tracingAttributes.samplingPriorityHeader\n );\n if (tracingAttributes.tracingStrategy !== 'DISCARD') {\n this.setRequestHeader(\n TRACE_ID_HEADER_KEY,\n tracingAttributes.traceId\n );\n this.setRequestHeader(\n PARENT_ID_HEADER_KEY,\n tracingAttributes.spanId\n );\n }\n }\n\n proxyOnReadyStateChange(this, providers);\n\n // eslint-disable-next-line prefer-rest-params\n return originalXhrSend.apply(this, arguments as any);\n };\n};\n\nconst proxyOnReadyStateChange = (\n xhrProxy: DdRumXhr,\n providers: XHRProxyProviders\n): void => {\n const xhrType = providers.xhrType;\n const originalOnreadystatechange = xhrProxy.onreadystatechange;\n\n xhrProxy.onreadystatechange = function () {\n if (xhrProxy.readyState === xhrType.DONE) {\n if (!xhrProxy._datadog_xhr.reported) {\n reportXhr(xhrProxy, providers.resourceReporter);\n xhrProxy._datadog_xhr.reported = true;\n }\n } else if (xhrProxy.readyState === xhrType.HEADERS_RECEIVED) {\n xhrProxy._datadog_xhr.timer.recordTick(RESPONSE_START_LABEL);\n }\n\n if (originalOnreadystatechange) {\n // eslint-disable-next-line prefer-rest-params\n originalOnreadystatechange.apply(xhrProxy, arguments as any);\n }\n };\n};\n\nconst reportXhr = async (\n xhrProxy: DdRumXhr,\n resourceReporter: ResourceReporter\n): Promise<void> => {\n const responseSize = calculateResponseSize(xhrProxy);\n\n const context = xhrProxy._datadog_xhr;\n\n const key = `${context.timer.startTime}/${context.method}`;\n\n context.timer.stop();\n\n resourceReporter.reportResource({\n key,\n request: {\n method: context.method,\n url: context.url,\n kind: 'xhr'\n },\n tracingAttributes: context.tracingAttributes,\n response: {\n statusCode: xhrProxy.status,\n size: responseSize\n },\n timings: {\n startTime: context.timer.startTime,\n stopTime: context.timer.stopTime,\n responseStartTime: context.timer.hasTickFor(RESPONSE_START_LABEL)\n ? context.timer.timeAt(RESPONSE_START_LABEL)\n : undefined\n }\n });\n};\n"]}
|
|
@@ -0,0 +1,86 @@
|
|
|
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
|
+
import { InternalLog } from '../../../../InternalLog';
|
|
7
|
+
import { SdkVerbosity } from '../../../../SdkVerbosity';
|
|
8
|
+
const MISSING_RESOURCE_SIZE = -1;
|
|
9
|
+
export const RESOURCE_SIZE_ERROR_MESSAGE = "Couldn't get resource size, because an error occured: ";
|
|
10
|
+
|
|
11
|
+
function byteLength(str) {
|
|
12
|
+
// This is a weird trick, but it works.
|
|
13
|
+
// Output is the same as TextEncoder.encode(...).length
|
|
14
|
+
return unescape(encodeURI(str)).length;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function getResponseContentLengthFromHeader(xhr) {
|
|
18
|
+
var _xhr$getResponseHeade;
|
|
19
|
+
|
|
20
|
+
const contentLengthHeader = parseInt((_xhr$getResponseHeade = xhr.getResponseHeader('Content-Length')) !== null && _xhr$getResponseHeade !== void 0 ? _xhr$getResponseHeade : '', 10);
|
|
21
|
+
|
|
22
|
+
if (!isNaN(contentLengthHeader)) {
|
|
23
|
+
return contentLengthHeader;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function calculateResponseSize(xhr) {
|
|
30
|
+
const contentLengthHeader = getResponseContentLengthFromHeader(xhr);
|
|
31
|
+
|
|
32
|
+
if (contentLengthHeader != null) {
|
|
33
|
+
return contentLengthHeader;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const response = xhr.response;
|
|
37
|
+
|
|
38
|
+
if (!response) {
|
|
39
|
+
return MISSING_RESOURCE_SIZE;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
let size;
|
|
43
|
+
|
|
44
|
+
try {
|
|
45
|
+
switch (xhr.responseType) {
|
|
46
|
+
case '':
|
|
47
|
+
case 'text':
|
|
48
|
+
// String
|
|
49
|
+
size = byteLength(response);
|
|
50
|
+
break;
|
|
51
|
+
|
|
52
|
+
case 'blob':
|
|
53
|
+
size = response.size;
|
|
54
|
+
break;
|
|
55
|
+
|
|
56
|
+
case 'arraybuffer':
|
|
57
|
+
size = response.byteLength;
|
|
58
|
+
break;
|
|
59
|
+
|
|
60
|
+
case 'document':
|
|
61
|
+
// currently not supported by RN as of 0.66
|
|
62
|
+
// HTML Document or XML Document
|
|
63
|
+
break;
|
|
64
|
+
|
|
65
|
+
case 'json':
|
|
66
|
+
// plain JS object
|
|
67
|
+
// original size was lost, because this is the object which was parsed.
|
|
68
|
+
// We can only convert back to the string and calculate the size,
|
|
69
|
+
// which will roughly match original.
|
|
70
|
+
size = byteLength(JSON.stringify(response));
|
|
71
|
+
break;
|
|
72
|
+
|
|
73
|
+
default:
|
|
74
|
+
break;
|
|
75
|
+
}
|
|
76
|
+
} catch (e) {
|
|
77
|
+
InternalLog.log(`${RESOURCE_SIZE_ERROR_MESSAGE}${e}`, SdkVerbosity.ERROR);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
if (typeof size !== 'number') {
|
|
81
|
+
return MISSING_RESOURCE_SIZE;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
return size;
|
|
85
|
+
}
|
|
86
|
+
//# sourceMappingURL=responseSize.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["responseSize.ts"],"names":["InternalLog","SdkVerbosity","MISSING_RESOURCE_SIZE","RESOURCE_SIZE_ERROR_MESSAGE","byteLength","str","unescape","encodeURI","length","getResponseContentLengthFromHeader","xhr","contentLengthHeader","parseInt","getResponseHeader","isNaN","calculateResponseSize","response","size","responseType","JSON","stringify","e","log","ERROR"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AAEA,SAASA,WAAT,QAA4B,yBAA5B;AACA,SAASC,YAAT,QAA6B,0BAA7B;AAEA,MAAMC,qBAAqB,GAAG,CAAC,CAA/B;AACA,OAAO,MAAMC,2BAA2B,GACpC,wDADG;;AAGP,SAASC,UAAT,CAAoBC,GAApB,EAAyC;AACrC;AACA;AACA,SAAOC,QAAQ,CAACC,SAAS,CAACF,GAAD,CAAV,CAAR,CAAyBG,MAAhC;AACH;;AAED,SAASC,kCAAT,CACIC,GADJ,EAEiB;AAAA;;AACb,QAAMC,mBAAmB,GAAGC,QAAQ,0BAChCF,GAAG,CAACG,iBAAJ,CAAsB,gBAAtB,CADgC,yEACW,EADX,EAEhC,EAFgC,CAApC;;AAIA,MAAI,CAACC,KAAK,CAACH,mBAAD,CAAV,EAAiC;AAC7B,WAAOA,mBAAP;AACH;;AACD,SAAO,IAAP;AACH;;AAED,OAAO,SAASI,qBAAT,CAA+BL,GAA/B,EAA4D;AAC/D,QAAMC,mBAAmB,GAAGF,kCAAkC,CAACC,GAAD,CAA9D;;AACA,MAAIC,mBAAmB,IAAI,IAA3B,EAAiC;AAC7B,WAAOA,mBAAP;AACH;;AAED,QAAMK,QAAQ,GAAGN,GAAG,CAACM,QAArB;;AACA,MAAI,CAACA,QAAL,EAAe;AACX,WAAOd,qBAAP;AACH;;AAED,MAAIe,IAAJ;;AACA,MAAI;AACA,YAAQP,GAAG,CAACQ,YAAZ;AACI,WAAK,EAAL;AACA,WAAK,MAAL;AACI;AACAD,QAAAA,IAAI,GAAGb,UAAU,CAACY,QAAD,CAAjB;AACA;;AACJ,WAAK,MAAL;AACIC,QAAAA,IAAI,GAAGD,QAAQ,CAACC,IAAhB;AACA;;AACJ,WAAK,aAAL;AACIA,QAAAA,IAAI,GAAGD,QAAQ,CAACZ,UAAhB;AACA;;AACJ,WAAK,UAAL;AACI;AACA;AACA;;AACJ,WAAK,MAAL;AACI;AACA;AACA;AACA;AACAa,QAAAA,IAAI,GAAGb,UAAU,CAACe,IAAI,CAACC,SAAL,CAAeJ,QAAf,CAAD,CAAjB;AACA;;AACJ;AACI;AAxBR;AA0BH,GA3BD,CA2BE,OAAOK,CAAP,EAAU;AACRrB,IAAAA,WAAW,CAACsB,GAAZ,CACK,GAAEnB,2BAA4B,GAAEkB,CAAE,EADvC,EAEIpB,YAAY,CAACsB,KAFjB;AAIH;;AAED,MAAI,OAAON,IAAP,KAAgB,QAApB,EAA8B;AAC1B,WAAOf,qBAAP;AACH;;AACD,SAAOe,IAAP;AACH","sourcesContent":["/*\n * Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.\n * This product includes software developed at Datadog (https://www.datadoghq.com/).\n * Copyright 2016-Present Datadog, Inc.\n */\n\nimport { InternalLog } from '../../../../InternalLog';\nimport { SdkVerbosity } from '../../../../SdkVerbosity';\n\nconst MISSING_RESOURCE_SIZE = -1;\nexport const RESOURCE_SIZE_ERROR_MESSAGE =\n \"Couldn't get resource size, because an error occured: \";\n\nfunction byteLength(str: string): number {\n // This is a weird trick, but it works.\n // Output is the same as TextEncoder.encode(...).length\n return unescape(encodeURI(str)).length;\n}\n\nfunction getResponseContentLengthFromHeader(\n xhr: XMLHttpRequest\n): number | null {\n const contentLengthHeader = parseInt(\n xhr.getResponseHeader('Content-Length') ?? '',\n 10\n );\n if (!isNaN(contentLengthHeader)) {\n return contentLengthHeader;\n }\n return null;\n}\n\nexport function calculateResponseSize(xhr: XMLHttpRequest): number {\n const contentLengthHeader = getResponseContentLengthFromHeader(xhr);\n if (contentLengthHeader != null) {\n return contentLengthHeader as number;\n }\n\n const response = xhr.response;\n if (!response) {\n return MISSING_RESOURCE_SIZE;\n }\n\n let size;\n try {\n switch (xhr.responseType) {\n case '':\n case 'text':\n // String\n size = byteLength(response);\n break;\n case 'blob':\n size = response.size;\n break;\n case 'arraybuffer':\n size = response.byteLength;\n break;\n case 'document':\n // currently not supported by RN as of 0.66\n // HTML Document or XML Document\n break;\n case 'json':\n // plain JS object\n // original size was lost, because this is the object which was parsed.\n // We can only convert back to the string and calculate the size,\n // which will roughly match original.\n size = byteLength(JSON.stringify(response));\n break;\n default:\n break;\n }\n } catch (e) {\n InternalLog.log(\n `${RESOURCE_SIZE_ERROR_MESSAGE}${e}`,\n SdkVerbosity.ERROR\n );\n }\n\n if (typeof size !== 'number') {\n return MISSING_RESOURCE_SIZE;\n }\n return size;\n}\n"]}
|
package/lib/module/types.js
CHANGED
|
@@ -23,4 +23,27 @@ export class DdSdkConfiguration {
|
|
|
23
23
|
/**
|
|
24
24
|
* The entry point to initialize Datadog's features.
|
|
25
25
|
*/
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Describe the type of a RUM Action.
|
|
29
|
+
*/
|
|
30
|
+
export let RumActionType;
|
|
31
|
+
|
|
32
|
+
(function (RumActionType) {
|
|
33
|
+
RumActionType["TAP"] = "TAP";
|
|
34
|
+
RumActionType["SCROLL"] = "SCROLL";
|
|
35
|
+
RumActionType["SWIPE"] = "SWIPE";
|
|
36
|
+
RumActionType["BACK"] = "BACK";
|
|
37
|
+
RumActionType["CUSTOM"] = "CUSTOM";
|
|
38
|
+
})(RumActionType || (RumActionType = {}));
|
|
39
|
+
|
|
40
|
+
export let ErrorSource;
|
|
41
|
+
|
|
42
|
+
(function (ErrorSource) {
|
|
43
|
+
ErrorSource["NETWORK"] = "NETWORK";
|
|
44
|
+
ErrorSource["SOURCE"] = "SOURCE";
|
|
45
|
+
ErrorSource["CONSOLE"] = "CONSOLE";
|
|
46
|
+
ErrorSource["WEBVIEW"] = "WEBVIEW";
|
|
47
|
+
ErrorSource["CUSTOM"] = "CUSTOM";
|
|
48
|
+
})(ErrorSource || (ErrorSource = {}));
|
|
26
49
|
//# sourceMappingURL=types.js.map
|
package/lib/module/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["types.tsx"],"names":["DdSdkConfiguration","constructor","clientToken","env","applicationId","nativeCrashReportEnabled","sampleRate","site","trackingConsent","additionalConfig"],"mappings":"AAAA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA,OAAO,MAAMA,kBAAN,CAAyB;AAC5BC,EAAAA,WAAW,CACEC,WADF,EAEEC,GAFF,EAGEC,aAHF,EAIEC,wBAJF,EAKEC,UALF,EAMEC,IANF,EAOEC,eAPF,EAQEC,gBARF,EAST;AAAA,SARWP,WAQX,GARWA,WAQX;AAAA,SAPWC,GAOX,GAPWA,GAOX;AAAA,SANWC,aAMX,GANWA,aAMX;AAAA,SALWC,wBAKX,GALWA,wBAKX;AAAA,SAJWC,UAIX,GAJWA,UAIX;AAAA,SAHWC,IAGX,GAHWA,IAGX;AAAA,SAFWC,eAEX,GAFWA,eAEX;AAAA,SADWC,gBACX,GADWA,gBACX;AAAE;;AAVwB;AAahC;AACA;AACA","sourcesContent":["/*\n * Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.\n * This product includes software developed at Datadog (https://www.datadoghq.com/).\n * Copyright 2016-Present Datadog, Inc.\n */\n\n/**\n * A configuration object to initialize Datadog's features.\n */\nexport class DdSdkConfiguration {\n constructor(\n readonly clientToken: string,\n readonly env: string,\n readonly applicationId: string,\n readonly nativeCrashReportEnabled: boolean,\n readonly sampleRate: number,\n readonly site: string,\n readonly trackingConsent: string,\n readonly additionalConfig: object\n ) {}\n}\n\n/**\n * The entry point to initialize Datadog's features.\n */\nexport type DdSdkType = {\n /**\n * Initializes Datadog's features.\n * @param configuration: The configuration to use.\n */\n initialize(configuration: DdSdkConfiguration): Promise<void>;\n\n /**\n * Sets the global context (set of attributes) attached with all future Logs, Spans and RUM events.\n * @param attributes: The global context attributes.\n */\n setAttributes(attributes: object): Promise<void>;\n\n /**\n * Set the user information.\n * @param user: The user object (use builtin attributes: 'id', 'email', 'name', and/or any custom attribute).\n */\n setUser(user: object): Promise<void>;\n\n /**\n * Set the tracking consent regarding the data collection.\n * @param trackingConsent: Consent, which can take one of the following values: 'pending', 'granted', 'not_granted'.\n */\n setTrackingConsent(trackingConsent: string): Promise<void>;\n};\n\n/**\n * The entry point to use Datadog's Logs feature.\n */\nexport type DdLogsType = {\n /**\n * Send a log with level debug.\n * @param message: The message to send.\n * @param context: The additional context to send.\n */\n debug(message: string, context?: object): Promise<void>;\n\n /**\n * Send a log with level info.\n * @param message: The message to send.\n * @param context: The additional context to send.\n */\n info(message: string, context?: object): Promise<void>;\n\n /**\n * Send a log with level warn.\n * @param message: The message to send.\n * @param context: The additional context to send.\n */\n warn(message: string, context?: object): Promise<void>;\n\n /**\n * Send a log with level error.\n * @param message: The message to send.\n * @param context: The additional context to send.\n */\n error(message: string, context?: object): Promise<void>;\n};\n\n/**\n * The entry point to use Datadog's Trace feature.\n */\nexport type DdTraceType = {\n /**\n * Start a span, and returns a unique identifier for the span.\n * @param operation: The operation name of the span.\n * @param context: The additional context to send.\n * @param timestampMs: The timestamp when the operation started (in milliseconds). If not provided, current timestamp will be used.\n */\n startSpan(\n operation: string,\n context?: object,\n timestampMs?: number\n ): Promise<string>;\n\n /**\n * Finish a started span.\n * @param spanId: The unique identifier of the span.\n * @param context: The additional context to send.\n * @param timestampMs: The timestamp when the operation stopped (in milliseconds). If not provided, current timestamp will be used.\n */\n finishSpan(\n spanId: string,\n context?: object,\n timestampMs?: number\n ): Promise<void>;\n};\n\n/**\n * The entry point to use Datadog's RUM feature.\n */\nexport type DdRumType = {\n /**\n * Start tracking a RUM View.\n * @param key: The view unique key identifier.\n * @param name: The view name.\n * @param context: The additional context to send.\n * @param timestampMs: The timestamp when the view started (in milliseconds). If not provided, current timestamp will be used.\n */\n startView(\n key: string,\n name: string,\n context?: object,\n timestampMs?: number\n ): Promise<void>;\n\n /**\n * Stop tracking a RUM View.\n * @param key: The view unique key identifier.\n * @param context: The additional context to send.\n * @param timestampMs: The timestamp when the view stopped (in milliseconds). If not provided, current timestamp will be used.\n */\n stopView(\n key: string,\n context?: object,\n timestampMs?: number\n ): Promise<void>;\n\n /**\n * Start tracking a RUM Action.\n * @param type: The action type (tap, scroll, swipe, click, custom).\n * @param name: The action name.\n * @param context: The additional context to send.\n * @param timestampMs: The timestamp when the action started (in milliseconds). If not provided, current timestamp will be used.\n */\n startAction(\n type: string,\n name: string,\n context?: object,\n timestampMs?: number\n ): Promise<void>;\n\n /**\n * Stop tracking the ongoing RUM Action.\n * @param context: The additional context to send.\n * @param timestampMs: The timestamp when the action stopped (in milliseconds). If not provided, current timestamp will be used.\n */\n stopAction(context?: object, timestampMs?: number): Promise<void>;\n\n /**\n * Add a RUM Action.\n * @param type: The action type (tap, scroll, swipe, click, custom).\n * @param name: The action name.\n * @param context: The additional context to send.\n * @param timestampMs: The timestamp when the action occurred (in milliseconds). If not provided, current timestamp will be used.\n */\n addAction(\n type: string,\n name: string,\n context?: object,\n timestampMs?: number\n ): Promise<void>;\n\n /**\n * Start tracking a RUM Resource.\n * @param key: The resource unique key identifier.\n * @param method: The resource method (GET, POST, …).\n * @param url: The resource url.\n * @param context: The additional context to send.\n * @param timestampMs: The timestamp when the resource started (in milliseconds). If not provided, current timestamp will be used.\n */\n startResource(\n key: string,\n method: string,\n url: string,\n context?: object,\n timestampMs?: number\n ): Promise<void>;\n\n /**\n * Stop tracking a RUM Resource.\n * @param key: The resource unique key identifier.\n * @param statusCode: The resource status code.\n * @param kind: The resource's kind (xhr, document, image, css, font, …).\n * @param size: The resource size in bytes. If size is unknown, use -1.\n * @param context: The additional context to send.\n * @param timestampMs: The timestamp when the resource stopped (in milliseconds). If not provided, current timestamp will be used.\n */\n stopResource(\n key: string,\n statusCode: number,\n kind: string,\n size?: number,\n context?: object,\n timestampMs?: number\n ): Promise<void>;\n\n /**\n * Add a RUM Error.\n * @param message: The error message.\n * @param source: The error source (network, source, console, logger, …).\n * @param stacktrace: The error stacktrace.\n * @param context: The additional context to send.\n * @param timestampMs: The timestamp when the error occurred (in milliseconds). If not provided, current timestamp will be used.\n */\n addError(\n message: string,\n source: string,\n stacktrace: string,\n context?: object,\n timestampMs?: number\n ): Promise<void>;\n\n /**\n * Adds a specific timing in the active View. The timing duration will be computed as the difference between the time the View was started and the time this function was called.\n * @param name: The name of the new custom timing attribute. Timings can be nested up to 8 levels deep. Names using more than 8 levels will be sanitized by SDK.\n */\n addTiming(name: string): Promise<void>;\n};\n"]}
|
|
1
|
+
{"version":3,"sources":["types.tsx"],"names":["DdSdkConfiguration","constructor","clientToken","env","applicationId","nativeCrashReportEnabled","sampleRate","site","trackingConsent","additionalConfig","RumActionType","ErrorSource"],"mappings":"AAAA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA,OAAO,MAAMA,kBAAN,CAAyB;AAC5BC,EAAAA,WAAW,CACEC,WADF,EAEEC,GAFF,EAGEC,aAHF,EAIEC,wBAJF,EAKEC,UALF,EAMEC,IANF,EAOEC,eAPF,EAQEC,gBARF,EAST;AAAA,SARWP,WAQX,GARWA,WAQX;AAAA,SAPWC,GAOX,GAPWA,GAOX;AAAA,SANWC,aAMX,GANWA,aAMX;AAAA,SALWC,wBAKX,GALWA,wBAKX;AAAA,SAJWC,UAIX,GAJWA,UAIX;AAAA,SAHWC,IAGX,GAHWA,IAGX;AAAA,SAFWC,eAEX,GAFWA,eAEX;AAAA,SADWC,gBACX,GADWA,gBACX;AAAE;;AAVwB;AAahC;AACA;AACA;;AAqOA;AACA;AACA;AACA,WAAYC,aAAZ;;WAAYA,a;AAAAA,EAAAA,a;AAAAA,EAAAA,a;AAAAA,EAAAA,a;AAAAA,EAAAA,a;AAAAA,EAAAA,a;GAAAA,a,KAAAA,a;;AA0BZ,WAAYC,WAAZ;;WAAYA,W;AAAAA,EAAAA,W;AAAAA,EAAAA,W;AAAAA,EAAAA,W;AAAAA,EAAAA,W;AAAAA,EAAAA,W;GAAAA,W,KAAAA,W","sourcesContent":["/*\n * Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.\n * This product includes software developed at Datadog (https://www.datadoghq.com/).\n * Copyright 2016-Present Datadog, Inc.\n */\n\n/**\n * A configuration object to initialize Datadog's features.\n */\nexport class DdSdkConfiguration {\n constructor(\n readonly clientToken: string,\n readonly env: string,\n readonly applicationId: string,\n readonly nativeCrashReportEnabled: boolean,\n readonly sampleRate: number,\n readonly site: string,\n readonly trackingConsent: string,\n readonly additionalConfig: object\n ) {}\n}\n\n/**\n * The entry point to initialize Datadog's features.\n */\nexport type DdSdkType = {\n /**\n * Initializes Datadog's features.\n * @param configuration: The configuration to use.\n */\n initialize(configuration: DdSdkConfiguration): Promise<void>;\n\n /**\n * Sets the global context (set of attributes) attached with all future Logs, Spans and RUM events.\n * @param attributes: The global context attributes.\n */\n setAttributes(attributes: object): Promise<void>;\n\n /**\n * Set the user information.\n * @param user: The user object (use builtin attributes: 'id', 'email', 'name', and/or any custom attribute).\n */\n setUser(user: object): Promise<void>;\n\n /**\n * Set the tracking consent regarding the data collection.\n * @param trackingConsent: Consent, which can take one of the following values: 'pending', 'granted', 'not_granted'.\n */\n setTrackingConsent(trackingConsent: string): Promise<void>;\n};\n\n/**\n * The entry point to use Datadog's Logs feature.\n */\nexport type DdLogsType = {\n /**\n * Send a log with level debug.\n * @param message: The message to send.\n * @param context: The additional context to send.\n */\n debug(message: string, context?: object): Promise<void>;\n\n /**\n * Send a log with level info.\n * @param message: The message to send.\n * @param context: The additional context to send.\n */\n info(message: string, context?: object): Promise<void>;\n\n /**\n * Send a log with level warn.\n * @param message: The message to send.\n * @param context: The additional context to send.\n */\n warn(message: string, context?: object): Promise<void>;\n\n /**\n * Send a log with level error.\n * @param message: The message to send.\n * @param context: The additional context to send.\n */\n error(message: string, context?: object): Promise<void>;\n};\n\n/**\n * The entry point to use Datadog's Trace feature.\n */\nexport type DdTraceType = {\n /**\n * Start a span, and returns a unique identifier for the span.\n * @param operation: The operation name of the span.\n * @param context: The additional context to send.\n * @param timestampMs: The timestamp when the operation started (in milliseconds). If not provided, current timestamp will be used.\n */\n startSpan(\n operation: string,\n context?: object,\n timestampMs?: number\n ): Promise<string>;\n\n /**\n * Finish a started span.\n * @param spanId: The unique identifier of the span.\n * @param context: The additional context to send.\n * @param timestampMs: The timestamp when the operation stopped (in milliseconds). If not provided, current timestamp will be used.\n */\n finishSpan(\n spanId: string,\n context?: object,\n timestampMs?: number\n ): Promise<void>;\n};\n\n/**\n * The entry point to use Datadog's RUM feature.\n */\nexport type DdRumType = {\n /**\n * Start tracking a RUM View.\n * @param key: The view unique key identifier.\n * @param name: The view name.\n * @param context: The additional context to send.\n * @param timestampMs: The timestamp when the view started (in milliseconds). If not provided, current timestamp will be used.\n */\n startView(\n key: string,\n name: string,\n context?: object,\n timestampMs?: number\n ): Promise<void>;\n\n /**\n * Stop tracking a RUM View.\n * @param key: The view unique key identifier.\n * @param context: The additional context to send.\n * @param timestampMs: The timestamp when the view stopped (in milliseconds). If not provided, current timestamp will be used.\n */\n stopView(\n key: string,\n context?: object,\n timestampMs?: number\n ): Promise<void>;\n\n /**\n * Start tracking a RUM Action.\n * @param type: The action type (tap, scroll, swipe, back, custom).\n * @param name: The action name.\n * @param context: The additional context to send.\n * @param timestampMs: The timestamp when the action started (in milliseconds). If not provided, current timestamp will be used.\n */\n startAction(\n type: RumActionType,\n name: string,\n context?: object,\n timestampMs?: number\n ): Promise<void>;\n\n /**\n * Stop tracking the ongoing RUM Action.\n * @param type: The action type (tap, scroll, swipe, back, custom).\n * @param name: The action name.\n * @param context: The additional context to send.\n * @param timestampMs: The timestamp when the action stopped (in milliseconds). If not provided, current timestamp will be used.\n */\n stopAction(\n type: RumActionType,\n name: string,\n context?: object,\n timestampMs?: number\n ): Promise<void>;\n\n /**\n * Stop tracking the ongoing RUM Action.\n *\n * Warning: using this function signature can lead to inconsistent behaviors on iOS and Android when multiple actions are started in parallel.\n *\n * @deprecated add the `type` and `name` of the action as first two arguments.\n * @param context: The additional context to send.\n * @param timestampMs: The timestamp when the action stopped (in milliseconds). If not provided, current timestamp will be used.\n */\n stopAction(context?: object, timestampMs?: number): Promise<void>;\n\n /**\n * Add a RUM Action.\n * @param type: The action type (tap, scroll, swipe, back, custom).\n * @param name: The action name.\n * @param context: The additional context to send.\n * @param timestampMs: The timestamp when the action occurred (in milliseconds). If not provided, current timestamp will be used.\n */\n addAction(\n type: RumActionType,\n name: string,\n context?: object,\n timestampMs?: number\n ): Promise<void>;\n\n /**\n * Start tracking a RUM Resource.\n * @param key: The resource unique key identifier.\n * @param method: The resource method (GET, POST, …).\n * @param url: The resource url.\n * @param context: The additional context to send.\n * @param timestampMs: The timestamp when the resource started (in milliseconds). If not provided, current timestamp will be used.\n */\n startResource(\n key: string,\n method: string,\n url: string,\n context?: object,\n timestampMs?: number\n ): Promise<void>;\n\n /**\n * Stop tracking a RUM Resource.\n * @param key: The resource unique key identifier.\n * @param statusCode: The resource status code.\n * @param kind: The resource's kind (xhr, document, image, css, font, …).\n * @param size: The resource size in bytes. If size is unknown, use -1.\n * @param context: The additional context to send.\n * @param timestampMs: The timestamp when the resource stopped (in milliseconds). If not provided, current timestamp will be used.\n */\n stopResource(\n key: string,\n statusCode: number,\n kind: ResourceKind,\n size?: number,\n context?: object,\n timestampMs?: number\n ): Promise<void>;\n\n /**\n * Add a RUM Error.\n * @param message: The error message.\n * @param source: The error source (network, source, console, webview, custom).\n * @param stacktrace: The error stacktrace.\n * @param context: The additional context to send.\n * @param timestampMs: The timestamp when the error occurred (in milliseconds). If not provided, current timestamp will be used.\n */\n addError(\n message: string,\n source: ErrorSource,\n stacktrace: string,\n context?: object,\n timestampMs?: number\n ): Promise<void>;\n\n /**\n * Adds a specific timing in the active View. The timing duration will be computed as the difference between the time the View was started and the time this function was called.\n * @param name: The name of the new custom timing attribute. Timings can be nested up to 8 levels deep. Names using more than 8 levels will be sanitized by SDK.\n */\n addTiming(name: string): Promise<void>;\n};\n\n/**\n * Describe the type of a RUM Action.\n */\nexport enum RumActionType {\n /** User tapped on a widget. */\n TAP = 'TAP',\n /** User scrolled a view. */\n SCROLL = 'SCROLL',\n /** User swiped on a view. */\n SWIPE = 'SWIPE',\n /** User pressed hardware back button (Android only). */\n BACK = 'BACK',\n /** A custom action. */\n CUSTOM = 'CUSTOM'\n}\n\nexport type ResourceKind =\n | 'image'\n | 'xhr'\n | 'beacon'\n | 'css'\n | 'document'\n | 'fetch'\n | 'font'\n | 'js'\n | 'media'\n | 'other'\n | 'native';\n\nexport enum ErrorSource {\n NETWORK = 'NETWORK',\n SOURCE = 'SOURCE',\n CONSOLE = 'CONSOLE',\n WEBVIEW = 'WEBVIEW',\n CUSTOM = 'CUSTOM'\n}\n"]}
|