@cloudcare/browser-core 3.0.23 → 3.0.29
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/cjs/browser/addEventListener.js +9 -7
- package/cjs/browser/fetchObservable.js +5 -3
- package/cjs/console/consoleObservable.js +5 -1
- package/cjs/helper/errorTools.js +7 -3
- package/cjs/helper/instrumentMethod.js +4 -2
- package/cjs/helper/monitor.js +59 -0
- package/cjs/helper/readBytesFromStream.js +5 -3
- package/cjs/helper/timer.js +4 -2
- package/cjs/helper/tools.js +2 -20
- package/cjs/index.js +13 -0
- package/cjs/init.js +13 -19
- package/cjs/report/reportObservable.js +4 -3
- package/cjs/transport/batch.js +2 -2
- package/cjs/transport/httpRequest.js +5 -3
- package/esm/browser/addEventListener.js +8 -7
- package/esm/browser/fetchObservable.js +4 -3
- package/esm/console/consoleObservable.js +4 -1
- package/esm/helper/errorTools.js +6 -3
- package/esm/helper/instrumentMethod.js +3 -2
- package/esm/helper/monitor.js +40 -0
- package/esm/helper/readBytesFromStream.js +4 -3
- package/esm/helper/timer.js +3 -2
- package/esm/helper/tools.js +2 -18
- package/esm/index.js +1 -0
- package/esm/init.js +12 -18
- package/esm/report/reportObservable.js +3 -3
- package/esm/transport/batch.js +2 -2
- package/esm/transport/httpRequest.js +4 -3
- package/package.json +2 -2
- package/src/browser/addEventListener.js +8 -7
- package/src/browser/fetchObservable.js +12 -3
- package/src/console/consoleObservable.js +4 -2
- package/src/helper/errorTools.js +6 -5
- package/src/helper/instrumentMethod.js +5 -2
- package/src/helper/monitor.js +44 -0
- package/src/helper/observable.js +10 -8
- package/src/helper/readBytesFromStream.js +5 -5
- package/src/helper/timer.js +3 -3
- package/src/helper/tools.js +1 -17
- package/src/index.js +1 -0
- package/src/init.js +19 -21
- package/src/report/reportObservable.js +3 -2
- package/src/transport/batch.js +4 -4
- package/src/transport/httpRequest.js +5 -4
|
@@ -10,6 +10,8 @@ var _tools = require("../helper/tools");
|
|
|
10
10
|
|
|
11
11
|
var _getZoneJsOriginalValue = require("../helper/getZoneJsOriginalValue");
|
|
12
12
|
|
|
13
|
+
var _monitor = require("../helper/monitor");
|
|
14
|
+
|
|
13
15
|
function addEventListener(eventTarget, event, listener, options) {
|
|
14
16
|
return addEventListeners(eventTarget, [event], listener, options);
|
|
15
17
|
}
|
|
@@ -30,24 +32,24 @@ function addEventListener(eventTarget, event, listener, options) {
|
|
|
30
32
|
*/
|
|
31
33
|
|
|
32
34
|
|
|
33
|
-
function addEventListeners(eventTarget,
|
|
34
|
-
var wrappedListener = options && options.once ? function (event) {
|
|
35
|
+
function addEventListeners(eventTarget, eventNames, listener, options) {
|
|
36
|
+
var wrappedListener = (0, _monitor.monitor)(options && options.once ? function (event) {
|
|
35
37
|
stop();
|
|
36
38
|
listener(event);
|
|
37
|
-
} : listener;
|
|
39
|
+
} : listener);
|
|
38
40
|
options = options && options.passive ? {
|
|
39
41
|
capture: options.capture,
|
|
40
42
|
passive: options.passive
|
|
41
43
|
} : options && options.capture;
|
|
42
44
|
var add = (0, _getZoneJsOriginalValue.getZoneJsOriginalValue)(eventTarget, 'addEventListener');
|
|
43
|
-
(0, _tools.each)(
|
|
44
|
-
add.call(eventTarget,
|
|
45
|
+
(0, _tools.each)(eventNames, function (eventName) {
|
|
46
|
+
add.call(eventTarget, eventName, wrappedListener, options);
|
|
45
47
|
});
|
|
46
48
|
|
|
47
49
|
var stop = function stop() {
|
|
48
50
|
var remove = (0, _getZoneJsOriginalValue.getZoneJsOriginalValue)(eventTarget, 'removeEventListener');
|
|
49
|
-
(0, _tools.each)(
|
|
50
|
-
remove.call(eventTarget,
|
|
51
|
+
(0, _tools.each)(eventNames, function (eventName) {
|
|
52
|
+
remove.call(eventTarget, eventName, wrappedListener, options);
|
|
51
53
|
});
|
|
52
54
|
};
|
|
53
55
|
|
|
@@ -11,6 +11,8 @@ var _observable = require("../helper/observable");
|
|
|
11
11
|
|
|
12
12
|
var _tools = require("../helper/tools");
|
|
13
13
|
|
|
14
|
+
var _monitor = require("../helper/monitor");
|
|
15
|
+
|
|
14
16
|
var _urlPolyfill = require("../helper/urlPolyfill");
|
|
15
17
|
|
|
16
18
|
var fetchObservable;
|
|
@@ -32,11 +34,11 @@ function createFetchObservable() {
|
|
|
32
34
|
var fetchMethod = (0, _instrumentMethod.instrumentMethod)(window, 'fetch', function (originalFetch) {
|
|
33
35
|
return function (input, init) {
|
|
34
36
|
var responsePromise;
|
|
35
|
-
var context = beforeSend
|
|
37
|
+
var context = (0, _monitor.callMonitored)(beforeSend, null, [observable, input, init]);
|
|
36
38
|
|
|
37
39
|
if (context) {
|
|
38
40
|
responsePromise = originalFetch.call(this, context.input, context.init);
|
|
39
|
-
afterSend
|
|
41
|
+
(0, _monitor.callMonitored)(afterSend, null, [observable, responsePromise, context]);
|
|
40
42
|
} else {
|
|
41
43
|
responsePromise = originalFetch.call(this, input, init);
|
|
42
44
|
}
|
|
@@ -90,5 +92,5 @@ function afterSend(observable, responsePromise, startContext) {
|
|
|
90
92
|
observable.notify(context);
|
|
91
93
|
};
|
|
92
94
|
|
|
93
|
-
responsePromise.then(reportFetch, reportFetch);
|
|
95
|
+
responsePromise.then((0, _monitor.monitor)(reportFetch), (0, _monitor.monitor)(reportFetch));
|
|
94
96
|
}
|
|
@@ -17,6 +17,8 @@ var _jsonStringify = require("../helper/serialisation/jsonStringify");
|
|
|
17
17
|
|
|
18
18
|
var _display = require("../helper/display");
|
|
19
19
|
|
|
20
|
+
var _monitor = require("../helper/monitor");
|
|
21
|
+
|
|
20
22
|
var consoleObservablesByApi = {};
|
|
21
23
|
|
|
22
24
|
function initConsoleObservable(apis) {
|
|
@@ -40,7 +42,9 @@ function createConsoleObservable(api) {
|
|
|
40
42
|
var params = [].slice.call(arguments);
|
|
41
43
|
originalConsoleApi.apply(console, arguments);
|
|
42
44
|
var handlingStack = (0, _errorTools.createHandlingStack)();
|
|
43
|
-
|
|
45
|
+
(0, _monitor.callMonitored)(function () {
|
|
46
|
+
observable.notify(buildConsoleLog(params, api, handlingStack));
|
|
47
|
+
});
|
|
44
48
|
};
|
|
45
49
|
|
|
46
50
|
return function () {
|
package/cjs/helper/errorTools.js
CHANGED
|
@@ -18,6 +18,8 @@ var _jsonStringify = require("../helper/serialisation/jsonStringify");
|
|
|
18
18
|
|
|
19
19
|
var _tracekit = require("../tracekit");
|
|
20
20
|
|
|
21
|
+
var _monitor = require("../helper/monitor");
|
|
22
|
+
|
|
21
23
|
var ErrorSource = {
|
|
22
24
|
AGENT: 'agent',
|
|
23
25
|
CONSOLE: 'console',
|
|
@@ -108,9 +110,11 @@ function createHandlingStack() {
|
|
|
108
110
|
}
|
|
109
111
|
}
|
|
110
112
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
113
|
+
(0, _monitor.callMonitored)(function () {
|
|
114
|
+
var stackTrace = (0, _tracekit.computeStackTrace)(error);
|
|
115
|
+
stackTrace.stack = stackTrace.stack.slice(internalFramesToSkip);
|
|
116
|
+
formattedStack = toStackTraceString(stackTrace);
|
|
117
|
+
});
|
|
114
118
|
return formattedStack;
|
|
115
119
|
}
|
|
116
120
|
|
|
@@ -11,6 +11,8 @@ var _tools = require("./tools");
|
|
|
11
11
|
|
|
12
12
|
var _timer = require("./timer");
|
|
13
13
|
|
|
14
|
+
var _monitor = require("./monitor");
|
|
15
|
+
|
|
14
16
|
function instrumentMethod(object, method, instrumentationFactory) {
|
|
15
17
|
var original = object[method];
|
|
16
18
|
var instrumentation = instrumentationFactory(original);
|
|
@@ -42,7 +44,7 @@ function instrumentMethodAndCallOriginal(object, method, aliasOption) {
|
|
|
42
44
|
var result;
|
|
43
45
|
|
|
44
46
|
if (aliasOption && aliasOption.before) {
|
|
45
|
-
aliasOption.before.apply(this, arguments)
|
|
47
|
+
(0, _monitor.callMonitored)(aliasOption.before, this, arguments); // aliasOption.before.apply(this, arguments)
|
|
46
48
|
}
|
|
47
49
|
|
|
48
50
|
if (typeof original === 'function') {
|
|
@@ -51,7 +53,7 @@ function instrumentMethodAndCallOriginal(object, method, aliasOption) {
|
|
|
51
53
|
}
|
|
52
54
|
|
|
53
55
|
if (aliasOption && aliasOption.after) {
|
|
54
|
-
aliasOption.after.apply(this, arguments)
|
|
56
|
+
(0, _monitor.callMonitored)(aliasOption.after, this, arguments); // aliasOption.after.apply(this, arguments)
|
|
55
57
|
}
|
|
56
58
|
|
|
57
59
|
return result;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.callMonitored = callMonitored;
|
|
7
|
+
exports.displayIfDebugEnabled = displayIfDebugEnabled;
|
|
8
|
+
exports.monitor = monitor;
|
|
9
|
+
exports.resetMonitor = resetMonitor;
|
|
10
|
+
exports.setDebugMode = setDebugMode;
|
|
11
|
+
exports.startMonitorErrorCollection = startMonitorErrorCollection;
|
|
12
|
+
|
|
13
|
+
var _display = require("./display");
|
|
14
|
+
|
|
15
|
+
var onMonitorErrorCollected;
|
|
16
|
+
var debugMode = false;
|
|
17
|
+
|
|
18
|
+
function startMonitorErrorCollection(newOnMonitorErrorCollected) {
|
|
19
|
+
onMonitorErrorCollected = newOnMonitorErrorCollected;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function setDebugMode(newDebugMode) {
|
|
23
|
+
debugMode = newDebugMode;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function resetMonitor() {
|
|
27
|
+
onMonitorErrorCollected = undefined;
|
|
28
|
+
debugMode = false;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function monitor(fn) {
|
|
32
|
+
return function () {
|
|
33
|
+
return callMonitored(fn, this, arguments);
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function callMonitored(fn, context, args) {
|
|
38
|
+
try {
|
|
39
|
+
return fn.apply(context, args);
|
|
40
|
+
} catch (e) {
|
|
41
|
+
displayIfDebugEnabled(_display.ConsoleApiName.error, e);
|
|
42
|
+
|
|
43
|
+
if (onMonitorErrorCollected) {
|
|
44
|
+
try {
|
|
45
|
+
onMonitorErrorCollected(e);
|
|
46
|
+
} catch (e) {
|
|
47
|
+
displayIfDebugEnabled(_display.ConsoleApiName.error, e);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function displayIfDebugEnabled(api) {
|
|
54
|
+
var args = [].slice.call(arguments, 1);
|
|
55
|
+
|
|
56
|
+
if (debugMode) {
|
|
57
|
+
_display.display.apply(null, [api, '[MONITOR]'].concat(args));
|
|
58
|
+
}
|
|
59
|
+
}
|
|
@@ -7,6 +7,8 @@ exports.readBytesFromStream = readBytesFromStream;
|
|
|
7
7
|
|
|
8
8
|
var _tools = require("./tools");
|
|
9
9
|
|
|
10
|
+
var _monitor = require("./monitor");
|
|
11
|
+
|
|
10
12
|
/**
|
|
11
13
|
* Read bytes from a ReadableStream until at least `limit` bytes have been read (or until the end of
|
|
12
14
|
* the stream). The callback is invoked with the at most `limit` bytes, and indicates that the limit
|
|
@@ -19,7 +21,7 @@ function readBytesFromStream(stream, callback, options) {
|
|
|
19
21
|
readMore();
|
|
20
22
|
|
|
21
23
|
function readMore() {
|
|
22
|
-
reader.read().then(function (result) {
|
|
24
|
+
reader.read().then((0, _monitor.monitor)(function (result) {
|
|
23
25
|
if (result.done) {
|
|
24
26
|
onDone();
|
|
25
27
|
return;
|
|
@@ -36,9 +38,9 @@ function readBytesFromStream(stream, callback, options) {
|
|
|
36
38
|
} else {
|
|
37
39
|
readMore();
|
|
38
40
|
}
|
|
39
|
-
}, function (error) {
|
|
41
|
+
}), (0, _monitor.monitor)(function (error) {
|
|
40
42
|
callback(error);
|
|
41
|
-
});
|
|
43
|
+
}));
|
|
42
44
|
}
|
|
43
45
|
|
|
44
46
|
function onDone() {
|
package/cjs/helper/timer.js
CHANGED
|
@@ -12,8 +12,10 @@ var _getZoneJsOriginalValue = require("./getZoneJsOriginalValue");
|
|
|
12
12
|
|
|
13
13
|
var _init = require("../init");
|
|
14
14
|
|
|
15
|
+
var _monitor = require("./monitor");
|
|
16
|
+
|
|
15
17
|
function setTimeout(callback, delay) {
|
|
16
|
-
return (0, _getZoneJsOriginalValue.getZoneJsOriginalValue)((0, _init.getGlobalObject)(), 'setTimeout')(callback, delay);
|
|
18
|
+
return (0, _getZoneJsOriginalValue.getZoneJsOriginalValue)((0, _init.getGlobalObject)(), 'setTimeout')((0, _monitor.monitor)(callback), delay);
|
|
17
19
|
}
|
|
18
20
|
|
|
19
21
|
function clearTimeout(timeoutId) {
|
|
@@ -21,7 +23,7 @@ function clearTimeout(timeoutId) {
|
|
|
21
23
|
}
|
|
22
24
|
|
|
23
25
|
function setInterval(callback, delay) {
|
|
24
|
-
return (0, _getZoneJsOriginalValue.getZoneJsOriginalValue)(window, 'setInterval')(callback, delay);
|
|
26
|
+
return (0, _getZoneJsOriginalValue.getZoneJsOriginalValue)(window, 'setInterval')((0, _monitor.monitor)(callback), delay);
|
|
25
27
|
}
|
|
26
28
|
|
|
27
29
|
function clearInterval(timeoutId) {
|
package/cjs/helper/tools.js
CHANGED
|
@@ -69,7 +69,6 @@ exports.preferredTimeStamp = preferredTimeStamp;
|
|
|
69
69
|
exports.relativeNow = relativeNow;
|
|
70
70
|
exports.relativeToClocks = relativeToClocks;
|
|
71
71
|
exports.replaceNumberCharByPath = replaceNumberCharByPath;
|
|
72
|
-
exports.requestIdleCallback = requestIdleCallback;
|
|
73
72
|
exports.round = round;
|
|
74
73
|
exports.safeJSONParse = void 0;
|
|
75
74
|
exports.safeTruncate = safeTruncate;
|
|
@@ -408,6 +407,8 @@ var matchList = function matchList(list, value, useStartsWith) {
|
|
|
408
407
|
exports.matchList = matchList;
|
|
409
408
|
|
|
410
409
|
var cssEscape = function cssEscape(str) {
|
|
410
|
+
str = str + '';
|
|
411
|
+
|
|
411
412
|
if (window.CSS && window.CSS.escape) {
|
|
412
413
|
return window.CSS.escape(str);
|
|
413
414
|
} // eslint-disable-next-line no-control-regex
|
|
@@ -2008,25 +2009,6 @@ function isNullUndefinedDefaultValue(data, defaultValue) {
|
|
|
2008
2009
|
}
|
|
2009
2010
|
}
|
|
2010
2011
|
|
|
2011
|
-
function requestIdleCallback(callback, opts) {
|
|
2012
|
-
// Use 'requestIdleCallback' when available: it will throttle the mutation processing if the
|
|
2013
|
-
// browser is busy rendering frames (ex: when frames are below 60fps). When not available, the
|
|
2014
|
-
// fallback on 'requestAnimationFrame' will still ensure the mutations are processed after any
|
|
2015
|
-
// browser rendering process (Layout, Recalculate Style, etc.), so we can serialize DOM nodes
|
|
2016
|
-
// efficiently.
|
|
2017
|
-
if (window.requestIdleCallback) {
|
|
2018
|
-
var id = window.requestIdleCallback(callback, opts);
|
|
2019
|
-
return function () {
|
|
2020
|
-
return window.cancelIdleCallback(id);
|
|
2021
|
-
};
|
|
2022
|
-
}
|
|
2023
|
-
|
|
2024
|
-
var id = window.requestAnimationFrame(callback);
|
|
2025
|
-
return function () {
|
|
2026
|
-
return window.cancelAnimationFrame(id);
|
|
2027
|
-
};
|
|
2028
|
-
}
|
|
2029
|
-
|
|
2030
2012
|
function objectHasValue(object, value) {
|
|
2031
2013
|
return some(keys(object), function (key) {
|
|
2032
2014
|
return object[key] === value;
|
package/cjs/index.js
CHANGED
|
@@ -147,6 +147,19 @@ Object.keys(_display).forEach(function (key) {
|
|
|
147
147
|
});
|
|
148
148
|
});
|
|
149
149
|
|
|
150
|
+
var _monitor = require("./helper/monitor");
|
|
151
|
+
|
|
152
|
+
Object.keys(_monitor).forEach(function (key) {
|
|
153
|
+
if (key === "default" || key === "__esModule") return;
|
|
154
|
+
if (key in exports && exports[key] === _monitor[key]) return;
|
|
155
|
+
Object.defineProperty(exports, key, {
|
|
156
|
+
enumerable: true,
|
|
157
|
+
get: function get() {
|
|
158
|
+
return _monitor[key];
|
|
159
|
+
}
|
|
160
|
+
});
|
|
161
|
+
});
|
|
162
|
+
|
|
150
163
|
var _sanitize = require("./helper/sanitize");
|
|
151
164
|
|
|
152
165
|
Object.keys(_sanitize).forEach(function (key) {
|
package/cjs/init.js
CHANGED
|
@@ -5,36 +5,30 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.defineGlobal = defineGlobal;
|
|
7
7
|
exports.getGlobalObject = getGlobalObject;
|
|
8
|
-
exports.makeGlobal = makeGlobal;
|
|
9
8
|
exports.makePublicApi = makePublicApi;
|
|
10
9
|
|
|
11
10
|
var _tools = require("./helper/tools");
|
|
12
11
|
|
|
13
|
-
|
|
12
|
+
var _monitor = require("./helper/monitor");
|
|
14
13
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
callback();
|
|
19
|
-
}
|
|
20
|
-
});
|
|
21
|
-
return global;
|
|
22
|
-
}
|
|
14
|
+
var _catchUserErrors = require("./helper/catchUserErrors");
|
|
15
|
+
|
|
16
|
+
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
|
23
17
|
|
|
24
18
|
function makePublicApi(stub) {
|
|
25
|
-
var publicApi = (0, _tools.
|
|
19
|
+
var publicApi = (0, _tools.assign)({
|
|
26
20
|
onReady: function onReady(callback) {
|
|
27
21
|
callback();
|
|
28
22
|
}
|
|
29
|
-
}); // Add an "hidden" property to set debug mode. We define it that way to hide it
|
|
23
|
+
}, stub); // Add an "hidden" property to set debug mode. We define it that way to hide it
|
|
30
24
|
// as much as possible but of course it's not a real protection.
|
|
31
|
-
// Object.defineProperty(publicApi, '_setDebug', {
|
|
32
|
-
// get: function () {
|
|
33
|
-
// return setDebugMode
|
|
34
|
-
// },
|
|
35
|
-
// enumerable: false
|
|
36
|
-
// })
|
|
37
25
|
|
|
26
|
+
Object.defineProperty(publicApi, '_setDebug', {
|
|
27
|
+
get: function get() {
|
|
28
|
+
return _monitor.setDebugMode;
|
|
29
|
+
},
|
|
30
|
+
enumerable: false
|
|
31
|
+
});
|
|
38
32
|
return publicApi;
|
|
39
33
|
}
|
|
40
34
|
|
|
@@ -44,7 +38,7 @@ function defineGlobal(global, name, api) {
|
|
|
44
38
|
|
|
45
39
|
if (existingGlobalVariable && existingGlobalVariable.q) {
|
|
46
40
|
(0, _tools.each)(existingGlobalVariable.q, function (fn) {
|
|
47
|
-
fn();
|
|
41
|
+
(0, _catchUserErrors.catchUserErrors)(fn, 'onReady callback threw an error:')();
|
|
48
42
|
});
|
|
49
43
|
}
|
|
50
44
|
}
|
|
@@ -16,6 +16,8 @@ var _addEventListener2 = require("../browser/addEventListener");
|
|
|
16
16
|
|
|
17
17
|
var _enums = require("../helper/enums");
|
|
18
18
|
|
|
19
|
+
var _monitor = require("../helper/monitor");
|
|
20
|
+
|
|
19
21
|
var RawReportType = {
|
|
20
22
|
intervention: 'intervention',
|
|
21
23
|
deprecation: 'deprecation',
|
|
@@ -47,12 +49,11 @@ function createReportObservable(reportTypes) {
|
|
|
47
49
|
return;
|
|
48
50
|
}
|
|
49
51
|
|
|
50
|
-
var handleReports = function
|
|
52
|
+
var handleReports = (0, _monitor.monitor)(function (reports) {
|
|
51
53
|
(0, _tools.each)(reports, function (report) {
|
|
52
54
|
observable.notify(buildRawReportFromReport(report));
|
|
53
55
|
});
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
+
});
|
|
56
57
|
var observer = new window.ReportingObserver(handleReports, {
|
|
57
58
|
types: reportTypes,
|
|
58
59
|
buffered: true
|
package/cjs/transport/batch.js
CHANGED
|
@@ -81,10 +81,10 @@ var processedMessageByDataMap = function processedMessageByDataMap(message) {
|
|
|
81
81
|
}
|
|
82
82
|
});
|
|
83
83
|
|
|
84
|
-
if (message.
|
|
84
|
+
if (message.context && (0, _tools.isObject)(message.context) && !(0, _tools.isEmptyObject)(message.context)) {
|
|
85
85
|
// 自定义tag, 存储成field
|
|
86
86
|
var _tagKeys = [];
|
|
87
|
-
(0, _tools.each)(message.
|
|
87
|
+
(0, _tools.each)(message.context, function (_value, _key) {
|
|
88
88
|
// 如果和之前tag重名,则舍弃
|
|
89
89
|
if (filterFileds.indexOf(_key) > -1) return;
|
|
90
90
|
filterFileds.push(_key);
|
|
@@ -10,6 +10,8 @@ var _sendWithRetryStrategy = require("./sendWithRetryStrategy");
|
|
|
10
10
|
|
|
11
11
|
var _addEventListener = require("../browser/addEventListener");
|
|
12
12
|
|
|
13
|
+
var _monitor = require("../helper/monitor");
|
|
14
|
+
|
|
13
15
|
/**
|
|
14
16
|
* Use POST request without content type to:
|
|
15
17
|
* - avoid CORS preflight requests
|
|
@@ -77,17 +79,17 @@ function fetchKeepAliveStrategy(endpointUrl, bytesLimit, payload, onResponse) {
|
|
|
77
79
|
body: data,
|
|
78
80
|
keepalive: true,
|
|
79
81
|
mode: 'cors'
|
|
80
|
-
}).then(function (response) {
|
|
82
|
+
}).then((0, _monitor.monitor)(function (response) {
|
|
81
83
|
if (typeof onResponse === 'function') {
|
|
82
84
|
onResponse({
|
|
83
85
|
status: response.status,
|
|
84
86
|
type: response.type
|
|
85
87
|
});
|
|
86
88
|
}
|
|
87
|
-
}, function () {
|
|
89
|
+
}), (0, _monitor.monitor)(function () {
|
|
88
90
|
// failed to queue the request
|
|
89
91
|
sendXHR(url, data, onResponse);
|
|
90
|
-
});
|
|
92
|
+
}));
|
|
91
93
|
} else {
|
|
92
94
|
sendXHR(url, data, onResponse);
|
|
93
95
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { each } from '../helper/tools';
|
|
2
2
|
import { getZoneJsOriginalValue } from '../helper/getZoneJsOriginalValue';
|
|
3
|
+
import { monitor } from '../helper/monitor';
|
|
3
4
|
export function addEventListener(eventTarget, event, listener, options) {
|
|
4
5
|
return addEventListeners(eventTarget, [event], listener, options);
|
|
5
6
|
}
|
|
@@ -19,24 +20,24 @@ export function addEventListener(eventTarget, event, listener, options) {
|
|
|
19
20
|
* listened
|
|
20
21
|
*/
|
|
21
22
|
|
|
22
|
-
export function addEventListeners(eventTarget,
|
|
23
|
-
var wrappedListener = options && options.once ? function (event) {
|
|
23
|
+
export function addEventListeners(eventTarget, eventNames, listener, options) {
|
|
24
|
+
var wrappedListener = monitor(options && options.once ? function (event) {
|
|
24
25
|
stop();
|
|
25
26
|
listener(event);
|
|
26
|
-
} : listener;
|
|
27
|
+
} : listener);
|
|
27
28
|
options = options && options.passive ? {
|
|
28
29
|
capture: options.capture,
|
|
29
30
|
passive: options.passive
|
|
30
31
|
} : options && options.capture;
|
|
31
32
|
var add = getZoneJsOriginalValue(eventTarget, 'addEventListener');
|
|
32
|
-
each(
|
|
33
|
-
add.call(eventTarget,
|
|
33
|
+
each(eventNames, function (eventName) {
|
|
34
|
+
add.call(eventTarget, eventName, wrappedListener, options);
|
|
34
35
|
});
|
|
35
36
|
|
|
36
37
|
var stop = function stop() {
|
|
37
38
|
var remove = getZoneJsOriginalValue(eventTarget, 'removeEventListener');
|
|
38
|
-
each(
|
|
39
|
-
remove.call(eventTarget,
|
|
39
|
+
each(eventNames, function (eventName) {
|
|
40
|
+
remove.call(eventTarget, eventName, wrappedListener, options);
|
|
40
41
|
});
|
|
41
42
|
};
|
|
42
43
|
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { instrumentMethod } from '../helper/instrumentMethod';
|
|
2
2
|
import { Observable } from '../helper/observable';
|
|
3
3
|
import { clocksNow } from '../helper/tools';
|
|
4
|
+
import { monitor, callMonitored } from '../helper/monitor';
|
|
4
5
|
import { normalizeUrl } from '../helper/urlPolyfill';
|
|
5
6
|
var fetchObservable;
|
|
6
7
|
export function initFetchObservable() {
|
|
@@ -20,11 +21,11 @@ function createFetchObservable() {
|
|
|
20
21
|
var fetchMethod = instrumentMethod(window, 'fetch', function (originalFetch) {
|
|
21
22
|
return function (input, init) {
|
|
22
23
|
var responsePromise;
|
|
23
|
-
var context = beforeSend
|
|
24
|
+
var context = callMonitored(beforeSend, null, [observable, input, init]);
|
|
24
25
|
|
|
25
26
|
if (context) {
|
|
26
27
|
responsePromise = originalFetch.call(this, context.input, context.init);
|
|
27
|
-
afterSend
|
|
28
|
+
callMonitored(afterSend, null, [observable, responsePromise, context]);
|
|
28
29
|
} else {
|
|
29
30
|
responsePromise = originalFetch.call(this, input, init);
|
|
30
31
|
}
|
|
@@ -78,5 +79,5 @@ function afterSend(observable, responsePromise, startContext) {
|
|
|
78
79
|
observable.notify(context);
|
|
79
80
|
};
|
|
80
81
|
|
|
81
|
-
responsePromise.then(reportFetch, reportFetch);
|
|
82
|
+
responsePromise.then(monitor(reportFetch), monitor(reportFetch));
|
|
82
83
|
}
|
|
@@ -4,6 +4,7 @@ import { mergeObservables, Observable } from '../helper/observable';
|
|
|
4
4
|
import { find, map } from '../helper/tools';
|
|
5
5
|
import { jsonStringify } from '../helper/serialisation/jsonStringify';
|
|
6
6
|
import { ConsoleApiName } from '../helper/display';
|
|
7
|
+
import { callMonitored } from '../helper/monitor';
|
|
7
8
|
var consoleObservablesByApi = {};
|
|
8
9
|
export function initConsoleObservable(apis) {
|
|
9
10
|
var consoleObservables = map(apis, function (api) {
|
|
@@ -25,7 +26,9 @@ function createConsoleObservable(api) {
|
|
|
25
26
|
var params = [].slice.call(arguments);
|
|
26
27
|
originalConsoleApi.apply(console, arguments);
|
|
27
28
|
var handlingStack = createHandlingStack();
|
|
28
|
-
|
|
29
|
+
callMonitored(function () {
|
|
30
|
+
observable.notify(buildConsoleLog(params, api, handlingStack));
|
|
31
|
+
});
|
|
29
32
|
};
|
|
30
33
|
|
|
31
34
|
return function () {
|
package/esm/helper/errorTools.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { each, noop } from './tools';
|
|
2
2
|
import { jsonStringify } from '../helper/serialisation/jsonStringify';
|
|
3
3
|
import { computeStackTrace } from '../tracekit';
|
|
4
|
+
import { callMonitored } from '../helper/monitor';
|
|
4
5
|
export var ErrorSource = {
|
|
5
6
|
AGENT: 'agent',
|
|
6
7
|
CONSOLE: 'console',
|
|
@@ -87,9 +88,11 @@ export function createHandlingStack() {
|
|
|
87
88
|
}
|
|
88
89
|
}
|
|
89
90
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
91
|
+
callMonitored(function () {
|
|
92
|
+
var stackTrace = computeStackTrace(error);
|
|
93
|
+
stackTrace.stack = stackTrace.stack.slice(internalFramesToSkip);
|
|
94
|
+
formattedStack = toStackTraceString(stackTrace);
|
|
95
|
+
});
|
|
93
96
|
return formattedStack;
|
|
94
97
|
}
|
|
95
98
|
export function toStackTraceString(stack) {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { noop } from './tools';
|
|
2
2
|
import { setTimeout } from './timer';
|
|
3
|
+
import { callMonitored } from './monitor';
|
|
3
4
|
export function instrumentMethod(object, method, instrumentationFactory) {
|
|
4
5
|
var original = object[method];
|
|
5
6
|
var instrumentation = instrumentationFactory(original);
|
|
@@ -30,7 +31,7 @@ export function instrumentMethodAndCallOriginal(object, method, aliasOption) {
|
|
|
30
31
|
var result;
|
|
31
32
|
|
|
32
33
|
if (aliasOption && aliasOption.before) {
|
|
33
|
-
aliasOption.before.apply(this, arguments)
|
|
34
|
+
callMonitored(aliasOption.before, this, arguments); // aliasOption.before.apply(this, arguments)
|
|
34
35
|
}
|
|
35
36
|
|
|
36
37
|
if (typeof original === 'function') {
|
|
@@ -39,7 +40,7 @@ export function instrumentMethodAndCallOriginal(object, method, aliasOption) {
|
|
|
39
40
|
}
|
|
40
41
|
|
|
41
42
|
if (aliasOption && aliasOption.after) {
|
|
42
|
-
aliasOption.after.apply(this, arguments)
|
|
43
|
+
callMonitored(aliasOption.after, this, arguments); // aliasOption.after.apply(this, arguments)
|
|
43
44
|
}
|
|
44
45
|
|
|
45
46
|
return result;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { ConsoleApiName, display } from './display';
|
|
2
|
+
var onMonitorErrorCollected;
|
|
3
|
+
var debugMode = false;
|
|
4
|
+
export function startMonitorErrorCollection(newOnMonitorErrorCollected) {
|
|
5
|
+
onMonitorErrorCollected = newOnMonitorErrorCollected;
|
|
6
|
+
}
|
|
7
|
+
export function setDebugMode(newDebugMode) {
|
|
8
|
+
debugMode = newDebugMode;
|
|
9
|
+
}
|
|
10
|
+
export function resetMonitor() {
|
|
11
|
+
onMonitorErrorCollected = undefined;
|
|
12
|
+
debugMode = false;
|
|
13
|
+
}
|
|
14
|
+
export function monitor(fn) {
|
|
15
|
+
return function () {
|
|
16
|
+
return callMonitored(fn, this, arguments);
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
export function callMonitored(fn, context, args) {
|
|
20
|
+
try {
|
|
21
|
+
return fn.apply(context, args);
|
|
22
|
+
} catch (e) {
|
|
23
|
+
displayIfDebugEnabled(ConsoleApiName.error, e);
|
|
24
|
+
|
|
25
|
+
if (onMonitorErrorCollected) {
|
|
26
|
+
try {
|
|
27
|
+
onMonitorErrorCollected(e);
|
|
28
|
+
} catch (e) {
|
|
29
|
+
displayIfDebugEnabled(ConsoleApiName.error, e);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
export function displayIfDebugEnabled(api) {
|
|
35
|
+
var args = [].slice.call(arguments, 1);
|
|
36
|
+
|
|
37
|
+
if (debugMode) {
|
|
38
|
+
display.apply(null, [api, '[MONITOR]'].concat(args));
|
|
39
|
+
}
|
|
40
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { noop, each } from './tools';
|
|
2
|
+
import { monitor } from './monitor';
|
|
2
3
|
/**
|
|
3
4
|
* Read bytes from a ReadableStream until at least `limit` bytes have been read (or until the end of
|
|
4
5
|
* the stream). The callback is invoked with the at most `limit` bytes, and indicates that the limit
|
|
@@ -12,7 +13,7 @@ export function readBytesFromStream(stream, callback, options) {
|
|
|
12
13
|
readMore();
|
|
13
14
|
|
|
14
15
|
function readMore() {
|
|
15
|
-
reader.read().then(function (result) {
|
|
16
|
+
reader.read().then(monitor(function (result) {
|
|
16
17
|
if (result.done) {
|
|
17
18
|
onDone();
|
|
18
19
|
return;
|
|
@@ -29,9 +30,9 @@ export function readBytesFromStream(stream, callback, options) {
|
|
|
29
30
|
} else {
|
|
30
31
|
readMore();
|
|
31
32
|
}
|
|
32
|
-
}, function (error) {
|
|
33
|
+
}), monitor(function (error) {
|
|
33
34
|
callback(error);
|
|
34
|
-
});
|
|
35
|
+
}));
|
|
35
36
|
}
|
|
36
37
|
|
|
37
38
|
function onDone() {
|