@cloudcare/browser-rum 3.3.4 → 3.3.6
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/bundle/dataflux-rum.js +1 -1
- package/cjs/boot/buildEnv.js +1 -1
- package/cjs/boot/perStartRum.js +42 -6
- package/cjs/boot/perStartRum.js.map +1 -1
- package/cjs/boot/recorderApi.js +35 -10
- package/cjs/boot/recorderApi.js.map +1 -1
- package/cjs/boot/rum.js +8 -0
- package/cjs/boot/rum.js.map +1 -1
- package/cjs/boot/rumPublicApi.js +36 -3
- package/cjs/boot/rumPublicApi.js.map +1 -1
- package/cjs/domain/configuration.js +7 -0
- package/cjs/domain/configuration.js.map +1 -1
- package/cjs/domain/contexts/urlContexts.js +11 -2
- package/cjs/domain/contexts/urlContexts.js.map +1 -1
- package/cjs/domain/contexts/viewContexts.js +2 -2
- package/cjs/domain/contexts/viewContexts.js.map +1 -1
- package/cjs/domain/deflate/deflateWorker.js +1 -1
- package/cjs/domain/plugins.js +67 -0
- package/cjs/domain/plugins.js.map +1 -0
- package/cjs/domain/replay/record/canvasEncodeWorker.js +1 -1
- package/cjs/domain/rumEventsCollection/error/errorCollection.js +17 -5
- package/cjs/domain/rumEventsCollection/error/errorCollection.js.map +1 -1
- package/cjs/domain/rumEventsCollection/resource/resourceCollection.js +56 -0
- package/cjs/domain/rumEventsCollection/resource/resourceCollection.js.map +1 -1
- package/cjs/domain/rumEventsCollection/resource/webSocketCollection.js +196 -0
- package/cjs/domain/rumEventsCollection/resource/webSocketCollection.js.map +1 -0
- package/cjs/domain/rumEventsCollection/view/trackLoadingTime.js +8 -3
- package/cjs/domain/rumEventsCollection/view/trackLoadingTime.js.map +1 -1
- package/cjs/domain/rumEventsCollection/view/trackViews.js +2 -1
- package/cjs/domain/rumEventsCollection/view/trackViews.js.map +1 -1
- package/cjs/domain/rumSessionManager.js +23 -3
- package/cjs/domain/rumSessionManager.js.map +1 -1
- package/esm/boot/buildEnv.js +1 -1
- package/esm/boot/perStartRum.js +42 -6
- package/esm/boot/perStartRum.js.map +1 -1
- package/esm/boot/recorderApi.js +35 -10
- package/esm/boot/recorderApi.js.map +1 -1
- package/esm/boot/rum.js +8 -0
- package/esm/boot/rum.js.map +1 -1
- package/esm/boot/rumPublicApi.js +36 -3
- package/esm/boot/rumPublicApi.js.map +1 -1
- package/esm/domain/configuration.js +8 -1
- package/esm/domain/configuration.js.map +1 -1
- package/esm/domain/contexts/urlContexts.js +12 -3
- package/esm/domain/contexts/urlContexts.js.map +1 -1
- package/esm/domain/contexts/viewContexts.js +2 -2
- package/esm/domain/contexts/viewContexts.js.map +1 -1
- package/esm/domain/deflate/deflateWorker.js +1 -1
- package/esm/domain/plugins.js +59 -0
- package/esm/domain/plugins.js.map +1 -0
- package/esm/domain/replay/record/canvasEncodeWorker.js +1 -1
- package/esm/domain/rumEventsCollection/error/errorCollection.js +17 -5
- package/esm/domain/rumEventsCollection/error/errorCollection.js.map +1 -1
- package/esm/domain/rumEventsCollection/resource/resourceCollection.js +55 -0
- package/esm/domain/rumEventsCollection/resource/resourceCollection.js.map +1 -1
- package/esm/domain/rumEventsCollection/resource/webSocketCollection.js +189 -0
- package/esm/domain/rumEventsCollection/resource/webSocketCollection.js.map +1 -0
- package/esm/domain/rumEventsCollection/view/trackLoadingTime.js +8 -3
- package/esm/domain/rumEventsCollection/view/trackLoadingTime.js.map +1 -1
- package/esm/domain/rumEventsCollection/view/trackViews.js +2 -1
- package/esm/domain/rumEventsCollection/view/trackViews.js.map +1 -1
- package/esm/domain/rumSessionManager.js +24 -4
- package/esm/domain/rumSessionManager.js.map +1 -1
- package/package.json +4 -4
- package/src/boot/perStartRum.js +47 -7
- package/src/boot/recorderApi.js +36 -12
- package/src/boot/rum.js +11 -0
- package/src/boot/rumPublicApi.js +38 -3
- package/src/domain/configuration.js +13 -1
- package/src/domain/contexts/urlContexts.js +17 -3
- package/src/domain/contexts/viewContexts.js +2 -2
- package/src/domain/plugins.js +94 -0
- package/src/domain/rumEventsCollection/error/errorCollection.js +22 -6
- package/src/domain/rumEventsCollection/resource/resourceCollection.js +70 -0
- package/src/domain/rumEventsCollection/resource/webSocketCollection.js +271 -0
- package/src/domain/rumEventsCollection/view/trackLoadingTime.js +12 -3
- package/src/domain/rumEventsCollection/view/trackViews.js +2 -1
- package/src/domain/rumSessionManager.js +33 -2
- package/types/index.d.ts +85 -6
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { assign, catchUserErrors, display, each, getType, isArray } from '@cloudcare/browser-core';
|
|
2
|
+
var PLUGIN_METHODS = ['onInit', 'onRumStart', 'getConfigurationTelemetry'];
|
|
3
|
+
export function validatePlugins(plugins) {
|
|
4
|
+
if (plugins === undefined) {
|
|
5
|
+
return true;
|
|
6
|
+
}
|
|
7
|
+
if (!isArray(plugins)) {
|
|
8
|
+
display.error('Plugins should be an array');
|
|
9
|
+
return false;
|
|
10
|
+
}
|
|
11
|
+
for (var i = 0; i < plugins.length; i += 1) {
|
|
12
|
+
var plugin = plugins[i];
|
|
13
|
+
if (!plugin || getType(plugin.name) !== 'string' || plugin.name.length === 0) {
|
|
14
|
+
display.error('Plugins should have a non-empty string name');
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
for (var methodIndex = 0; methodIndex < PLUGIN_METHODS.length; methodIndex += 1) {
|
|
18
|
+
var methodName = PLUGIN_METHODS[methodIndex];
|
|
19
|
+
if (plugin[methodName] !== undefined && getType(plugin[methodName]) !== 'function') {
|
|
20
|
+
display.error('Plugin ' + plugin.name + ' has an invalid ' + methodName + ' method');
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return true;
|
|
26
|
+
}
|
|
27
|
+
export function callPluginsMethod(plugins, methodName, parameter) {
|
|
28
|
+
if (!plugins) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
each(plugins, function (plugin) {
|
|
32
|
+
var method = plugin[methodName];
|
|
33
|
+
if (getType(method) !== 'function') {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
catchUserErrors(function () {
|
|
37
|
+
return method.call(plugin, parameter);
|
|
38
|
+
}, plugin.name + ' plugin ' + methodName + ' threw an error:')();
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
export function getPluginsTelemetry(plugins) {
|
|
42
|
+
var telemetry = [];
|
|
43
|
+
each(plugins || [], function (plugin) {
|
|
44
|
+
var pluginTelemetry = {
|
|
45
|
+
name: plugin.name
|
|
46
|
+
};
|
|
47
|
+
if (getType(plugin.getConfigurationTelemetry) === 'function') {
|
|
48
|
+
var configurationTelemetry = catchUserErrors(function () {
|
|
49
|
+
return plugin.getConfigurationTelemetry();
|
|
50
|
+
}, plugin.name + ' plugin getConfigurationTelemetry threw an error:')();
|
|
51
|
+
if (getType(configurationTelemetry) === 'object') {
|
|
52
|
+
pluginTelemetry = assign(pluginTelemetry, configurationTelemetry);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
telemetry.push(pluginTelemetry);
|
|
56
|
+
});
|
|
57
|
+
return telemetry;
|
|
58
|
+
}
|
|
59
|
+
//# sourceMappingURL=plugins.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugins.js","names":["assign","catchUserErrors","display","each","getType","isArray","PLUGIN_METHODS","validatePlugins","plugins","undefined","error","i","length","plugin","name","methodIndex","methodName","callPluginsMethod","parameter","method","call","getPluginsTelemetry","telemetry","pluginTelemetry","getConfigurationTelemetry","configurationTelemetry","push"],"sources":["../../src/domain/plugins.js"],"sourcesContent":["import {\n assign,\n catchUserErrors,\n display,\n each,\n getType,\n isArray\n} from '@cloudcare/browser-core'\n\nvar PLUGIN_METHODS = [\n 'onInit',\n 'onRumStart',\n 'getConfigurationTelemetry'\n]\n\nexport function validatePlugins(plugins) {\n if (plugins === undefined) {\n return true\n }\n if (!isArray(plugins)) {\n display.error('Plugins should be an array')\n return false\n }\n\n for (var i = 0; i < plugins.length; i += 1) {\n var plugin = plugins[i]\n if (\n !plugin ||\n getType(plugin.name) !== 'string' ||\n plugin.name.length === 0\n ) {\n display.error('Plugins should have a non-empty string name')\n return false\n }\n\n for (\n var methodIndex = 0;\n methodIndex < PLUGIN_METHODS.length;\n methodIndex += 1\n ) {\n var methodName = PLUGIN_METHODS[methodIndex]\n if (\n plugin[methodName] !== undefined &&\n getType(plugin[methodName]) !== 'function'\n ) {\n display.error(\n 'Plugin ' + plugin.name + ' has an invalid ' + methodName + ' method'\n )\n return false\n }\n }\n }\n\n return true\n}\n\nexport function callPluginsMethod(plugins, methodName, parameter) {\n if (!plugins) {\n return\n }\n\n each(plugins, function (plugin) {\n var method = plugin[methodName]\n if (getType(method) !== 'function') {\n return\n }\n catchUserErrors(\n function () {\n return method.call(plugin, parameter)\n },\n plugin.name + ' plugin ' + methodName + ' threw an error:'\n )()\n })\n}\n\nexport function getPluginsTelemetry(plugins) {\n var telemetry = []\n each(plugins || [], function (plugin) {\n var pluginTelemetry = { name: plugin.name }\n if (getType(plugin.getConfigurationTelemetry) === 'function') {\n var configurationTelemetry = catchUserErrors(\n function () {\n return plugin.getConfigurationTelemetry()\n },\n plugin.name + ' plugin getConfigurationTelemetry threw an error:'\n )()\n if (getType(configurationTelemetry) === 'object') {\n pluginTelemetry = assign(pluginTelemetry, configurationTelemetry)\n }\n }\n telemetry.push(pluginTelemetry)\n })\n return telemetry\n}\n"],"mappings":"AAAA,SACEA,MAAM,EACNC,eAAe,EACfC,OAAO,EACPC,IAAI,EACJC,OAAO,EACPC,OAAO,QACF,yBAAyB;AAEhC,IAAIC,cAAc,GAAG,CACnB,QAAQ,EACR,YAAY,EACZ,2BAA2B,CAC5B;AAED,OAAO,SAASC,eAAeA,CAACC,OAAO,EAAE;EACvC,IAAIA,OAAO,KAAKC,SAAS,EAAE;IACzB,OAAO,IAAI;EACb;EACA,IAAI,CAACJ,OAAO,CAACG,OAAO,CAAC,EAAE;IACrBN,OAAO,CAACQ,KAAK,CA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AM,CAACC,IAAI,GAAG,UAAU,GAAGE,UAAU,GAAG,kBAC1C,CAAC,CAAC,CAAC;EACL,CAAC,CAAC;AACJ;AAEA,OAAO,SAASK,mBAAmBA,CAACb,OAAO,EAAE;EAC3C,IAAIc,SAAS,GAAG,EAAE;EAClBnB,IAAI,CAACK,OAAO,IAAI,EAAE,EAAE,UAAUK,MAAM,EAAE;IACpC,IAAIU,eAAe,GAAG;MAAET,IAAI,EAAED,MAAM,CAACC;IAAK,CAAC;IAC3C,IAAIV,OAAO,CAACS,MAAM,CAACW,yBAAyB,CAAC,KAAK,UAAU,EAAE;MAC5D,IAAIC,sBAAsB,GAAGxB,eAAe,CAC1C,YAAY;QACV,OAAOY,MAAM,CAACW,yBAAyB,CAAC,CAAC;MAC3C,CAAC,EACDX,MAAM,CAACC,IAAI,GAAG,mDAChB,CAAC,CAAC,CAAC;MACH,IAAIV,OAAO,CAACqB,sBAAsB,CAAC,KAAK,QAAQ,EAAE;QAChDF,eAAe,GAAGvB,MAAM,CAACuB,eAAe,EAAEE,sBAAsB,CAAC;MACnE;IACF;IACAH,SAAS,CAACI,IAAI,CAACH,eAAe,CAAC;EACjC,CAAC,CAAC;EACF,OAAOD,SAAS;AAClB","ignoreList":[]}
|
|
@@ -10,7 +10,7 @@ export function createCanvasEncodeWorker(configuration, workerCtor, urlObject) {
|
|
|
10
10
|
var workerUrl = configuration.replayCanvasWorkerUrl;
|
|
11
11
|
var usesExternalUrl = !!workerUrl;
|
|
12
12
|
if (!workerUrl) {
|
|
13
|
-
workerUrl = urlObject.createObjectURL(new Blob(["!function(){\"use strict\";function t(t){for(var e=new Uint8Array(t),n=[],r=0;r<e.length;r+=8192){for(var i=e.subarray(r,r+8192),o=\"\",a=0;a<i.length;a+=1)o+=String.fromCharCode(i[a]);n.push(o)}return btoa(n.join(\"\"))}function e(t,e){try{t.postMessage(e)}catch(n){t.postMessage({action:\"errored\",id:e&&e.id,error:String(n&&n.message?n.message:n)})}}var n;void 0===n&&(n=self),n.addEventListener(\"message\",(function(r){var i=r.data;i&&(\"init\"!==i.action?\"encode\"===i.action&&Promise.resolve().then((function(){var e=function(t,e,n){if(!t||!e||!n)return{width:t,height:e};if(t<=n&&e<=n)return{width:t,height:e};var r=t>e?n/t:n/e;return{width:Math.max(1,Math.round(t*r)),height:Math.max(1,Math.round(e*r))}}(i.width,i.height,i.maxSize),n=new OffscreenCanvas(e.width,e.height),r=n.getContext(\"2d\");if(!r)throw new Error(\"Cannot create offscreen canvas 2d context for encoding\");if(r.drawImage(i.bitmap,0,0,e.width,e.height),i.bitmap&&\"function\"==typeof i.bitmap.close&&i.bitmap.close(),\"function\"!=typeof n.convertToBlob)throw new Error(\"OffscreenCanvas convertToBlob is not supported\");return n.convertToBlob({type:i.mimeType,quality:i.quality}).then((function(n){return n.arrayBuffer().then((function(r){var o=n.type||i.mimeType;return{action:\"encoded\",id:i.id,dataUrl:\"data:\"+o+\";base64,\"+t(r),width:e.width,height:e.height}}))}))})).then((function(t){e(n,t)})).catch((function(t){e(n,{action:\"errored\",id:i.id,error:String(t&&t.message?t.message:t)})})):e(n,{action:\"initialized\",version:\"3.3.
|
|
13
|
+
workerUrl = urlObject.createObjectURL(new Blob(["!function(){\"use strict\";function t(t){for(var e=new Uint8Array(t),n=[],r=0;r<e.length;r+=8192){for(var i=e.subarray(r,r+8192),o=\"\",a=0;a<i.length;a+=1)o+=String.fromCharCode(i[a]);n.push(o)}return btoa(n.join(\"\"))}function e(t,e){try{t.postMessage(e)}catch(n){t.postMessage({action:\"errored\",id:e&&e.id,error:String(n&&n.message?n.message:n)})}}var n;void 0===n&&(n=self),n.addEventListener(\"message\",(function(r){var i=r.data;i&&(\"init\"!==i.action?\"encode\"===i.action&&Promise.resolve().then((function(){var e=function(t,e,n){if(!t||!e||!n)return{width:t,height:e};if(t<=n&&e<=n)return{width:t,height:e};var r=t>e?n/t:n/e;return{width:Math.max(1,Math.round(t*r)),height:Math.max(1,Math.round(e*r))}}(i.width,i.height,i.maxSize),n=new OffscreenCanvas(e.width,e.height),r=n.getContext(\"2d\");if(!r)throw new Error(\"Cannot create offscreen canvas 2d context for encoding\");if(r.drawImage(i.bitmap,0,0,e.width,e.height),i.bitmap&&\"function\"==typeof i.bitmap.close&&i.bitmap.close(),\"function\"!=typeof n.convertToBlob)throw new Error(\"OffscreenCanvas convertToBlob is not supported\");return n.convertToBlob({type:i.mimeType,quality:i.quality}).then((function(n){return n.arrayBuffer().then((function(r){var o=n.type||i.mimeType;return{action:\"encoded\",id:i.id,dataUrl:\"data:\"+o+\";base64,\"+t(r),width:e.width,height:e.height}}))}))})).then((function(t){e(n,t)})).catch((function(t){e(n,{action:\"errored\",id:i.id,error:String(t&&t.message?t.message:t)})})):e(n,{action:\"initialized\",version:\"3.3.6\"}))}))}();"]));
|
|
14
14
|
}
|
|
15
15
|
return {
|
|
16
16
|
worker: new workerCtor(workerUrl),
|
|
@@ -8,22 +8,31 @@ export function startErrorCollection(lifeCycle, configuration, sessionManager, p
|
|
|
8
8
|
trackRuntimeError(errorObservable);
|
|
9
9
|
trackReportError(configuration, errorObservable);
|
|
10
10
|
var session = sessionManager.findTrackedSession();
|
|
11
|
-
var hasError = session && session.
|
|
12
|
-
if (session
|
|
11
|
+
var hasError = shouldMarkSessionOnError(session) && session.sessionHasError;
|
|
12
|
+
if (shouldMarkSessionOnError(session)) {
|
|
13
13
|
lifeCycle.subscribe(LifeCycleEventType.SESSION_RENEWED, function () {
|
|
14
14
|
hasError = false;
|
|
15
15
|
});
|
|
16
16
|
}
|
|
17
|
-
|
|
18
|
-
if (session &&
|
|
17
|
+
var markSessionOnError = function markSessionOnError() {
|
|
18
|
+
if (shouldMarkSessionOnError(session) && !hasError) {
|
|
19
19
|
sessionManager.setErrorForSession();
|
|
20
20
|
hasError = true;
|
|
21
21
|
}
|
|
22
|
+
};
|
|
23
|
+
errorObservable.subscribe(function (error) {
|
|
24
|
+
markSessionOnError();
|
|
22
25
|
lifeCycle.notify(LifeCycleEventType.RAW_ERROR_COLLECTED, {
|
|
23
26
|
error: error
|
|
24
27
|
});
|
|
25
28
|
});
|
|
26
|
-
|
|
29
|
+
var errorCollection = doStartErrorCollection(lifeCycle, pageStateHistory);
|
|
30
|
+
return {
|
|
31
|
+
addError: function addError(providedError, savedCommonContext) {
|
|
32
|
+
markSessionOnError();
|
|
33
|
+
errorCollection.addError(providedError, savedCommonContext);
|
|
34
|
+
}
|
|
35
|
+
};
|
|
27
36
|
}
|
|
28
37
|
export function doStartErrorCollection(lifeCycle, pageStateHistory) {
|
|
29
38
|
lifeCycle.subscribe(LifeCycleEventType.RAW_ERROR_COLLECTED, function (error) {
|
|
@@ -80,4 +89,7 @@ function processError(error, pageStateHistory) {
|
|
|
80
89
|
}
|
|
81
90
|
};
|
|
82
91
|
}
|
|
92
|
+
function shouldMarkSessionOnError(session) {
|
|
93
|
+
return session && (session.isErrorSession || session.errorSessionReplayAllowed === true);
|
|
94
|
+
}
|
|
83
95
|
//# sourceMappingURL=errorCollection.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errorCollection.js","names":["assign","computeStackTrace","computeRawError","ErrorSource","UUID","ErrorHandling","Observable","trackRuntimeError","RumEventType","LifeCycleEventType","NonErrorPrefix","trackConsoleError","trackReportError","PageState","startErrorCollection","lifeCycle","configuration","sessionManager","pageStateHistory","errorObservable","session","findTrackedSession","hasError","
|
|
1
|
+
{"version":3,"file":"errorCollection.js","names":["assign","computeStackTrace","computeRawError","ErrorSource","UUID","ErrorHandling","Observable","trackRuntimeError","RumEventType","LifeCycleEventType","NonErrorPrefix","trackConsoleError","trackReportError","PageState","startErrorCollection","lifeCycle","configuration","sessionManager","pageStateHistory","errorObservable","session","findTrackedSession","hasError","shouldMarkSessionOnError","sessionHasError","subscribe","SESSION_RENEWED","markSessionOnError","setErrorForSession","error","notify","RAW_ERROR_COLLECTED","errorCollection","doStartErrorCollection","addError","providedError","savedCommonContext","RAW_RUM_EVENT_COLLECTED","customerContext","processError","stackTrace","Error","undefined","rawError","originalError","handlingStack","startClocks","nonErrorPrefix","PROVIDED","source","CUSTOM","handling","HANDLED","context","rawRumEvent","date","timeStamp","id","message","stack","handling_stack","type","causes","source_type","ERROR","view","in_foreground","wasInPageStateAt","ACTIVE","relative","startTime","domainContext","isErrorSession","errorSessionReplayAllowed"],"sources":["../../../../src/domain/rumEventsCollection/error/errorCollection.js"],"sourcesContent":["import {\n assign,\n computeStackTrace,\n computeRawError,\n ErrorSource,\n UUID,\n ErrorHandling,\n Observable,\n trackRuntimeError,\n RumEventType,\n LifeCycleEventType,\n NonErrorPrefix\n} from '@cloudcare/browser-core'\nimport { trackConsoleError } from './trackConsoleError'\nimport { trackReportError } from './trackReportError'\nimport { PageState } from '../../contexts/pageStateHistory'\n\nexport function startErrorCollection(\n lifeCycle,\n configuration,\n sessionManager,\n pageStateHistory\n) {\n var errorObservable = new Observable()\n\n trackConsoleError(errorObservable)\n trackRuntimeError(errorObservable)\n trackReportError(configuration, errorObservable)\n var session = sessionManager.findTrackedSession()\n let hasError = shouldMarkSessionOnError(session) && session.sessionHasError\n if (shouldMarkSessionOnError(session)) {\n lifeCycle.subscribe(LifeCycleEventType.SESSION_RENEWED, function () {\n hasError = false\n })\n }\n var markSessionOnError = function () {\n if (shouldMarkSessionOnError(session) && !hasError) {\n sessionManager.setErrorForSession()\n hasError = true\n }\n }\n\n errorObservable.subscribe(function (error) {\n markSessionOnError()\n lifeCycle.notify(LifeCycleEventType.RAW_ERROR_COLLECTED, { error: error })\n })\n\n var errorCollection = doStartErrorCollection(lifeCycle, pageStateHistory)\n return {\n addError: function (providedError, savedCommonContext) {\n markSessionOnError()\n errorCollection.addError(providedError, savedCommonContext)\n }\n }\n}\n\nexport function doStartErrorCollection(lifeCycle, pageStateHistory) {\n lifeCycle.subscribe(LifeCycleEventType.RAW_ERROR_COLLECTED, function (error) {\n lifeCycle.notify(\n LifeCycleEventType.RAW_RUM_EVENT_COLLECTED,\n assign(\n {\n customerContext: error.customerContext,\n savedCommonContext: error.savedCommonContext\n },\n processError(error.error, pageStateHistory)\n )\n )\n })\n\n return {\n addError: function (providedError, savedCommonContext) {\n var error = providedError.error\n var stackTrace =\n error instanceof Error ? computeStackTrace(error) : undefined\n var rawError = computeRawError({\n stackTrace,\n originalError: error,\n handlingStack: providedError.handlingStack,\n startClocks: providedError.startClocks,\n nonErrorPrefix: NonErrorPrefix.PROVIDED,\n source: ErrorSource.CUSTOM,\n handling: ErrorHandling.HANDLED\n })\n lifeCycle.notify(LifeCycleEventType.RAW_ERROR_COLLECTED, {\n customerContext: providedError.context,\n savedCommonContext: savedCommonContext,\n error: rawError\n })\n }\n }\n}\n\nfunction processError(error, pageStateHistory) {\n var rawRumEvent = {\n date: error.startClocks.timeStamp,\n error: {\n id: UUID(),\n message: error.message,\n source: error.source,\n stack: error.stack,\n handling_stack: error.handlingStack,\n type: error.type,\n handling: error.handling,\n causes: error.causes,\n source_type: 'browser'\n },\n type: RumEventType.ERROR,\n view: {\n in_foreground: pageStateHistory.wasInPageStateAt(\n PageState.ACTIVE,\n error.startClocks.relative\n )\n }\n }\n\n return {\n rawRumEvent: rawRumEvent,\n startTime: error.startClocks.relative,\n domainContext: {\n error: error.originalError\n }\n }\n}\n\nfunction shouldMarkSessionOnError(session) {\n return (\n session &&\n (session.isErrorSession || session.errorSessionReplayAllowed === true)\n )\n}\n"],"mappings":"AAAA,SACEA,MAAM,EACNC,iBAAiB,EACjBC,eAAe,EACfC,WAAW,EACXC,IAAI,EACJC,aAAa,EACbC,UAAU,EACVC,iBAAiB,EACjBC,YAAY,EACZC,kBAAkB,EAClBC,cAAc,QACT,yBAAyB;AAChC,SAASC,iBAAiB,QAAQ,qBAAqB;AACvD,SAASC,gBAAgB,QAAQ,oBAAoB;AACrD,SAASC,SAAS,QAAQ,iCAAiC;AAE3D,OAAO,SAASC,oBAAoBA,CAClCC,SAAS,EACTC,aAAa,EACbC,cAAc,EACdC,gBAAgB,EAChB;EACA,IAAIC,eAAe,GAAG,IAAIb,UA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AAO;MACtBT,MAAM,EAAEpB,KAAK,CAACoB,MAAM;MACpBU,KAAK,EAAE9B,KAAK,CAAC8B,KAAK;MAClBC,cAAc,EAAE/B,KAAK,CAACgB,aAAa;MACnCgB,IAAI,EAAEhC,KAAK,CAACgC,IAAI;MAChBV,QAAQ,EAAEtB,KAAK,CAACsB,QAAQ;MACxBW,MAAM,EAAEjC,KAAK,CAACiC,MAAM;MACpBC,WAAW,EAAE;IACf,CAAC;IACDF,IAAI,EAAErD,YAAY,CAACwD,KAAK;IACxBC,IAAI,EAAE;MACJC,aAAa,EAAEhD,gBAAgB,CAACiD,gBAAgB,CAC9CtD,SAAS,CAACuD,MAAM,EAChBvC,KAAK,CAACiB,WAAW,CAACuB,QACpB;IACF;EACF,CAAC;EAED,OAAO;IACLf,WAAW,EAAEA,WAAW;IACxBgB,SAAS,EAAEzC,KAAK,CAACiB,WAAW,CAACuB,QAAQ;IACrCE,aAAa,EAAE;MACb1C,KAAK,EAAEA,KAAK,CAACe;IACf;EACF,CAAC;AACH;AAEA,SAASrB,wBAAwBA,CAACH,OAAO,EAAE;EACzC,OACEA,OAAO,KACNA,OAAO,CAACoD,cAAc,IAAIpD,OAAO,CAACqD,yBAAyB,KAAK,IAAI,CAAC;AAE1E","ignoreList":[]}
|
|
@@ -17,6 +17,13 @@ export function startResourceCollection(lifeCycle, configuration, pageStateHisto
|
|
|
17
17
|
});
|
|
18
18
|
}
|
|
19
19
|
var requestResourceEntryMatcher = createRequestResourceEntryMatcher();
|
|
20
|
+
var webSocketSubscription = lifeCycle.subscribe(LifeCycleEventType.WEBSOCKET_COMPLETED, function (event) {
|
|
21
|
+
try {
|
|
22
|
+
lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, processWebSocket(event));
|
|
23
|
+
} catch (error) {
|
|
24
|
+
addTelemetryError(error);
|
|
25
|
+
}
|
|
26
|
+
});
|
|
20
27
|
lifeCycle.subscribe(LifeCycleEventType.REQUEST_COMPLETED, function (request) {
|
|
21
28
|
handleResource(function () {
|
|
22
29
|
return processRequest(request, pageStateHistory, requestResourceEntryMatcher);
|
|
@@ -60,6 +67,7 @@ export function startResourceCollection(lifeCycle, configuration, pageStateHisto
|
|
|
60
67
|
}
|
|
61
68
|
return {
|
|
62
69
|
stop: function stop() {
|
|
70
|
+
webSocketSubscription.unsubscribe();
|
|
63
71
|
performanceResourceSubscription.unsubscribe();
|
|
64
72
|
},
|
|
65
73
|
addResource: function addResource(resource, savedCommonContext) {
|
|
@@ -71,6 +79,53 @@ export function startResourceCollection(lifeCycle, configuration, pageStateHisto
|
|
|
71
79
|
}
|
|
72
80
|
};
|
|
73
81
|
}
|
|
82
|
+
export function processWebSocket(event) {
|
|
83
|
+
var duration = event.endClocks.timeStamp - event.startClocks.timeStamp;
|
|
84
|
+
var urlObj = urlParse(event.url).getParse();
|
|
85
|
+
return {
|
|
86
|
+
startTime: event.startClocks.relative,
|
|
87
|
+
rawRumEvent: {
|
|
88
|
+
date: event.startClocks.timeStamp,
|
|
89
|
+
type: RumEventType.RESOURCE,
|
|
90
|
+
resource: {
|
|
91
|
+
id: UUID(),
|
|
92
|
+
type: ResourceType.WEBSOCKET,
|
|
93
|
+
url: event.url,
|
|
94
|
+
urlHost: urlObj.Host,
|
|
95
|
+
urlPath: urlObj.Path,
|
|
96
|
+
urlPathGroup: replaceNumberCharByPath(urlObj.Path),
|
|
97
|
+
urlQuery: getQueryParamsFromUrl(event.url),
|
|
98
|
+
duration: toServerDuration(duration),
|
|
99
|
+
websocket: {
|
|
100
|
+
connectionId: event.connectionId,
|
|
101
|
+
handshakeSucceeded: event.handshakeSucceeded,
|
|
102
|
+
startTime: event.startClocks.timeStamp,
|
|
103
|
+
endTime: event.endClocks.timeStamp,
|
|
104
|
+
startViewId: event.startViewId,
|
|
105
|
+
endViewId: event.endViewId,
|
|
106
|
+
trackingEndReason: event.trackingEndReason,
|
|
107
|
+
closeCode: event.closeCode,
|
|
108
|
+
closeReason: event.closeReason,
|
|
109
|
+
wasClean: event.wasClean,
|
|
110
|
+
messagesIn: event.messagesIn,
|
|
111
|
+
messagesOut: event.messagesOut,
|
|
112
|
+
timeToFirstMessageIn: toServerDuration(event.firstMessageInOffset),
|
|
113
|
+
timeToFirstMessageOut: toServerDuration(event.firstMessageOutOffset),
|
|
114
|
+
lastMessageInAt: event.lastMessageInAt,
|
|
115
|
+
longestInboundSilence: toServerDuration(event.longestInboundSilence),
|
|
116
|
+
inboundIdleDurationBeforeClose: toServerDuration(event.inboundIdleDurationBeforeClose),
|
|
117
|
+
bufferedAmountMax: event.bufferedAmountMax,
|
|
118
|
+
protocol: event.protocol,
|
|
119
|
+
setupDuration: toServerDuration(event.setupDuration)
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
},
|
|
123
|
+
domainContext: {
|
|
124
|
+
isWebSocket: true,
|
|
125
|
+
webSocket: event.webSocket
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
}
|
|
74
129
|
function processRequest(request, pageStateHistory, requestResourceEntryMatcher) {
|
|
75
130
|
var matchingTiming = requestResourceEntryMatcher.matchRequestResourceEntry(request);
|
|
76
131
|
var startClocks = matchingTiming ? relativeToClocks(matchingTiming.startTime) : request.startClocks;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resourceCollection.js","names":["getStatusGroup","UUID","extend","extend2Lev","relativeToClocks","urlParse","getQueryParamsFromUrl","replaceNumberCharByPath","RequestType","ResourceType","RumEventType","LifeCycleEventType","toServerDuration","createTaskQueue","addTelemetryError","createRequestResourceEntryMatcher","computePerformanceResourceDetails","computeResourceEntryDuration","computeResourceEntryType","computeResourceEntrySize","isResourceEntryRequestType","isResourceUrlLimit","isLongDataUrl","sanitizeDataUrl","computeResourceEntryDeliveryType","computeResourceEntryProtocol","PageState","createPerformanceObservable","RumPerformanceEntryType","retrieveInitialDocumentResourceTiming","startResourceCollection","lifeCycle","configuration","pageStateHistory","taskQueue","retrieveInitialDocumentResourceTimingImpl","resourceTrackerManager","undefined","setFlushTrackedResource","rawEvent","notify","RAW_RUM_EVENT_COLLECTED","requestResourceEntryMatcher","subscribe","REQUEST_COMPLETED","request","handleResource","processRequest","performanceResourceSubscription","type","RESOURCE","buffered","entries","loop","entry","name","resourceUrlLimit","processResourceEntry","_i","entries_1","length","timing","computeRawEvent","push","domainContext","resourceTrackerId","trackRequestResource","error","stop","unsubscribe","addResource","resource","savedCommonContext","processCustomResource","matchingTiming","matchRequestResourceEntry","startClocks","startTime","tracingInfo","computeRequestTracingInfo","XHR","FETCH","correspondingTimingOverrides","computeResourceEntryMetrics","duration","computeRequestDuration","urlObj","url","getParse","resourceEvent","date","timeStamp","id","method","status","statusGroup","urlHost","Host","urlPath","Path","urlPathGroup","urlQuery","deliveryType","protocol","relative","rawRumEvent","performanceEntry","xhr","requestHeaderContexts","response","requestInput","input","requestInit","init","isAborted","handlingStack","getResourceTrackerIdFromRequest","computeResourceEntryTracingInfo","entryMetrics","discardZeroStatus","responseStatus","customerContext","context","hasBeenTraced","traceSampled","traceId","spanId","_gc","wasInPageStateDuringPeriod","FROZEN","statusCode","getHeaderValue","headers","key","normalizedKey","String","toLowerCase","get","Array","isArray","i","headerEntry","headerKey"],"sources":["../../../../src/domain/rumEventsCollection/resource/resourceCollection.js"],"sourcesContent":["import {\n getStatusGroup,\n UUID,\n extend,\n extend2Lev,\n relativeToClocks,\n urlParse,\n getQueryParamsFromUrl,\n replaceNumberCharByPath,\n RequestType,\n ResourceType,\n RumEventType,\n LifeCycleEventType,\n toServerDuration,\n createTaskQueue,\n addTelemetryError\n} from '@cloudcare/browser-core'\nimport { createRequestResourceEntryMatcher } from './matchRequestResourceEntry'\nimport {\n computePerformanceResourceDetails,\n computeResourceEntryDuration,\n computeResourceEntryType,\n computeResourceEntrySize,\n isResourceEntryRequestType,\n isResourceUrlLimit,\n isLongDataUrl,\n sanitizeDataUrl,\n computeResourceEntryDeliveryType,\n computeResourceEntryProtocol\n} from './resourceUtils'\nimport { PageState } from '../../contexts/pageStateHistory'\nimport {\n createPerformanceObservable,\n RumPerformanceEntryType\n} from '../../performanceObservable'\nimport { retrieveInitialDocumentResourceTiming } from './retrieveInitialDocumentResourceTiming'\nexport function startResourceCollection(\n lifeCycle,\n configuration,\n pageStateHistory,\n taskQueue,\n retrieveInitialDocumentResourceTimingImpl,\n resourceTrackerManager\n) {\n if (taskQueue === undefined) {\n taskQueue = createTaskQueue()\n }\n if (typeof retrieveInitialDocumentResourceTimingImpl === 'undefined') {\n retrieveInitialDocumentResourceTimingImpl =\n retrieveInitialDocumentResourceTiming\n }\n if (resourceTrackerManager) {\n resourceTrackerManager.setFlushTrackedResource(function (rawEvent) {\n lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, rawEvent)\n })\n }\n var requestResourceEntryMatcher = createRequestResourceEntryMatcher()\n lifeCycle.subscribe(LifeCycleEventType.REQUEST_COMPLETED, function (request) {\n handleResource(function () {\n return processRequest(request, pageStateHistory, requestResourceEntryMatcher)\n })\n })\n var performanceResourceSubscription = createPerformanceObservable(\n configuration,\n {\n type: RumPerformanceEntryType.RESOURCE,\n buffered: true\n }\n ).subscribe(function (entries) {\n var loop = function (entry) {\n if (\n !isResourceEntryRequestType(entry) &&\n !isResourceUrlLimit(entry.name, configuration.resourceUrlLimit)\n ) {\n handleResource(function () {\n return processResourceEntry(entry, configuration)\n })\n }\n }\n for (var _i = 0, entries_1 = entries; _i < entries_1.length; _i++) {\n var entry = entries_1[_i]\n loop(entry)\n }\n })\n\n retrieveInitialDocumentResourceTimingImpl(configuration, function (timing) {\n handleResource(function () {\n return processResourceEntry(timing, configuration)\n })\n })\n function handleResource(computeRawEvent) {\n taskQueue.push(function () {\n try {\n const rawEvent = computeRawEvent()\n if (rawEvent) {\n if (\n resourceTrackerManager &&\n rawEvent.domainContext &&\n rawEvent.domainContext.resourceTrackerId &&\n resourceTrackerManager.trackRequestResource(\n rawEvent.domainContext.resourceTrackerId,\n rawEvent\n )\n ) {\n return\n }\n lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, rawEvent)\n }\n } catch (error) {\n addTelemetryError(error)\n }\n })\n }\n return {\n stop: function () {\n performanceResourceSubscription.unsubscribe()\n },\n addResource: (resource, savedCommonContext) => {\n handleResource(function () {\n return extend(\n { savedCommonContext: savedCommonContext },\n processCustomResource(resource)\n )\n })\n }\n }\n}\n\nfunction processRequest(request, pageStateHistory, requestResourceEntryMatcher) {\n var matchingTiming = requestResourceEntryMatcher.matchRequestResourceEntry(request)\n var startClocks = matchingTiming\n ? relativeToClocks(matchingTiming.startTime)\n : request.startClocks\n var tracingInfo = computeRequestTracingInfo(request)\n\n var type =\n request.type === RequestType.XHR ? ResourceType.XHR : ResourceType.FETCH\n var correspondingTimingOverrides = matchingTiming\n ? computeResourceEntryMetrics(matchingTiming)\n : undefined\n\n var duration = computeRequestDuration(\n pageStateHistory,\n startClocks,\n request.duration\n )\n\n var urlObj = urlParse(request.url).getParse()\n var resourceEvent = extend2Lev(\n {\n date: startClocks.timeStamp,\n resource: {\n id: UUID(),\n type: type,\n duration: duration,\n method: request.method,\n status: request.status,\n statusGroup: getStatusGroup(request.status),\n url: isLongDataUrl(request.url)\n ? sanitizeDataUrl(request.url)\n : request.url,\n urlHost: urlObj.Host,\n urlPath: urlObj.Path,\n urlPathGroup: replaceNumberCharByPath(urlObj.Path),\n urlQuery: getQueryParamsFromUrl(request.url),\n deliveryType:\n matchingTiming && computeResourceEntryDeliveryType(matchingTiming),\n protocol: matchingTiming && computeResourceEntryProtocol(matchingTiming)\n },\n type: RumEventType.RESOURCE\n },\n tracingInfo,\n correspondingTimingOverrides\n )\n return {\n startTime: startClocks.relative,\n rawRumEvent: resourceEvent,\n domainContext: {\n performanceEntry: matchingTiming,\n xhr: request.xhr,\n requestHeaderContexts: request.requestHeaderContexts,\n response: request.response,\n requestInput: request.input,\n requestInit: request.init,\n error: request.error,\n isAborted: request.isAborted,\n handlingStack: request.handlingStack,\n resourceTrackerId: getResourceTrackerIdFromRequest(request)\n }\n }\n}\n\nfunction processResourceEntry(entry, configuration) {\n var startClocks = relativeToClocks(entry.startTime)\n var tracingInfo = computeResourceEntryTracingInfo(entry)\n var type = computeResourceEntryType(entry)\n var entryMetrics = computeResourceEntryMetrics(entry)\n var urlObj = urlParse(entry.name).getParse()\n var resourceEvent = extend2Lev(\n {\n date: startClocks.timeStamp,\n resource: {\n id: UUID(),\n type: type,\n url: entry.name,\n urlHost: urlObj.Host,\n urlPath: urlObj.Path,\n urlPathGroup: replaceNumberCharByPath(urlObj.Path),\n urlQuery: getQueryParamsFromUrl(entry.name),\n method: 'GET',\n status: discardZeroStatus(entry.responseStatus),\n statusGroup: getStatusGroup(entry.responseStatus),\n deliveryType: computeResourceEntryDeliveryType(entry),\n protocol: computeResourceEntryProtocol(entry)\n },\n type: RumEventType.RESOURCE\n },\n tracingInfo,\n entryMetrics\n )\n return {\n startTime: startClocks.relative,\n rawRumEvent: resourceEvent,\n domainContext: {\n performanceEntry: entry\n }\n }\n}\nfunction processCustomResource(resource) {\n var resourceEvent = {\n date: resource.startClocks.timeStamp,\n resource: {\n id: UUID(),\n type: resource.type\n },\n type: RumEventType.RESOURCE\n }\n return {\n customerContext: resource.context,\n startTime: resource.startClocks.relative,\n rawRumEvent: resourceEvent,\n domainContext: {\n resource: resource\n }\n }\n}\nfunction computeResourceEntryMetrics(entry) {\n return {\n resource: extend2Lev(\n {},\n {\n duration: computeResourceEntryDuration(entry)\n },\n computeResourceEntrySize(entry),\n computePerformanceResourceDetails(entry)\n )\n }\n}\n\nfunction computeRequestTracingInfo(request) {\n var hasBeenTraced = request.traceSampled && request.traceId && request.spanId\n if (!hasBeenTraced) {\n return undefined\n }\n return {\n _gc: {\n spanId: request.spanId,\n traceId: request.traceId\n },\n resource: { id: UUID() }\n }\n}\n\nfunction computeRequestDuration(pageStateHistory, startClocks, duration) {\n return !pageStateHistory.wasInPageStateDuringPeriod(\n PageState.FROZEN,\n startClocks.relative,\n duration\n )\n ? toServerDuration(duration)\n : undefined\n}\nfunction computeResourceEntryTracingInfo(entry) {\n return entry.traceId ? { _gc: { traceId: entry.traceId } } : undefined\n}\n/**\n * The status is 0 for cross-origin resources without CORS headers, so the status is meaningless, and we shouldn't report it\n * https://developer.mozilla.org/en-US/docs/Web/API/PerformanceResourceTiming/responseStatus#cross-origin_response_status_codes\n */\nfunction discardZeroStatus(statusCode) {\n return statusCode === 0 ? undefined : statusCode\n}\n\nfunction getResourceTrackerIdFromRequest(request) {\n return getHeaderValue(request.requestHeaderContexts, 'x-rum-resource-id')\n}\n\nfunction getHeaderValue(headers, key) {\n if (!headers || !key) {\n return undefined\n }\n\n var normalizedKey = String(key).toLowerCase()\n\n if (typeof headers.get === 'function') {\n return headers.get(key) || headers.get(normalizedKey) || undefined\n }\n\n if (Array.isArray(headers)) {\n for (var i = 0; i < headers.length; i += 1) {\n var headerEntry = headers[i]\n if (\n Array.isArray(headerEntry) &&\n String(headerEntry[0]).toLowerCase() === normalizedKey\n ) {\n return headerEntry[1]\n }\n }\n return undefined\n }\n\n for (var headerKey in headers) {\n if (String(headerKey).toLowerCase() === normalizedKey) {\n return headers[headerKey]\n }\n }\n}\n"],"mappings":"AAAA,SACEA,cAAc,EACdC,IAAI,EACJC,MAAM,EACNC,UAAU,EACVC,gBAAgB,EAChBC,QAAQ,EACRC,qBAAqB,EACrBC,uBAAuB,EACvBC,WAAW,EACXC,YAAY,EACZC,YAAY,EACZC,kBAAkB,EAClBC,gBAAgB,EAChBC,eAAe,EACfC,iBAAiB,QACZ,yBAAyB;AAChC,SAASC,iCAAiC,QAAQ,6BAA6B;AAC/E,SACEC,iCAAiC,EACjCC,4BAA4B,EAC5BC,wBAAwB,EACxBC,wBAAwB,EACxBC,0BAA0B,EAC1BC,kBAAkB,EAClBC,aAAa,EACbC,eAAe,EACfC,gCAAgC,EAChCC,4BAA4B,QACvB,iBAAiB;AACxB,SAASC,SAAS,QAAQ,iCAAiC;AAC3D,SACEC,2BAA2B,EAC3BC,uBAAu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OAAOxG,SAAS;EAClB;EAEA,KAAK,IAAIyG,SAAS,IAAIV,OAAO,EAAE;IAC7B,IAAIG,MAAM,CAACO,SAAS,CAAC,CAACN,WAAW,CAAC,CAAC,KAAKF,aAAa,EAAE;MACrD,OAAOF,OAAO,CAACU,SAAS,CAAC;IAC3B;EACF;AACF","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"resourceCollection.js","names":["getStatusGroup","UUID","extend","extend2Lev","relativeToClocks","urlParse","getQueryParamsFromUrl","replaceNumberCharByPath","RequestType","ResourceType","RumEventType","LifeCycleEventType","toServerDuration","createTaskQueue","addTelemetryError","createRequestResourceEntryMatcher","computePerformanceResourceDetails","computeResourceEntryDuration","computeResourceEntryType","computeResourceEntrySize","isResourceEntryRequestType","isResourceUrlLimit","isLongDataUrl","sanitizeDataUrl","computeResourceEntryDeliveryType","computeResourceEntryProtocol","PageState","createPerformanceObservable","RumPerformanceEntryType","retrieveInitialDocumentResourceTiming","startResourceCollection","lifeCycle","configuration","pageStateHistory","taskQueue","retrieveInitialDocumentResourceTimingImpl","resourceTrackerManager","undefined","setFlushTrackedResource","rawEvent","notify","RAW_RUM_EVENT_COLLECTED","requestResourceEntryMatcher","webSocketSubscription","subscribe","WEBSOCKET_COMPLETED","event","processWebSocket","error","REQUEST_COMPLETED","request","handleResource","processRequest","performanceResourceSubscription","type","RESOURCE","buffered","entries","loop","entry","name","resourceUrlLimit","processResourceEntry","_i","entries_1","length","timing","computeRawEvent","push","domainContext","resourceTrackerId","trackRequestResource","stop","unsubscribe","addResource","resource","savedCommonContext","processCustomResource","duration","endClocks","timeStamp","startClocks","urlObj","url","getParse","startTime","relative","rawRumEvent","date","id","WEBSOCKET","urlHost","Host","urlPath","Path","urlPathGroup","urlQuery","websocket","connectionId","handshakeSucceeded","endTime","startViewId","endViewId","trackingEndReason","closeCode","closeReason","wasClean","messagesIn","messagesOut","timeToFirstMessageIn","firstMessageInOffset","timeToFirstMessageOut","firstMessageOutOffset","lastMessageInAt","longestInboundSilence","inboundIdleDurationBeforeClose","bufferedAmountMax","protocol","setupDuration","isWebSocket","webSocket","matchingTiming","matchRequestResourceEntry","tracingInfo","computeRequestTracingInfo","XHR","FETCH","correspondingTimingOverrides","computeResourceEntryMetrics","computeRequestDuration","resourceEvent","method","status","statusGroup","deliveryType","performanceEntry","xhr","requestHeaderContexts","response","requestInput","input","requestInit","init","isAborted","handlingStack","getResourceTrackerIdFromRequest","computeResourceEntryTracingInfo","entryMetrics","discardZeroStatus","responseStatus","customerContext","context","hasBeenTraced","traceSampled","traceId","spanId","_gc","wasInPageStateDuringPeriod","FROZEN","statusCode","getHeaderValue","headers","key","normalizedKey","String","toLowerCase","get","Array","isArray","i","headerEntry","headerKey"],"sources":["../../../../src/domain/rumEventsCollection/resource/resourceCollection.js"],"sourcesContent":["import {\n getStatusGroup,\n UUID,\n extend,\n extend2Lev,\n relativeToClocks,\n urlParse,\n getQueryParamsFromUrl,\n replaceNumberCharByPath,\n RequestType,\n ResourceType,\n RumEventType,\n LifeCycleEventType,\n toServerDuration,\n createTaskQueue,\n addTelemetryError\n} from '@cloudcare/browser-core'\nimport { createRequestResourceEntryMatcher } from './matchRequestResourceEntry'\nimport {\n computePerformanceResourceDetails,\n computeResourceEntryDuration,\n computeResourceEntryType,\n computeResourceEntrySize,\n isResourceEntryRequestType,\n isResourceUrlLimit,\n isLongDataUrl,\n sanitizeDataUrl,\n computeResourceEntryDeliveryType,\n computeResourceEntryProtocol\n} from './resourceUtils'\nimport { PageState } from '../../contexts/pageStateHistory'\nimport {\n createPerformanceObservable,\n RumPerformanceEntryType\n} from '../../performanceObservable'\nimport { retrieveInitialDocumentResourceTiming } from './retrieveInitialDocumentResourceTiming'\nexport function startResourceCollection(\n lifeCycle,\n configuration,\n pageStateHistory,\n taskQueue,\n retrieveInitialDocumentResourceTimingImpl,\n resourceTrackerManager\n) {\n if (taskQueue === undefined) {\n taskQueue = createTaskQueue()\n }\n if (typeof retrieveInitialDocumentResourceTimingImpl === 'undefined') {\n retrieveInitialDocumentResourceTimingImpl =\n retrieveInitialDocumentResourceTiming\n }\n if (resourceTrackerManager) {\n resourceTrackerManager.setFlushTrackedResource(function (rawEvent) {\n lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, rawEvent)\n })\n }\n var requestResourceEntryMatcher = createRequestResourceEntryMatcher()\n var webSocketSubscription = lifeCycle.subscribe(\n LifeCycleEventType.WEBSOCKET_COMPLETED,\n function (event) {\n try {\n lifeCycle.notify(\n LifeCycleEventType.RAW_RUM_EVENT_COLLECTED,\n processWebSocket(event)\n )\n } catch (error) {\n addTelemetryError(error)\n }\n }\n )\n lifeCycle.subscribe(LifeCycleEventType.REQUEST_COMPLETED, function (request) {\n handleResource(function () {\n return processRequest(request, pageStateHistory, requestResourceEntryMatcher)\n })\n })\n var performanceResourceSubscription = createPerformanceObservable(\n configuration,\n {\n type: RumPerformanceEntryType.RESOURCE,\n buffered: true\n }\n ).subscribe(function (entries) {\n var loop = function (entry) {\n if (\n !isResourceEntryRequestType(entry) &&\n !isResourceUrlLimit(entry.name, configuration.resourceUrlLimit)\n ) {\n handleResource(function () {\n return processResourceEntry(entry, configuration)\n })\n }\n }\n for (var _i = 0, entries_1 = entries; _i < entries_1.length; _i++) {\n var entry = entries_1[_i]\n loop(entry)\n }\n })\n\n retrieveInitialDocumentResourceTimingImpl(configuration, function (timing) {\n handleResource(function () {\n return processResourceEntry(timing, configuration)\n })\n })\n function handleResource(computeRawEvent) {\n taskQueue.push(function () {\n try {\n const rawEvent = computeRawEvent()\n if (rawEvent) {\n if (\n resourceTrackerManager &&\n rawEvent.domainContext &&\n rawEvent.domainContext.resourceTrackerId &&\n resourceTrackerManager.trackRequestResource(\n rawEvent.domainContext.resourceTrackerId,\n rawEvent\n )\n ) {\n return\n }\n lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, rawEvent)\n }\n } catch (error) {\n addTelemetryError(error)\n }\n })\n }\n return {\n stop: function () {\n webSocketSubscription.unsubscribe()\n performanceResourceSubscription.unsubscribe()\n },\n addResource: (resource, savedCommonContext) => {\n handleResource(function () {\n return extend(\n { savedCommonContext: savedCommonContext },\n processCustomResource(resource)\n )\n })\n }\n }\n}\n\nexport function processWebSocket(event) {\n var duration = event.endClocks.timeStamp - event.startClocks.timeStamp\n var urlObj = urlParse(event.url).getParse()\n return {\n startTime: event.startClocks.relative,\n rawRumEvent: {\n date: event.startClocks.timeStamp,\n type: RumEventType.RESOURCE,\n resource: {\n id: UUID(),\n type: ResourceType.WEBSOCKET,\n url: event.url,\n urlHost: urlObj.Host,\n urlPath: urlObj.Path,\n urlPathGroup: replaceNumberCharByPath(urlObj.Path),\n urlQuery: getQueryParamsFromUrl(event.url),\n duration: toServerDuration(duration),\n websocket: {\n connectionId: event.connectionId,\n handshakeSucceeded: event.handshakeSucceeded,\n startTime: event.startClocks.timeStamp,\n endTime: event.endClocks.timeStamp,\n startViewId: event.startViewId,\n endViewId: event.endViewId,\n trackingEndReason: event.trackingEndReason,\n closeCode: event.closeCode,\n closeReason: event.closeReason,\n wasClean: event.wasClean,\n messagesIn: event.messagesIn,\n messagesOut: event.messagesOut,\n timeToFirstMessageIn: toServerDuration(\n event.firstMessageInOffset\n ),\n timeToFirstMessageOut: toServerDuration(\n event.firstMessageOutOffset\n ),\n lastMessageInAt: event.lastMessageInAt,\n longestInboundSilence: toServerDuration(\n event.longestInboundSilence\n ),\n inboundIdleDurationBeforeClose: toServerDuration(\n event.inboundIdleDurationBeforeClose\n ),\n bufferedAmountMax: event.bufferedAmountMax,\n protocol: event.protocol,\n setupDuration: toServerDuration(event.setupDuration)\n }\n }\n },\n domainContext: {\n isWebSocket: true,\n webSocket: event.webSocket\n }\n }\n}\n\nfunction processRequest(request, pageStateHistory, requestResourceEntryMatcher) {\n var matchingTiming = requestResourceEntryMatcher.matchRequestResourceEntry(request)\n var startClocks = matchingTiming\n ? relativeToClocks(matchingTiming.startTime)\n : request.startClocks\n var tracingInfo = computeRequestTracingInfo(request)\n\n var type =\n request.type === RequestType.XHR ? ResourceType.XHR : ResourceType.FETCH\n var correspondingTimingOverrides = matchingTiming\n ? computeResourceEntryMetrics(matchingTiming)\n : undefined\n\n var duration = computeRequestDuration(\n pageStateHistory,\n startClocks,\n request.duration\n )\n\n var urlObj = urlParse(request.url).getParse()\n var resourceEvent = extend2Lev(\n {\n date: startClocks.timeStamp,\n resource: {\n id: UUID(),\n type: type,\n duration: duration,\n method: request.method,\n status: request.status,\n statusGroup: getStatusGroup(request.status),\n url: isLongDataUrl(request.url)\n ? sanitizeDataUrl(request.url)\n : request.url,\n urlHost: urlObj.Host,\n urlPath: urlObj.Path,\n urlPathGroup: replaceNumberCharByPath(urlObj.Path),\n urlQuery: getQueryParamsFromUrl(request.url),\n deliveryType:\n matchingTiming && computeResourceEntryDeliveryType(matchingTiming),\n protocol: matchingTiming && computeResourceEntryProtocol(matchingTiming)\n },\n type: RumEventType.RESOURCE\n },\n tracingInfo,\n correspondingTimingOverrides\n )\n return {\n startTime: startClocks.relative,\n rawRumEvent: resourceEvent,\n domainContext: {\n performanceEntry: matchingTiming,\n xhr: request.xhr,\n requestHeaderContexts: request.requestHeaderContexts,\n response: request.response,\n requestInput: request.input,\n requestInit: request.init,\n error: request.error,\n isAborted: request.isAborted,\n handlingStack: request.handlingStack,\n resourceTrackerId: getResourceTrackerIdFromRequest(request)\n }\n }\n}\n\nfunction processResourceEntry(entry, configuration) {\n var startClocks = relativeToClocks(entry.startTime)\n var tracingInfo = computeResourceEntryTracingInfo(entry)\n var type = computeResourceEntryType(entry)\n var entryMetrics = computeResourceEntryMetrics(entry)\n var urlObj = urlParse(entry.name).getParse()\n var resourceEvent = extend2Lev(\n {\n date: startClocks.timeStamp,\n resource: {\n id: UUID(),\n type: type,\n url: entry.name,\n urlHost: urlObj.Host,\n urlPath: urlObj.Path,\n urlPathGroup: replaceNumberCharByPath(urlObj.Path),\n urlQuery: getQueryParamsFromUrl(entry.name),\n method: 'GET',\n status: discardZeroStatus(entry.responseStatus),\n statusGroup: getStatusGroup(entry.responseStatus),\n deliveryType: computeResourceEntryDeliveryType(entry),\n protocol: computeResourceEntryProtocol(entry)\n },\n type: RumEventType.RESOURCE\n },\n tracingInfo,\n entryMetrics\n )\n return {\n startTime: startClocks.relative,\n rawRumEvent: resourceEvent,\n domainContext: {\n performanceEntry: entry\n }\n }\n}\nfunction processCustomResource(resource) {\n var resourceEvent = {\n date: resource.startClocks.timeStamp,\n resource: {\n id: UUID(),\n type: resource.type\n },\n type: RumEventType.RESOURCE\n }\n return {\n customerContext: resource.context,\n startTime: resource.startClocks.relative,\n rawRumEvent: resourceEvent,\n domainContext: {\n resource: resource\n }\n }\n}\nfunction computeResourceEntryMetrics(entry) {\n return {\n resource: extend2Lev(\n {},\n {\n duration: computeResourceEntryDuration(entry)\n },\n computeResourceEntrySize(entry),\n computePerformanceResourceDetails(entry)\n )\n }\n}\n\nfunction computeRequestTracingInfo(request) {\n var hasBeenTraced = request.traceSampled && request.traceId && request.spanId\n if (!hasBeenTraced) {\n return undefined\n }\n return {\n _gc: {\n spanId: request.spanId,\n traceId: request.traceId\n },\n resource: { id: UUID() }\n }\n}\n\nfunction computeRequestDuration(pageStateHistory, startClocks, duration) {\n return !pageStateHistory.wasInPageStateDuringPeriod(\n PageState.FROZEN,\n startClocks.relative,\n duration\n )\n ? toServerDuration(duration)\n : undefined\n}\nfunction computeResourceEntryTracingInfo(entry) {\n return entry.traceId ? { _gc: { traceId: entry.traceId } } : undefined\n}\n/**\n * The status is 0 for cross-origin resources without CORS headers, so the status is meaningless, and we shouldn't report it\n * https://developer.mozilla.org/en-US/docs/Web/API/PerformanceResourceTiming/responseStatus#cross-origin_response_status_codes\n */\nfunction discardZeroStatus(statusCode) {\n return statusCode === 0 ? undefined : statusCode\n}\n\nfunction getResourceTrackerIdFromRequest(request) {\n return getHeaderValue(request.requestHeaderContexts, 'x-rum-resource-id')\n}\n\nfunction getHeaderValue(headers, key) {\n if (!headers || !key) {\n return undefined\n }\n\n var normalizedKey = String(key).toLowerCase()\n\n if (typeof headers.get === 'function') {\n return headers.get(key) || headers.get(normalizedKey) || undefined\n }\n\n if (Array.isArray(headers)) {\n for (var i = 0; i < headers.length; i += 1) {\n var headerEntry = headers[i]\n if (\n Array.isArray(headerEntry) &&\n String(headerEntry[0]).toLowerCase() === normalizedKey\n ) {\n return headerEntry[1]\n }\n }\n return undefined\n }\n\n for (var headerKey in headers) {\n if (String(headerKey).toLowerCase() === normalizedKey) {\n return headers[headerKey]\n }\n }\n}\n"],"mappings":"AAAA,SACEA,cAAc,EACdC,IAAI,EACJC,MAAM,EACNC,UAAU,EACVC,gBAAgB,EAChBC,QAAQ,EACRC,qBAAqB,EACrBC,uBAAuB,EACvBC,WAAW,EACXC,YAAY,EACZC,YAAY,EACZC,kBAAkB,EAClBC,gBAAgB,EAChBC,eAAe,EACfC,iBAAiB,QACZ,yBAAyB;AAChC,SAASC,iCAAiC,QAAQ,6BAA6B;AAC/E,SACEC,iCAAiC,EACjCC,4BAA4B,EAC5BC,wBAAwB,EACxBC,wBAAwB,EACxBC,0BAA0B,EAC1BC,kBAAkB,EAClBC,aAAa,EACbC,eAAe,EACfC,gCAAgC,EAChCC,4BAA4B,QACvB,iBAAiB;AACxB,SAASC,SAAS,QAAQ,iCAAiC;AAC3D,SACEC,2BAA2B,EAC3BC,uBAAuB,QAClB,6BAA6B;AACpC,SAASC,qCAAqC,QAAQ,yCAAyC;AAC/F,OAAO,SAASC,uBAAuBA,CACrCC,SAAS,EACTC,aAAa,EACbC,gBAAgB,EAChBC,SAAS,EACTC,yCAAyC,EACzCC,sBAAsB,EACtB;EACA,IAAIF,SAAS,KAAKG,SAAS,EAAE;IAC3BH,SAAS,GAAGrB,eAAe,CAAC,CAAC;EAC/B;EACA,IAAI,OAAOsB,yCAAyC,KAAK,WAAW,EAAE;IACpEA,yCAAyC,GACvCN,qCAAqC;EACzC;EACA,IAAIO,sBAAsB,EAAE;IAC1BA,sBAAsB,CAACE,uBAA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EAClB;EAEA,IAAI8H,aAAa,GAAGC,MAAM,CAACF,GAAG,CAAC,CAACG,WAAW,CAAC,CAAC;EAE7C,IAAI,OAAOJ,OAAO,CAACK,GAAG,KAAK,UAAU,EAAE;IACrC,OAAOL,OAAO,CAACK,GAAG,CAACJ,GAAG,CAAC,IAAID,OAAO,CAACK,GAAG,CAACH,aAAa,CAAC,IAAI9H,SAAS;EACpE;EAEA,IAAIkI,KAAK,CAACC,OAAO,CAACP,OAAO,CAAC,EAAE;IAC1B,KAAK,IAAIQ,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGR,OAAO,CAAChG,MAAM,EAAEwG,CAAC,IAAI,CAAC,EAAE;MAC1C,IAAIC,WAAW,GAAGT,OAAO,CAACQ,CAAC,CAAC;MAC5B,IACEF,KAAK,CAACC,OAAO,CAACE,WAAW,CAAC,IAC1BN,MAAM,CAACM,WAAW,CAAC,CAAC,CAAC,CAAC,CAACL,WAAW,CAAC,CAAC,KAAKF,aAAa,EACtD;QACA,OAAOO,WAAW,CAAC,CAAC,CAAC;MACvB;IACF;IACA,OAAOrI,SAAS;EAClB;EAEA,KAAK,IAAIsI,SAAS,IAAIV,OAAO,EAAE;IAC7B,IAAIG,MAAM,CAACO,SAAS,CAAC,CAACN,WAAW,CAAC,CAAC,KAAKF,aAAa,EAAE;MACrD,OAAOF,OAAO,CAACU,SAAS,CAAC;IAC3B;EACF;AACF","ignoreList":[]}
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
import { clocksNow, elapsed, initWebSocketObservable, LifeCycleEventType, PageExitReason, UUID } from '@cloudcare/browser-core';
|
|
2
|
+
export function startWebSocketCollection(lifeCycle, viewContexts, webSocketContextObservable) {
|
|
3
|
+
var tracker = trackWebSocket(lifeCycle, webSocketContextObservable || initWebSocketObservable(), viewContexts);
|
|
4
|
+
var sessionExpiredSubscription = lifeCycle.subscribe(LifeCycleEventType.SESSION_EXPIRED, function () {
|
|
5
|
+
tracker.flushOpenConnections('session_end', true);
|
|
6
|
+
});
|
|
7
|
+
var sessionRenewedSubscription = lifeCycle.subscribe(LifeCycleEventType.SESSION_RENEWED, function () {
|
|
8
|
+
tracker.resumeOpenConnections();
|
|
9
|
+
});
|
|
10
|
+
var pageExitSubscription = lifeCycle.subscribe(LifeCycleEventType.PAGE_EXITED, function (event) {
|
|
11
|
+
if (event.reason === PageExitReason.UNLOADING) {
|
|
12
|
+
tracker.flushOpenConnections('page_exit');
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
return {
|
|
16
|
+
stop: function stop() {
|
|
17
|
+
sessionExpiredSubscription.unsubscribe();
|
|
18
|
+
sessionRenewedSubscription.unsubscribe();
|
|
19
|
+
pageExitSubscription.unsubscribe();
|
|
20
|
+
tracker.flushOpenConnections('session_end');
|
|
21
|
+
tracker.stop();
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
export function trackWebSocket(lifeCycle, webSocketContextObservable, viewContexts) {
|
|
26
|
+
var registry = new Map();
|
|
27
|
+
var isWaitingForSessionRenewal = false;
|
|
28
|
+
var subscription = webSocketContextObservable.subscribe(function (context) {
|
|
29
|
+
var connection = registry.get(context.instance);
|
|
30
|
+
if (context.state === 'connecting') {
|
|
31
|
+
connection = createConnection(context.instance, context.url, context.startClocks, viewContexts);
|
|
32
|
+
connection.pendingSessionRenewal = isWaitingForSessionRenewal;
|
|
33
|
+
registry.set(context.instance, connection);
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
if (!connection) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
if (connection.pendingSessionRenewal) {
|
|
40
|
+
if (context.state === 'open') {
|
|
41
|
+
connection.openClocks = context.openClocks;
|
|
42
|
+
connection.protocol = context.protocol;
|
|
43
|
+
} else if (context.state === 'closed') {
|
|
44
|
+
registry["delete"](context.instance);
|
|
45
|
+
}
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
if (context.state === 'open') {
|
|
49
|
+
connection.openClocks = context.openClocks;
|
|
50
|
+
connection.protocol = context.protocol;
|
|
51
|
+
connection.setupDuration = elapsed(connection.startClocks.timeStamp, context.openClocks.timeStamp);
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
if (context.state === 'message-in') {
|
|
55
|
+
connection.messagesIn.count += 1;
|
|
56
|
+
connection.messagesIn.size += context.size;
|
|
57
|
+
recordMessageTiming(connection, context.at, 'in');
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
if (context.state === 'message-out') {
|
|
61
|
+
connection.messagesOut.count += 1;
|
|
62
|
+
connection.messagesOut.size += context.size;
|
|
63
|
+
connection.bufferedAmountMax = Math.max(connection.bufferedAmountMax, context.bufferedAmountPreSend);
|
|
64
|
+
recordMessageTiming(connection, context.at, 'out');
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
if (context.state === 'closed') {
|
|
68
|
+
registry["delete"](context.instance);
|
|
69
|
+
lifeCycle.notify(LifeCycleEventType.WEBSOCKET_COMPLETED, buildCompletedEvent(connection, context, 'close_event', viewContexts));
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
return {
|
|
73
|
+
flushOpenConnections: function flushOpenConnections(reason, preserveConnections) {
|
|
74
|
+
var at = clocksNow();
|
|
75
|
+
isWaitingForSessionRenewal = !!preserveConnections;
|
|
76
|
+
registry.forEach(function (connection) {
|
|
77
|
+
if (connection.pendingSessionRenewal) {
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
lifeCycle.notify(LifeCycleEventType.WEBSOCKET_COMPLETED, buildCompletedEvent(connection, {
|
|
81
|
+
at: at
|
|
82
|
+
}, reason, viewContexts));
|
|
83
|
+
if (preserveConnections) {
|
|
84
|
+
connection.pendingSessionRenewal = true;
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
if (!preserveConnections) {
|
|
88
|
+
registry.clear();
|
|
89
|
+
}
|
|
90
|
+
},
|
|
91
|
+
resumeOpenConnections: function resumeOpenConnections() {
|
|
92
|
+
var at = clocksNow();
|
|
93
|
+
isWaitingForSessionRenewal = false;
|
|
94
|
+
registry.forEach(function (connection) {
|
|
95
|
+
if (connection.pendingSessionRenewal) {
|
|
96
|
+
resetConnectionSegment(connection, at, viewContexts);
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
},
|
|
100
|
+
stop: function stop() {
|
|
101
|
+
subscription.unsubscribe();
|
|
102
|
+
registry.clear();
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
function createConnection(webSocket, url, startClocks, viewContexts) {
|
|
107
|
+
var connection = {
|
|
108
|
+
webSocket: webSocket,
|
|
109
|
+
connectionId: UUID(),
|
|
110
|
+
url: url
|
|
111
|
+
};
|
|
112
|
+
resetConnectionSegment(connection, startClocks, viewContexts);
|
|
113
|
+
return connection;
|
|
114
|
+
}
|
|
115
|
+
function resetConnectionSegment(connection, startClocks, viewContexts) {
|
|
116
|
+
var wasOpen = connection.openClocks !== undefined;
|
|
117
|
+
var startView = viewContexts.findView(startClocks.relative);
|
|
118
|
+
connection.startClocks = startClocks;
|
|
119
|
+
connection.startViewId = startView && startView.id;
|
|
120
|
+
connection.messagesIn = {
|
|
121
|
+
count: 0,
|
|
122
|
+
size: 0
|
|
123
|
+
};
|
|
124
|
+
connection.messagesOut = {
|
|
125
|
+
count: 0,
|
|
126
|
+
size: 0
|
|
127
|
+
};
|
|
128
|
+
connection.longestInboundSilence = 0;
|
|
129
|
+
connection.bufferedAmountMax = 0;
|
|
130
|
+
connection.pendingSessionRenewal = false;
|
|
131
|
+
delete connection.firstMessageInOffset;
|
|
132
|
+
delete connection.firstMessageOutOffset;
|
|
133
|
+
delete connection.lastMessageInAt;
|
|
134
|
+
if (wasOpen) {
|
|
135
|
+
connection.openClocks = startClocks;
|
|
136
|
+
connection.setupDuration = 0;
|
|
137
|
+
} else {
|
|
138
|
+
delete connection.openClocks;
|
|
139
|
+
delete connection.setupDuration;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
function recordMessageTiming(connection, at, direction) {
|
|
143
|
+
if (!connection.openClocks) {
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
var offset = elapsed(connection.openClocks.timeStamp, at.timeStamp);
|
|
147
|
+
if (direction === 'in' && connection.firstMessageInOffset === undefined) {
|
|
148
|
+
connection.firstMessageInOffset = offset;
|
|
149
|
+
} else if (direction === 'out' && connection.firstMessageOutOffset === undefined) {
|
|
150
|
+
connection.firstMessageOutOffset = offset;
|
|
151
|
+
}
|
|
152
|
+
if (direction === 'in') {
|
|
153
|
+
if (connection.lastMessageInAt !== undefined) {
|
|
154
|
+
connection.longestInboundSilence = Math.max(connection.longestInboundSilence, elapsed(connection.lastMessageInAt, at.timeStamp));
|
|
155
|
+
}
|
|
156
|
+
connection.lastMessageInAt = at.timeStamp;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
function buildCompletedEvent(connection, endInfo, trackingEndReason, viewContexts) {
|
|
160
|
+
var endClocks = endInfo.at;
|
|
161
|
+
var endView = viewContexts.findView(endClocks.relative, trackingEndReason === 'session_end' || trackingEndReason === 'page_exit' ? {
|
|
162
|
+
returnInactive: true
|
|
163
|
+
} : undefined);
|
|
164
|
+
return {
|
|
165
|
+
webSocket: connection.webSocket,
|
|
166
|
+
connectionId: connection.connectionId,
|
|
167
|
+
url: connection.url,
|
|
168
|
+
protocol: connection.protocol,
|
|
169
|
+
startClocks: connection.startClocks,
|
|
170
|
+
endClocks: endClocks,
|
|
171
|
+
startViewId: connection.startViewId,
|
|
172
|
+
endViewId: endView && endView.id,
|
|
173
|
+
messagesIn: connection.messagesIn,
|
|
174
|
+
messagesOut: connection.messagesOut,
|
|
175
|
+
firstMessageInOffset: connection.firstMessageInOffset,
|
|
176
|
+
firstMessageOutOffset: connection.firstMessageOutOffset,
|
|
177
|
+
lastMessageInAt: connection.lastMessageInAt,
|
|
178
|
+
longestInboundSilence: connection.longestInboundSilence,
|
|
179
|
+
bufferedAmountMax: connection.bufferedAmountMax,
|
|
180
|
+
inboundIdleDurationBeforeClose: connection.lastMessageInAt === undefined ? undefined : elapsed(connection.lastMessageInAt, endClocks.timeStamp),
|
|
181
|
+
closeCode: endInfo.code,
|
|
182
|
+
closeReason: endInfo.reason,
|
|
183
|
+
wasClean: endInfo.wasClean,
|
|
184
|
+
handshakeSucceeded: connection.openClocks !== undefined,
|
|
185
|
+
trackingEndReason: trackingEndReason,
|
|
186
|
+
setupDuration: connection.setupDuration === undefined ? elapsed(connection.startClocks.timeStamp, endClocks.timeStamp) : connection.setupDuration
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
//# sourceMappingURL=webSocketCollection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"webSocketCollection.js","names":["clocksNow","elapsed","initWebSocketObservable","LifeCycleEventType","PageExitReason","UUID","startWebSocketCollection","lifeCycle","viewContexts","webSocketContextObservable","tracker","trackWebSocket","sessionExpiredSubscription","subscribe","SESSION_EXPIRED","flushOpenConnections","sessionRenewedSubscription","SESSION_RENEWED","resumeOpenConnections","pageExitSubscription","PAGE_EXITED","event","reason","UNLOADING","stop","unsubscribe","registry","Map","isWaitingForSessionRenewal","subscription","context","connection","get","instance","state","createConnection","url","startClocks","pendingSessionRenewal","set","openClocks","protocol","setupDuration","timeStamp","messagesIn","count","size","recordMessageTiming","at","messagesOut","bufferedAmountMax","Math","max","bufferedAmountPreSend","notify","WEBSOCKET_COMPLETED","buildCompletedEvent","preserveConnections","forEach","clear","resetConnectionSegment","webSocket","connectionId","wasOpen","undefined","startView","findView","relative","startViewId","id","longestInboundSilence","firstMessageInOffset","firstMessageOutOffset","lastMessageInAt","direction","offset","endInfo","trackingEndReason","endClocks","endView","returnInactive","endViewId","inboundIdleDurationBeforeClose","closeCode","code","closeReason","wasClean","handshakeSucceeded"],"sources":["../../../../src/domain/rumEventsCollection/resource/webSocketCollection.js"],"sourcesContent":["import {\n clocksNow,\n elapsed,\n initWebSocketObservable,\n LifeCycleEventType,\n PageExitReason,\n UUID\n} from '@cloudcare/browser-core'\n\nexport function startWebSocketCollection(\n lifeCycle,\n viewContexts,\n webSocketContextObservable\n) {\n var tracker = trackWebSocket(\n lifeCycle,\n webSocketContextObservable || initWebSocketObservable(),\n viewContexts\n )\n var sessionExpiredSubscription = lifeCycle.subscribe(\n LifeCycleEventType.SESSION_EXPIRED,\n function () {\n tracker.flushOpenConnections('session_end', true)\n }\n )\n var sessionRenewedSubscription = lifeCycle.subscribe(\n LifeCycleEventType.SESSION_RENEWED,\n function () {\n tracker.resumeOpenConnections()\n }\n )\n var pageExitSubscription = lifeCycle.subscribe(\n LifeCycleEventType.PAGE_EXITED,\n function (event) {\n if (event.reason === PageExitReason.UNLOADING) {\n tracker.flushOpenConnections('page_exit')\n }\n }\n )\n\n return {\n stop: function () {\n sessionExpiredSubscription.unsubscribe()\n sessionRenewedSubscription.unsubscribe()\n pageExitSubscription.unsubscribe()\n tracker.flushOpenConnections('session_end')\n tracker.stop()\n }\n }\n}\n\nexport function trackWebSocket(\n lifeCycle,\n webSocketContextObservable,\n viewContexts\n) {\n var registry = new Map()\n var isWaitingForSessionRenewal = false\n var subscription = webSocketContextObservable.subscribe(function (context) {\n var connection = registry.get(context.instance)\n\n if (context.state === 'connecting') {\n connection = createConnection(\n context.instance,\n context.url,\n context.startClocks,\n viewContexts\n )\n connection.pendingSessionRenewal = isWaitingForSessionRenewal\n registry.set(context.instance, connection)\n return\n }\n\n if (!connection) {\n return\n }\n\n if (connection.pendingSessionRenewal) {\n if (context.state === 'open') {\n connection.openClocks = context.openClocks\n connection.protocol = context.protocol\n } else if (context.state === 'closed') {\n registry.delete(context.instance)\n }\n return\n }\n\n if (context.state === 'open') {\n connection.openClocks = context.openClocks\n connection.protocol = context.protocol\n connection.setupDuration = elapsed(\n connection.startClocks.timeStamp,\n context.openClocks.timeStamp\n )\n return\n }\n\n if (context.state === 'message-in') {\n connection.messagesIn.count += 1\n connection.messagesIn.size += context.size\n recordMessageTiming(connection, context.at, 'in')\n return\n }\n\n if (context.state === 'message-out') {\n connection.messagesOut.count += 1\n connection.messagesOut.size += context.size\n connection.bufferedAmountMax = Math.max(\n connection.bufferedAmountMax,\n context.bufferedAmountPreSend\n )\n recordMessageTiming(connection, context.at, 'out')\n return\n }\n\n if (context.state === 'closed') {\n registry.delete(context.instance)\n lifeCycle.notify(\n LifeCycleEventType.WEBSOCKET_COMPLETED,\n buildCompletedEvent(\n connection,\n context,\n 'close_event',\n viewContexts\n )\n )\n }\n })\n\n return {\n flushOpenConnections: function (reason, preserveConnections) {\n var at = clocksNow()\n isWaitingForSessionRenewal = !!preserveConnections\n registry.forEach(function (connection) {\n if (connection.pendingSessionRenewal) {\n return\n }\n lifeCycle.notify(\n LifeCycleEventType.WEBSOCKET_COMPLETED,\n buildCompletedEvent(connection, { at: at }, reason, viewContexts)\n )\n if (preserveConnections) {\n connection.pendingSessionRenewal = true\n }\n })\n if (!preserveConnections) {\n registry.clear()\n }\n },\n resumeOpenConnections: function () {\n var at = clocksNow()\n isWaitingForSessionRenewal = false\n registry.forEach(function (connection) {\n if (connection.pendingSessionRenewal) {\n resetConnectionSegment(connection, at, viewContexts)\n }\n })\n },\n stop: function () {\n subscription.unsubscribe()\n registry.clear()\n }\n }\n}\n\nfunction createConnection(webSocket, url, startClocks, viewContexts) {\n var connection = {\n webSocket: webSocket,\n connectionId: UUID(),\n url: url\n }\n resetConnectionSegment(connection, startClocks, viewContexts)\n return connection\n}\n\nfunction resetConnectionSegment(connection, startClocks, viewContexts) {\n var wasOpen = connection.openClocks !== undefined\n var startView = viewContexts.findView(startClocks.relative)\n\n connection.startClocks = startClocks\n connection.startViewId = startView && startView.id\n connection.messagesIn = { count: 0, size: 0 }\n connection.messagesOut = { count: 0, size: 0 }\n connection.longestInboundSilence = 0\n connection.bufferedAmountMax = 0\n connection.pendingSessionRenewal = false\n\n delete connection.firstMessageInOffset\n delete connection.firstMessageOutOffset\n delete connection.lastMessageInAt\n\n if (wasOpen) {\n connection.openClocks = startClocks\n connection.setupDuration = 0\n } else {\n delete connection.openClocks\n delete connection.setupDuration\n }\n}\n\nfunction recordMessageTiming(connection, at, direction) {\n if (!connection.openClocks) {\n return\n }\n\n var offset = elapsed(connection.openClocks.timeStamp, at.timeStamp)\n if (direction === 'in' && connection.firstMessageInOffset === undefined) {\n connection.firstMessageInOffset = offset\n } else if (\n direction === 'out' &&\n connection.firstMessageOutOffset === undefined\n ) {\n connection.firstMessageOutOffset = offset\n }\n\n if (direction === 'in') {\n if (connection.lastMessageInAt !== undefined) {\n connection.longestInboundSilence = Math.max(\n connection.longestInboundSilence,\n elapsed(connection.lastMessageInAt, at.timeStamp)\n )\n }\n connection.lastMessageInAt = at.timeStamp\n }\n}\n\nfunction buildCompletedEvent(\n connection,\n endInfo,\n trackingEndReason,\n viewContexts\n) {\n var endClocks = endInfo.at\n var endView = viewContexts.findView(\n endClocks.relative,\n trackingEndReason === 'session_end' || trackingEndReason === 'page_exit'\n ? { returnInactive: true }\n : undefined\n )\n\n return {\n webSocket: connection.webSocket,\n connectionId: connection.connectionId,\n url: connection.url,\n protocol: connection.protocol,\n startClocks: connection.startClocks,\n endClocks: endClocks,\n startViewId: connection.startViewId,\n endViewId: endView && endView.id,\n messagesIn: connection.messagesIn,\n messagesOut: connection.messagesOut,\n firstMessageInOffset: connection.firstMessageInOffset,\n firstMessageOutOffset: connection.firstMessageOutOffset,\n lastMessageInAt: connection.lastMessageInAt,\n longestInboundSilence: connection.longestInboundSilence,\n bufferedAmountMax: connection.bufferedAmountMax,\n inboundIdleDurationBeforeClose:\n connection.lastMessageInAt === undefined\n ? undefined\n : elapsed(connection.lastMessageInAt, endClocks.timeStamp),\n closeCode: endInfo.code,\n closeReason: endInfo.reason,\n wasClean: endInfo.wasClean,\n handshakeSucceeded: connection.openClocks !== undefined,\n trackingEndReason: trackingEndReason,\n setupDuration:\n connection.setupDuration === undefined\n ? elapsed(connection.startClocks.timeStamp, endClocks.timeStamp)\n : connection.setup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B,iBAAiB;IAC/CgC,8BAA8B,EAC5BnD,UAAU,CAAC0C,eAAe,KAAKT,SAAS,GACpCA,SAAS,GACT/D,OAAO,CAAC8B,UAAU,CAAC0C,eAAe,EAAEK,SAAS,CAACnC,SAAS,CAAC;IAC9DwC,SAAS,EAAEP,OAAO,CAACQ,IAAI;IACvBC,WAAW,EAAET,OAAO,CAACtD,MAAM;IAC3BgE,QAAQ,EAAEV,OAAO,CAACU,QAAQ;IAC1BC,kBAAkB,EAAExD,UAAU,CAACS,UAAU,KAAKwB,SAAS;IACvDa,iBAAiB,EAAEA,iBAAiB;IACpCnC,aAAa,EACXX,UAAU,CAACW,aAAa,KAAKsB,SAAS,GAClC/D,OAAO,CAAC8B,UAAU,CAACM,WAAW,CAACM,SAAS,EAAEmC,SAAS,CAACnC,SAAS,CAAC,GAC9DZ,UAAU,CAACW;EACnB,CAAC;AACH","ignoreList":[]}
|
|
@@ -8,10 +8,15 @@ export function trackLoadingTime(lifeCycle, domMutationObservable, configuration
|
|
|
8
8
|
var firstHidden = trackFirstHidden(viewStart);
|
|
9
9
|
function invokeCallbackIfAllCandidatesAreReceived() {
|
|
10
10
|
if (!isWaitingForActivityLoadingTime && !isWaitingForLoadEvent && loadingTimeCandidates.length > 0) {
|
|
11
|
-
var
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
var firstHiddenTime = firstHidden.getTimeStamp() - viewStart.relative;
|
|
12
|
+
var visibleLoadingTimeCandidates = loadingTimeCandidates.filter(function (loadingTime) {
|
|
13
|
+
return loadingTime < firstHiddenTime;
|
|
14
|
+
});
|
|
15
|
+
if (visibleLoadingTimeCandidates.length === 0) {
|
|
16
|
+
return;
|
|
14
17
|
}
|
|
18
|
+
var loadingTime = Math.max.apply(Math, visibleLoadingTimeCandidates);
|
|
19
|
+
callback(loadingTime);
|
|
15
20
|
}
|
|
16
21
|
}
|
|
17
22
|
var _waitPageActivityEnd = waitPageActivityEnd(lifeCycle, domMutationObservable, configuration, function (event) {
|