@datadog/mobile-react-native 1.0.0-rc6 → 1.0.0-rc9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/DatadogSDKReactNative.podspec +1 -1
- package/README.md +2 -0
- package/android/build.gradle +1 -1
- package/ios/Sources/DdSdk.swift +6 -3
- package/lib/commonjs/DdSdkReactNative.js +7 -3
- package/lib/commonjs/DdSdkReactNative.js.map +1 -1
- package/lib/commonjs/DdSdkReactNativeConfiguration.js +2 -0
- package/lib/commonjs/DdSdkReactNativeConfiguration.js.map +1 -1
- package/lib/commonjs/InternalLog.js +5 -0
- package/lib/commonjs/InternalLog.js.map +1 -1
- package/lib/commonjs/index.js +8 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/rum/instrumentation/resourceTracking/DdRumResourceTracking.js +73 -0
- package/lib/commonjs/rum/instrumentation/resourceTracking/DdRumResourceTracking.js.map +1 -0
- package/lib/commonjs/rum/instrumentation/{TraceIdentifier.js → resourceTracking/domain/distributedTracing.js} +40 -1
- package/lib/commonjs/rum/instrumentation/resourceTracking/domain/distributedTracing.js.map +1 -0
- package/lib/commonjs/rum/instrumentation/resourceTracking/domain/firstPartyHosts.js +46 -0
- package/lib/commonjs/rum/instrumentation/resourceTracking/domain/firstPartyHosts.js.map +1 -0
- package/lib/commonjs/rum/instrumentation/resourceTracking/domain/interfaces/RequestProxy.js +25 -0
- package/lib/commonjs/rum/instrumentation/resourceTracking/domain/interfaces/RequestProxy.js.map +1 -0
- package/lib/commonjs/rum/instrumentation/resourceTracking/domain/interfaces/RumResource.js +2 -0
- package/lib/commonjs/rum/instrumentation/{DdRumXhr.js.map → resourceTracking/domain/interfaces/RumResource.js.map} +0 -0
- package/lib/commonjs/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/ResourceReporter.js +57 -0
- package/lib/commonjs/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/ResourceReporter.js.map +1 -0
- package/lib/commonjs/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/internalDevResourceBlocklist.js +49 -0
- package/lib/commonjs/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/internalDevResourceBlocklist.js.map +1 -0
- package/lib/commonjs/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/resourceTiming.js +45 -0
- package/lib/commonjs/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/resourceTiming.js.map +1 -0
- package/lib/commonjs/rum/instrumentation/resourceTracking/implementation/URLHostParser.js +42 -0
- package/lib/commonjs/rum/instrumentation/resourceTracking/implementation/URLHostParser.js.map +1 -0
- package/lib/commonjs/rum/instrumentation/resourceTracking/implementation/XHRProxy.js +167 -0
- package/lib/commonjs/rum/instrumentation/resourceTracking/implementation/XHRProxy.js.map +1 -0
- package/lib/commonjs/rum/instrumentation/resourceTracking/implementation/responseSize.js +97 -0
- package/lib/commonjs/rum/instrumentation/resourceTracking/implementation/responseSize.js.map +1 -0
- package/lib/commonjs/version.js +1 -1
- package/lib/commonjs/version.js.map +1 -1
- package/lib/module/DdSdkReactNative.js +6 -2
- package/lib/module/DdSdkReactNative.js.map +1 -1
- package/lib/module/DdSdkReactNativeConfiguration.js +2 -0
- package/lib/module/DdSdkReactNativeConfiguration.js.map +1 -1
- package/lib/module/InternalLog.js +6 -0
- package/lib/module/InternalLog.js.map +1 -1
- package/lib/module/index.js +2 -1
- package/lib/module/index.js.map +1 -1
- package/lib/module/rum/instrumentation/resourceTracking/DdRumResourceTracking.js +61 -0
- package/lib/module/rum/instrumentation/resourceTracking/DdRumResourceTracking.js.map +1 -0
- package/lib/module/rum/instrumentation/{TraceIdentifier.js → resourceTracking/domain/distributedTracing.js} +35 -1
- package/lib/module/rum/instrumentation/resourceTracking/domain/distributedTracing.js.map +1 -0
- package/lib/module/rum/instrumentation/resourceTracking/domain/firstPartyHosts.js +29 -0
- package/lib/module/rum/instrumentation/resourceTracking/domain/firstPartyHosts.js.map +1 -0
- package/lib/module/rum/instrumentation/resourceTracking/domain/interfaces/RequestProxy.js +16 -0
- package/lib/module/rum/instrumentation/resourceTracking/domain/interfaces/RequestProxy.js.map +1 -0
- package/lib/module/rum/instrumentation/resourceTracking/domain/interfaces/RumResource.js +2 -0
- package/lib/module/rum/instrumentation/{DdRumXhr.js.map → resourceTracking/domain/interfaces/RumResource.js.map} +0 -0
- package/lib/module/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/ResourceReporter.js +50 -0
- package/lib/module/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/ResourceReporter.js.map +1 -0
- package/lib/module/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/internalDevResourceBlocklist.js +40 -0
- package/lib/module/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/internalDevResourceBlocklist.js.map +1 -0
- package/lib/module/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/resourceTiming.js +36 -0
- package/lib/module/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/resourceTiming.js.map +1 -0
- package/lib/module/rum/instrumentation/resourceTracking/implementation/URLHostParser.js +30 -0
- package/lib/module/rum/instrumentation/resourceTracking/implementation/URLHostParser.js.map +1 -0
- package/lib/module/rum/instrumentation/resourceTracking/implementation/XHRProxy.js +151 -0
- package/lib/module/rum/instrumentation/resourceTracking/implementation/XHRProxy.js.map +1 -0
- package/lib/module/rum/instrumentation/resourceTracking/implementation/responseSize.js +86 -0
- package/lib/module/rum/instrumentation/resourceTracking/implementation/responseSize.js.map +1 -0
- package/lib/module/version.js +1 -1
- package/lib/module/version.js.map +1 -1
- package/lib/typescript/DdSdkReactNativeConfiguration.d.ts +1 -0
- package/lib/typescript/InternalLog.d.ts +5 -0
- package/lib/typescript/index.d.ts +2 -1
- package/lib/typescript/rum/instrumentation/resourceTracking/DdRumResourceTracking.d.ts +15 -0
- package/lib/typescript/rum/instrumentation/resourceTracking/domain/distributedTracing.d.ts +18 -0
- package/lib/typescript/rum/instrumentation/resourceTracking/domain/firstPartyHosts.d.ts +6 -0
- package/lib/typescript/rum/instrumentation/resourceTracking/domain/interfaces/RequestProxy.d.ts +8 -0
- package/lib/typescript/rum/instrumentation/resourceTracking/domain/interfaces/RumResource.d.ts +19 -0
- package/lib/typescript/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/ResourceReporter.d.ts +8 -0
- package/lib/typescript/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/internalDevResourceBlocklist.d.ts +6 -0
- package/lib/typescript/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/resourceTiming.d.ts +17 -0
- package/lib/typescript/rum/instrumentation/resourceTracking/implementation/URLHostParser.d.ts +6 -0
- package/lib/typescript/rum/instrumentation/resourceTracking/implementation/XHRProxy.d.ts +25 -0
- package/lib/typescript/rum/instrumentation/resourceTracking/implementation/responseSize.d.ts +3 -0
- package/lib/typescript/version.d.ts +1 -1
- package/package.json +4 -3
- package/src/DdSdkReactNative.tsx +8 -4
- package/src/DdSdkReactNativeConfiguration.tsx +1 -0
- package/src/InternalLog.tsx +5 -0
- package/src/__tests__/DdSdkReactNative.test.tsx +42 -24
- package/src/__tests__/rum/instrumentation/DdEventsInterceptor.test.tsx +1 -1
- package/src/__tests__/rum/instrumentation/DdRumUserInteractionTracking.test.tsx +1 -1
- package/src/index.tsx +2 -0
- package/src/rum/instrumentation/resourceTracking/DdRumResourceTracking.tsx +67 -0
- package/src/rum/instrumentation/resourceTracking/__tests__/DdRumResourceTracking.test.ts +79 -0
- package/src/{__tests__/rum/instrumentation → rum/instrumentation/resourceTracking/__tests__}/__utils__/XMLHttpRequestMock.ts +0 -0
- package/src/{__tests__/rum/instrumentation/TraceIdentifier.test.tsx → rum/instrumentation/resourceTracking/domain/__tests__/distributedTracing.test.ts} +1 -1
- package/src/rum/instrumentation/resourceTracking/domain/distributedTracing.tsx +87 -0
- package/src/rum/instrumentation/resourceTracking/domain/firstPartyHosts.ts +45 -0
- package/src/rum/instrumentation/resourceTracking/domain/interfaces/RequestProxy.ts +15 -0
- package/src/rum/instrumentation/resourceTracking/domain/interfaces/RumResource.ts +26 -0
- package/src/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/ResourceReporter.ts +78 -0
- package/src/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/__tests__/ResourceReporter.test.ts +83 -0
- package/src/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/__tests__/__utils__/ResourceMockFactory.ts +45 -0
- package/src/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/__tests__/internalDevResourceBlocklist.test.ts +69 -0
- package/src/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/internalDevResourceBlocklist.ts +50 -0
- package/src/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/resourceTiming.ts +70 -0
- package/src/rum/instrumentation/resourceTracking/implementation/URLHostParser.ts +30 -0
- package/src/rum/instrumentation/resourceTracking/implementation/XHRProxy.ts +197 -0
- package/src/rum/instrumentation/resourceTracking/implementation/__tests__/URLHostParser.test.ts +40 -0
- package/src/{__tests__/rum/instrumentation/DdRumResourceTracking.test.tsx → rum/instrumentation/resourceTracking/implementation/__tests__/XHRProxy.test.ts} +178 -69
- package/src/rum/instrumentation/resourceTracking/implementation/responseSize.ts +83 -0
- package/src/version.ts +1 -1
- package/lib/commonjs/internal.js +0 -14
- package/lib/commonjs/internal.js.map +0 -1
- package/lib/commonjs/rum/instrumentation/DdRumResourceTracking.js +0 -298
- package/lib/commonjs/rum/instrumentation/DdRumResourceTracking.js.map +0 -1
- package/lib/commonjs/rum/instrumentation/DdRumXhr.js +0 -2
- package/lib/commonjs/rum/instrumentation/TraceIdentifier.js.map +0 -1
- package/lib/module/internal.js +0 -2
- package/lib/module/internal.js.map +0 -1
- package/lib/module/rum/instrumentation/DdRumResourceTracking.js +0 -276
- package/lib/module/rum/instrumentation/DdRumResourceTracking.js.map +0 -1
- package/lib/module/rum/instrumentation/DdRumXhr.js +0 -2
- package/lib/module/rum/instrumentation/TraceIdentifier.js.map +0 -1
- package/lib/typescript/internal.d.ts +0 -1
- package/lib/typescript/rum/instrumentation/DdRumResourceTracking.d.ts +0 -31
- package/lib/typescript/rum/instrumentation/DdRumXhr.d.ts +0 -23
- package/lib/typescript/rum/instrumentation/TraceIdentifier.d.ts +0 -1
- package/src/internal.tsx +0 -1
- package/src/rum/instrumentation/DdRumResourceTracking.tsx +0 -361
- package/src/rum/instrumentation/DdRumXhr.tsx +0 -33
- package/src/rum/instrumentation/TraceIdentifier.tsx +0 -34
|
@@ -0,0 +1,61 @@
|
|
|
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 { InternalLog } from '../../../InternalLog';
|
|
9
|
+
import { SdkVerbosity } from '../../../SdkVerbosity';
|
|
10
|
+
import { firstPartyHostsRegexBuilder } from './domain/firstPartyHosts';
|
|
11
|
+
import { ResourceReporter } from './implementation/DatadogRumResource/ResourceReporter';
|
|
12
|
+
import { filterDevResource } from './implementation/DatadogRumResource/internalDevResourceBlocklist';
|
|
13
|
+
import { XHRProxy } from './implementation/XHRProxy';
|
|
14
|
+
/**
|
|
15
|
+
* Provides RUM auto-instrumentation feature to track resources (fetch, XHR, axios) as RUM events.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
export class DdRumResourceTracking {
|
|
19
|
+
/**
|
|
20
|
+
* Starts tracking resources and sends a RUM Resource event every time a network request is detected.
|
|
21
|
+
*/
|
|
22
|
+
static startTracking({
|
|
23
|
+
tracingSamplingRate,
|
|
24
|
+
firstPartyHosts
|
|
25
|
+
}) {
|
|
26
|
+
// extra safety to avoid proxying the XHR class twice
|
|
27
|
+
if (DdRumResourceTracking.isTracking) {
|
|
28
|
+
InternalLog.log('Datadog SDK is already tracking XHR resources', SdkVerbosity.WARN);
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
this.requestProxy = new XHRProxy({
|
|
33
|
+
xhrType: XMLHttpRequest,
|
|
34
|
+
resourceReporter: new ResourceReporter([filterDevResource])
|
|
35
|
+
});
|
|
36
|
+
this.requestProxy.onTrackingStart({
|
|
37
|
+
tracingSamplingRate,
|
|
38
|
+
firstPartyHostsRegex: firstPartyHostsRegexBuilder(firstPartyHosts)
|
|
39
|
+
});
|
|
40
|
+
InternalLog.log('Datadog SDK is tracking XHR resources', SdkVerbosity.INFO);
|
|
41
|
+
DdRumResourceTracking.isTracking = true;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
static stopTracking() {
|
|
45
|
+
if (DdRumResourceTracking.isTracking) {
|
|
46
|
+
DdRumResourceTracking.isTracking = false;
|
|
47
|
+
|
|
48
|
+
if (this.requestProxy) {
|
|
49
|
+
this.requestProxy.onTrackingStop();
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
this.requestProxy = null;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
_defineProperty(DdRumResourceTracking, "isTracking", false);
|
|
59
|
+
|
|
60
|
+
_defineProperty(DdRumResourceTracking, "requestProxy", void 0);
|
|
61
|
+
//# sourceMappingURL=DdRumResourceTracking.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["DdRumResourceTracking.tsx"],"names":["InternalLog","SdkVerbosity","firstPartyHostsRegexBuilder","ResourceReporter","filterDevResource","XHRProxy","DdRumResourceTracking","startTracking","tracingSamplingRate","firstPartyHosts","isTracking","log","WARN","requestProxy","xhrType","XMLHttpRequest","resourceReporter","onTrackingStart","firstPartyHostsRegex","INFO","stopTracking","onTrackingStop"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AAEA,SAASA,WAAT,QAA4B,sBAA5B;AACA,SAASC,YAAT,QAA6B,uBAA7B;AAEA,SAASC,2BAAT,QAA4C,0BAA5C;AAEA,SAASC,gBAAT,QAAiC,sDAAjC;AACA,SAASC,iBAAT,QAAkC,kEAAlC;AACA,SAASC,QAAT,QAAyB,2BAAzB;AAEA;AACA;AACA;;AACA,OAAO,MAAMC,qBAAN,CAA4B;AAI/B;AACJ;AACA;AACwB,SAAbC,aAAa,CAAC;AACjBC,IAAAA,mBADiB;AAEjBC,IAAAA;AAFiB,GAAD,EAMX;AACL;AACA,QAAIH,qBAAqB,CAACI,UAA1B,EAAsC;AAClCV,MAAAA,WAAW,CAACW,GAAZ,CACI,+CADJ,EAEIV,YAAY,CAACW,IAFjB;AAIA;AACH;;AAED,SAAKC,YAAL,GAAoB,IAAIR,QAAJ,CAAa;AAC7BS,MAAAA,OAAO,EAAEC,cADoB;AAE7BC,MAAAA,gBAAgB,EAAE,IAAIb,gBAAJ,CAAqB,CAACC,iBAAD,CAArB;AAFW,KAAb,CAApB;AAIA,SAAKS,YAAL,CAAkBI,eAAlB,CAAkC;AAC9BT,MAAAA,mBAD8B;AAE9BU,MAAAA,oBAAoB,EAAEhB,2BAA2B,CAACO,eAAD;AAFnB,KAAlC;AAKAT,IAAAA,WAAW,CAACW,GAAZ,CACI,uCADJ,EAEIV,YAAY,CAACkB,IAFjB;AAIAb,IAAAA,qBAAqB,CAACI,UAAtB,GAAmC,IAAnC;AACH;;AAEkB,SAAZU,YAAY,GAAS;AACxB,QAAId,qBAAqB,CAACI,UAA1B,EAAsC;AAClCJ,MAAAA,qBAAqB,CAACI,UAAtB,GAAmC,KAAnC;;AACA,UAAI,KAAKG,YAAT,EAAuB;AACnB,aAAKA,YAAL,CAAkBQ,cAAlB;AACH;;AACD,WAAKR,YAAL,GAAoB,IAApB;AACH;AACJ;;AA/C8B;;gBAAtBP,qB,gBACmB,K;;gBADnBA,qB","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\nimport { firstPartyHostsRegexBuilder } from './domain/firstPartyHosts';\nimport type { RequestProxy } from './domain/interfaces/RequestProxy';\nimport { ResourceReporter } from './implementation/DatadogRumResource/ResourceReporter';\nimport { filterDevResource } from './implementation/DatadogRumResource/internalDevResourceBlocklist';\nimport { XHRProxy } from './implementation/XHRProxy';\n\n/**\n * Provides RUM auto-instrumentation feature to track resources (fetch, XHR, axios) as RUM events.\n */\nexport class DdRumResourceTracking {\n private static isTracking = false;\n private static requestProxy: RequestProxy | null;\n\n /**\n * Starts tracking resources and sends a RUM Resource event every time a network request is detected.\n */\n static startTracking({\n tracingSamplingRate,\n firstPartyHosts\n }: {\n tracingSamplingRate: number;\n firstPartyHosts: string[];\n }): void {\n // extra safety to avoid proxying the XHR class twice\n if (DdRumResourceTracking.isTracking) {\n InternalLog.log(\n 'Datadog SDK is already tracking XHR resources',\n SdkVerbosity.WARN\n );\n return;\n }\n\n this.requestProxy = new XHRProxy({\n xhrType: XMLHttpRequest,\n resourceReporter: new ResourceReporter([filterDevResource])\n });\n this.requestProxy.onTrackingStart({\n tracingSamplingRate,\n firstPartyHostsRegex: firstPartyHostsRegexBuilder(firstPartyHosts)\n });\n\n InternalLog.log(\n 'Datadog SDK is tracking XHR resources',\n SdkVerbosity.INFO\n );\n DdRumResourceTracking.isTracking = true;\n }\n\n static stopTracking(): void {\n if (DdRumResourceTracking.isTracking) {\n DdRumResourceTracking.isTracking = false;\n if (this.requestProxy) {\n this.requestProxy.onTrackingStop();\n }\n this.requestProxy = null;\n }\n }\n}\n"]}
|
|
@@ -3,10 +3,44 @@
|
|
|
3
3
|
* This product includes software developed at Datadog (https://www.datadoghq.com/).
|
|
4
4
|
* Copyright 2016-Present Datadog, Inc.
|
|
5
5
|
*/
|
|
6
|
+
import { isHostFirstParty } from './firstPartyHosts';
|
|
7
|
+
const DISCARDED_TRACE_ATTRIBUTES = {
|
|
8
|
+
samplingPriorityHeader: '0',
|
|
9
|
+
tracingStrategy: 'DISCARD'
|
|
10
|
+
};
|
|
11
|
+
export const getTracingAttributes = ({
|
|
12
|
+
hostname,
|
|
13
|
+
firstPartyHostsRegex,
|
|
14
|
+
tracingSamplingRate
|
|
15
|
+
}) => {
|
|
16
|
+
if (hostname === null) {
|
|
17
|
+
return DISCARDED_TRACE_ATTRIBUTES;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
if (isHostFirstParty(hostname, firstPartyHostsRegex)) {
|
|
21
|
+
return generateTracingAttributesWithSampling(tracingSamplingRate);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return DISCARDED_TRACE_ATTRIBUTES;
|
|
25
|
+
};
|
|
6
26
|
|
|
27
|
+
const generateTracingAttributesWithSampling = tracingSamplingRate => {
|
|
28
|
+
if (Math.random() * 100 <= tracingSamplingRate) {
|
|
29
|
+
return {
|
|
30
|
+
traceId: generateTraceId(),
|
|
31
|
+
spanId: generateTraceId(),
|
|
32
|
+
samplingPriorityHeader: '1',
|
|
33
|
+
tracingStrategy: 'KEEP'
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return DISCARDED_TRACE_ATTRIBUTES;
|
|
38
|
+
};
|
|
7
39
|
/*
|
|
8
40
|
* This code was inspired from browser-sdk at (https://github.com/DataDog/browser-sdk/blob/master/packages/rum-core/src/domain/tracing/tracer.ts#L107)
|
|
9
41
|
*/
|
|
42
|
+
|
|
43
|
+
|
|
10
44
|
export function generateTraceId() {
|
|
11
45
|
const radix = 10;
|
|
12
46
|
const MAX_32_BITS_NUMBER = 4294967295; // 2^32-1
|
|
@@ -33,4 +67,4 @@ export function generateTraceId() {
|
|
|
33
67
|
|
|
34
68
|
return str;
|
|
35
69
|
}
|
|
36
|
-
//# sourceMappingURL=
|
|
70
|
+
//# sourceMappingURL=distributedTracing.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["distributedTracing.tsx"],"names":["isHostFirstParty","DISCARDED_TRACE_ATTRIBUTES","samplingPriorityHeader","tracingStrategy","getTracingAttributes","hostname","firstPartyHostsRegex","tracingSamplingRate","generateTracingAttributesWithSampling","Math","random","traceId","generateTraceId","spanId","radix","MAX_32_BITS_NUMBER","low","floor","high","str","modH","temp","digit","toString"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AAGA,SAASA,gBAAT,QAAiC,mBAAjC;AAgBA,MAAMC,0BAA0D,GAAG;AAC/DC,EAAAA,sBAAsB,EAAE,GADuC;AAE/DC,EAAAA,eAAe,EAAE;AAF8C,CAAnE;AAKA,OAAO,MAAMC,oBAAoB,GAAG,CAAC;AACjCC,EAAAA,QADiC;AAEjCC,EAAAA,oBAFiC;AAGjCC,EAAAA;AAHiC,CAAD,KAQE;AAClC,MAAIF,QAAQ,KAAK,IAAjB,EAAuB;AACnB,WAAOJ,0BAAP;AACH;;AACD,MAAID,gBAAgB,CAACK,QAAD,EAAWC,oBAAX,CAApB,EAAsD;AAClD,WAAOE,qCAAqC,CAACD,mBAAD,CAA5C;AACH;;AACD,SAAON,0BAAP;AACH,CAhBM;;AAkBP,MAAMO,qCAAqC,GACvCD,mBAD0C,IAET;AACjC,MAAIE,IAAI,CAACC,MAAL,KAAgB,GAAhB,IAAuBH,mBAA3B,EAAgD;AAC5C,WAAO;AACHI,MAAAA,OAAO,EAAEC,eAAe,EADrB;AAEHC,MAAAA,MAAM,EAAED,eAAe,EAFpB;AAGHV,MAAAA,sBAAsB,EAAE,GAHrB;AAIHC,MAAAA,eAAe,EAAE;AAJd,KAAP;AAMH;;AACD,SAAOF,0BAAP;AACH,CAZD;AAcA;AACA;AACA;;;AACA,OAAO,SAASW,eAAT,GAAmC;AACtC,QAAME,KAAK,GAAG,EAAd;AACA,QAAMC,kBAAkB,GAAG,UAA3B,CAFsC,CAEC;;AACvC,MAAIC,GAAW,GAAGP,IAAI,CAACQ,KAAL,CAAWR,IAAI,CAACC,MAAL,KAAgBK,kBAA3B,CAAlB;AACA,MAAIG,IAAY,GAAGT,IAAI,CAACQ,KAAL,CAAWR,IAAI,CAACC,MAAL,KAAgBK,kBAA3B,CAAnB;AACA,MAAII,GAAG,GAAG,EAAV;;AAEA,SAAOD,IAAI,GAAG,CAAP,IAAYF,GAAG,GAAG,CAAzB,EAA4B;AACxB;AACA;AACA,UAAMI,IAAI,GAAGF,IAAI,GAAGJ,KAApB;AACA,UAAMO,IAAI,GAAG,CAACD,IAAI,IAAI,EAAT,IAAeJ,GAA5B;AACA,UAAMM,KAAK,GAAGD,IAAI,GAAGP,KAArB,CALwB,CAOxB;;AACAI,IAAAA,IAAI,GAAG,CAACA,IAAI,GAAGE,IAAR,IAAgBN,KAAvB,CARwB,CAQM;AAC9B;;AACAE,IAAAA,GAAG,GAAG,CAACK,IAAI,GAAGC,KAAR,IAAiBR,KAAvB,CAVwB,CAUM;AAE9B;;AACAK,IAAAA,GAAG,GAAGG,KAAK,CAACC,QAAN,KAAmBJ,GAAzB;AACH;;AACD,SAAOA,GAAP;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 type { Hostname } from './firstPartyHosts';\nimport { isHostFirstParty } from './firstPartyHosts';\n\nexport type DdRumResourceTracingAttributes =\n | {\n tracingStrategy: 'KEEP';\n traceId: string;\n spanId: string;\n samplingPriorityHeader: '1';\n }\n | {\n tracingStrategy: 'DISCARD';\n traceId?: void;\n spanId?: void;\n samplingPriorityHeader: '0';\n };\n\nconst DISCARDED_TRACE_ATTRIBUTES: DdRumResourceTracingAttributes = {\n samplingPriorityHeader: '0',\n tracingStrategy: 'DISCARD'\n};\n\nexport const getTracingAttributes = ({\n hostname,\n firstPartyHostsRegex,\n tracingSamplingRate\n}: {\n hostname: Hostname | null;\n firstPartyHostsRegex: RegExp;\n tracingSamplingRate: number;\n}): DdRumResourceTracingAttributes => {\n if (hostname === null) {\n return DISCARDED_TRACE_ATTRIBUTES;\n }\n if (isHostFirstParty(hostname, firstPartyHostsRegex)) {\n return generateTracingAttributesWithSampling(tracingSamplingRate);\n }\n return DISCARDED_TRACE_ATTRIBUTES;\n};\n\nconst generateTracingAttributesWithSampling = (\n tracingSamplingRate: number\n): DdRumResourceTracingAttributes => {\n if (Math.random() * 100 <= tracingSamplingRate) {\n return {\n traceId: generateTraceId(),\n spanId: generateTraceId(),\n samplingPriorityHeader: '1',\n tracingStrategy: 'KEEP'\n };\n }\n return DISCARDED_TRACE_ATTRIBUTES;\n};\n\n/*\n * This code was inspired from browser-sdk at (https://github.com/DataDog/browser-sdk/blob/master/packages/rum-core/src/domain/tracing/tracer.ts#L107)\n */\nexport function generateTraceId(): string {\n const radix = 10;\n const MAX_32_BITS_NUMBER = 4294967295; // 2^32-1\n let low: number = Math.floor(Math.random() * MAX_32_BITS_NUMBER);\n let high: number = Math.floor(Math.random() * MAX_32_BITS_NUMBER);\n let str = '';\n\n while (high > 0 && low > 0) {\n // Create an intermediate value with the same modulo as the combined high and low value\n // but requiring 36 bits max (32 for the low value + 4 for the high part)\n const modH = high % radix;\n const temp = (modH << 32) + low;\n const digit = temp % radix;\n\n // update the high value\n high = (high - modH) / radix; // we reuse the modH to avoid the need of a floor op\n // the low value reuses the previous temp value to account for the \"missing mod\" in the high update\n low = (temp - digit) / radix; // we reuse the digit to avoid the need of a floor op\n\n // update the string from right to left\n str = digit.toString() + str;\n }\n return str;\n}\n"]}
|
|
@@ -0,0 +1,29 @@
|
|
|
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^');
|
|
10
|
+
export const firstPartyHostsRegexBuilder = firstPartyHosts => {
|
|
11
|
+
if (firstPartyHosts.length === 0) {
|
|
12
|
+
return NO_MATCH_REGEX;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
try {
|
|
16
|
+
// A regexp for matching hosts, e.g. when `hosts` is "example.com", it will match
|
|
17
|
+
// "example.com", "api.example.com", but not "foo.com".
|
|
18
|
+
const firstPartyHostsRegex = new RegExp(`^(.*\\.)*(${firstPartyHosts.map(host => `${host}$`).join('|')})`);
|
|
19
|
+
firstPartyHostsRegex.test('test_the_regex_is_valid');
|
|
20
|
+
return firstPartyHostsRegex;
|
|
21
|
+
} catch (e) {
|
|
22
|
+
InternalLog.log(`Invalid first party hosts list ${JSON.stringify(firstPartyHosts)}. Regular expressions are not allowed.`, SdkVerbosity.WARN);
|
|
23
|
+
return NO_MATCH_REGEX;
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
export const isHostFirstParty = (hostname, firstPartyHostsRegex) => {
|
|
27
|
+
return firstPartyHostsRegex.test(hostname);
|
|
28
|
+
};
|
|
29
|
+
//# sourceMappingURL=firstPartyHosts.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["firstPartyHosts.ts"],"names":["InternalLog","SdkVerbosity","NO_MATCH_REGEX","RegExp","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;AAEP,OAAO,MAAMC,2BAA2B,GACpCC,eADuC,IAE9B;AACT,MAAIA,eAAe,CAACC,MAAhB,KAA2B,CAA/B,EAAkC;AAC9B,WAAOJ,cAAP;AACH;;AACD,MAAI;AACA;AACA;AACA,UAAMK,oBAAoB,GAAG,IAAIJ,MAAJ,CACxB,aAAYE,eAAe,CAACG,GAAhB,CAAoBC,IAAI,IAAK,GAAEA,IAAK,GAApC,EAAwCC,IAAxC,CAA6C,GAA7C,CAAkD,GADtC,CAA7B;AAGAH,IAAAA,oBAAoB,CAACI,IAArB,CAA0B,yBAA1B;AACA,WAAOJ,oBAAP;AACH,GARD,CAQE,OAAOK,CAAP,EAAU;AACRZ,IAAAA,WAAW,CAACa,GAAZ,CACK,kCAAiCC,IAAI,CAACC,SAAL,CAC9BV,eAD8B,CAEhC,wCAHN,EAIIJ,YAAY,CAACe,IAJjB;AAMA,WAAOd,cAAP;AACH;AACJ,CAvBM;AAyBP,OAAO,MAAMe,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\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.map(host => `${host}$`).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"]}
|
|
@@ -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
|
+
import { InternalLog } from '../../../../InternalLog';
|
|
7
|
+
import { SdkVerbosity } from '../../../../SdkVerbosity';
|
|
8
|
+
// matches what is between the first "://" and the next "/", ":" or whitespace
|
|
9
|
+
const hostRegex = '^.+://([^:/\\s]+)';
|
|
10
|
+
/**
|
|
11
|
+
* Returns the host from an URL.
|
|
12
|
+
* @returns the host (without the port) or null if could not cast the URL as host
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
export const URLHostParser = url => {
|
|
16
|
+
try {
|
|
17
|
+
const matchedHost = url.match(hostRegex);
|
|
18
|
+
|
|
19
|
+
if (matchedHost === null) {
|
|
20
|
+
return null;
|
|
21
|
+
} // [0] is the input, [1] is the captured group
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
return matchedHost[1];
|
|
25
|
+
} catch (e) {
|
|
26
|
+
InternalLog.log(`Impossible to cast ${url} as URL`, SdkVerbosity.WARN);
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
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"]}
|