@cloudcare/browser-logs 1.1.24 → 1.2.1
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/README.md +5 -4
- package/bundle/dataflux-logs.js +1 -1
- package/cjs/boot/buildEnv.js +1 -1
- package/cjs/boot/logsPublicApi.js +133 -0
- package/cjs/boot/startLogs.js +63 -0
- package/cjs/domain/assembly.js +74 -0
- package/cjs/domain/configuration.js +55 -0
- package/cjs/domain/internalContext.js +22 -0
- package/cjs/domain/logger.js +28 -36
- package/cjs/domain/logsCollection/console/consoleCollection.js +39 -0
- package/cjs/domain/logsCollection/logger/loggerCollection.js +51 -0
- package/cjs/domain/logsCollection/networkError/networkErrorCollection.js +238 -0
- package/cjs/domain/logsCollection/report/reportCollection.js +50 -0
- package/cjs/domain/logsCollection/rumtimeError/runtimeErrorCollection.js +46 -0
- package/cjs/domain/{loggerSession.js → logsSessionManager.js} +19 -23
- package/cjs/entries/main.js +16 -0
- package/cjs/index.js +2 -2
- package/cjs/transport/startLogsBatch.js +15 -0
- package/esm/boot/buildEnv.js +1 -1
- package/esm/boot/logsPublicApi.js +122 -0
- package/esm/boot/startLogs.js +45 -0
- package/esm/domain/assembly.js +59 -0
- package/esm/domain/configuration.js +41 -0
- package/esm/domain/internalContext.js +15 -0
- package/esm/domain/logger.js +26 -36
- package/esm/domain/logsCollection/console/consoleCollection.js +31 -0
- package/esm/domain/logsCollection/logger/loggerCollection.js +38 -0
- package/esm/domain/logsCollection/networkError/networkErrorCollection.js +223 -0
- package/esm/domain/logsCollection/report/reportCollection.js +40 -0
- package/esm/domain/logsCollection/rumtimeError/runtimeErrorCollection.js +37 -0
- package/esm/domain/logsSessionManager.js +45 -0
- package/esm/entries/main.js +5 -0
- package/esm/index.js +1 -1
- package/esm/transport/startLogsBatch.js +7 -0
- package/package.json +3 -3
- package/src/boot/logsPublicApi.js +140 -0
- package/src/boot/startLogs.js +51 -0
- package/src/domain/assembly.js +101 -0
- package/src/domain/configuration.js +70 -0
- package/src/domain/internalContext.js +15 -0
- package/src/domain/logger.js +37 -58
- package/src/domain/logsCollection/console/consoleCollection.js +36 -0
- package/src/domain/logsCollection/logger/loggerCollection.js +48 -0
- package/src/domain/logsCollection/networkError/networkErrorCollection.js +260 -0
- package/src/domain/logsCollection/report/reportCollection.js +49 -0
- package/src/domain/logsCollection/rumtimeError/runtimeErrorCollection.js +35 -0
- package/src/domain/logsSessionManager.js +52 -0
- package/src/entries/main.js +7 -0
- package/src/index.js +1 -1
- package/src/transport/startLogsBatch.js +17 -0
- package/cjs/boot/log.entry.js +0 -115
- package/cjs/boot/log.js +0 -132
- package/esm/boot/log.entry.js +0 -87
- package/esm/boot/log.js +0 -115
- package/esm/domain/loggerSession.js +0 -46
- package/src/boot/log.entry.js +0 -119
- package/src/boot/log.js +0 -185
- package/src/domain/loggerSession.js +0 -56
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.startInternalContext = startInternalContext;
|
|
7
|
+
|
|
8
|
+
function startInternalContext(sessionManager) {
|
|
9
|
+
return {
|
|
10
|
+
get: function get(startTime) {
|
|
11
|
+
var trackedSession = sessionManager.findTrackedSession(startTime);
|
|
12
|
+
|
|
13
|
+
if (trackedSession) {
|
|
14
|
+
return {
|
|
15
|
+
session: {
|
|
16
|
+
id: trackedSession.id
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
}
|
package/cjs/domain/logger.js
CHANGED
|
@@ -9,31 +9,25 @@ exports.StatusType = exports.STATUSES = void 0;
|
|
|
9
9
|
|
|
10
10
|
var _browserCore = require("@cloudcare/browser-core");
|
|
11
11
|
|
|
12
|
-
var _STATUS_PRIORITIES;
|
|
13
|
-
|
|
14
|
-
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
15
|
-
|
|
16
12
|
var StatusType = {
|
|
17
13
|
debug: 'debug',
|
|
18
|
-
critical: 'critical',
|
|
19
14
|
error: 'error',
|
|
20
15
|
info: 'info',
|
|
21
|
-
warn: '
|
|
22
|
-
|
|
23
|
-
|
|
16
|
+
warn: 'warn',
|
|
17
|
+
critical: 'critical'
|
|
18
|
+
};
|
|
24
19
|
exports.StatusType = StatusType;
|
|
25
|
-
var STATUS_PRIORITIES = (_STATUS_PRIORITIES = {}, _defineProperty(_STATUS_PRIORITIES, StatusType.debug, 0), _defineProperty(_STATUS_PRIORITIES, StatusType.info, 1), _defineProperty(_STATUS_PRIORITIES, StatusType.warn, 2), _defineProperty(_STATUS_PRIORITIES, StatusType.error, 3), _defineProperty(_STATUS_PRIORITIES, StatusType.critical, 4), _STATUS_PRIORITIES);
|
|
26
|
-
var STATUSES = (0, _browserCore.keys)(StatusType);
|
|
27
|
-
exports.STATUSES = STATUSES;
|
|
28
20
|
var HandlerType = {
|
|
29
21
|
console: 'console',
|
|
30
22
|
http: 'http',
|
|
31
23
|
silent: 'silent'
|
|
32
|
-
};
|
|
33
|
-
|
|
24
|
+
};
|
|
34
25
|
exports.HandlerType = HandlerType;
|
|
26
|
+
var STATUSES = (0, _browserCore.keys)(StatusType); // eslint-disable-next-line @typescript-eslint/no-redeclare
|
|
27
|
+
|
|
28
|
+
exports.STATUSES = STATUSES;
|
|
35
29
|
|
|
36
|
-
function Logger(
|
|
30
|
+
function Logger(handleLogStrategy, name, handlerType, level, loggerContext) {
|
|
37
31
|
this.contextManager = (0, _browserCore.createContextManager)();
|
|
38
32
|
|
|
39
33
|
if (typeof handlerType === 'undefined') {
|
|
@@ -48,10 +42,14 @@ function Logger(sendLog, handlerType, level, loggerContext) {
|
|
|
48
42
|
loggerContext = {};
|
|
49
43
|
}
|
|
50
44
|
|
|
51
|
-
this.
|
|
45
|
+
this.handleLogStrategy = handleLogStrategy;
|
|
52
46
|
this.handlerType = handlerType;
|
|
53
47
|
this.level = level;
|
|
54
|
-
this.contextManager.set(loggerContext
|
|
48
|
+
this.contextManager.set((0, _browserCore.assign)({}, loggerContext, name ? {
|
|
49
|
+
logger: {
|
|
50
|
+
name: name
|
|
51
|
+
}
|
|
52
|
+
} : undefined));
|
|
55
53
|
}
|
|
56
54
|
|
|
57
55
|
Logger.prototype = {
|
|
@@ -60,26 +58,11 @@ Logger.prototype = {
|
|
|
60
58
|
status = StatusType.info;
|
|
61
59
|
}
|
|
62
60
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
status: status
|
|
69
|
-
}, {
|
|
70
|
-
tags: this.contextManager.get()
|
|
71
|
-
}, messageContext);
|
|
72
|
-
this.sendLog(logMessage);
|
|
73
|
-
break;
|
|
74
|
-
|
|
75
|
-
case HandlerType.console:
|
|
76
|
-
console.log(status + ' : ' + message, (0, _browserCore.extend2Lev)(this.contextManager.get(), messageContext));
|
|
77
|
-
break;
|
|
78
|
-
|
|
79
|
-
case HandlerType.silent:
|
|
80
|
-
break;
|
|
81
|
-
}
|
|
82
|
-
}
|
|
61
|
+
this.handleLogStrategy({
|
|
62
|
+
message: message,
|
|
63
|
+
context: (0, _browserCore.deepClone)(messageContext),
|
|
64
|
+
status: status
|
|
65
|
+
}, this);
|
|
83
66
|
},
|
|
84
67
|
debug: function debug(message, messageContext) {
|
|
85
68
|
this.log(message, messageContext, StatusType.debug);
|
|
@@ -104,6 +87,9 @@ Logger.prototype = {
|
|
|
104
87
|
setContext: function setContext(context) {
|
|
105
88
|
this.contextManager.set(context);
|
|
106
89
|
},
|
|
90
|
+
getContext: function getContext() {
|
|
91
|
+
return this.contextManager.get();
|
|
92
|
+
},
|
|
107
93
|
addContext: function addContext(key, value) {
|
|
108
94
|
this.contextManager.add(key, value);
|
|
109
95
|
},
|
|
@@ -113,7 +99,13 @@ Logger.prototype = {
|
|
|
113
99
|
setHandler: function setHandler(handler) {
|
|
114
100
|
this.handlerType = handler;
|
|
115
101
|
},
|
|
102
|
+
getHandler: function getHandler() {
|
|
103
|
+
return this.handlerType;
|
|
104
|
+
},
|
|
116
105
|
setLevel: function setLevel(level) {
|
|
117
106
|
this.level = level;
|
|
107
|
+
},
|
|
108
|
+
getLevel: function getLevel() {
|
|
109
|
+
return this.level;
|
|
118
110
|
}
|
|
119
111
|
};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.startConsoleCollection = startConsoleCollection;
|
|
7
|
+
|
|
8
|
+
var _browserCore = require("@cloudcare/browser-core");
|
|
9
|
+
|
|
10
|
+
var _logger = require("../../logger");
|
|
11
|
+
|
|
12
|
+
var _LogStatusForApi;
|
|
13
|
+
|
|
14
|
+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
15
|
+
|
|
16
|
+
var LogStatusForApi = (_LogStatusForApi = {}, _defineProperty(_LogStatusForApi, _browserCore.ConsoleApiName.log, _logger.StatusType.info), _defineProperty(_LogStatusForApi, _browserCore.ConsoleApiName.debug, _logger.StatusType.debug), _defineProperty(_LogStatusForApi, _browserCore.ConsoleApiName.info, _logger.StatusType.info), _defineProperty(_LogStatusForApi, _browserCore.ConsoleApiName.warn, _logger.StatusType.warn), _defineProperty(_LogStatusForApi, _browserCore.ConsoleApiName.error, _logger.StatusType.error), _LogStatusForApi);
|
|
17
|
+
|
|
18
|
+
function startConsoleCollection(configuration, lifeCycle) {
|
|
19
|
+
var consoleSubscription = (0, _browserCore.initConsoleObservable)(configuration.forwardConsoleLogs).subscribe(function (log) {
|
|
20
|
+
lifeCycle.notify(_browserCore.LifeCycleEventType.RAW_LOG_COLLECTED, {
|
|
21
|
+
rawLogsEvent: {
|
|
22
|
+
date: (0, _browserCore.timeStampNow)(),
|
|
23
|
+
message: log.message,
|
|
24
|
+
origin: _browserCore.ErrorSource.CONSOLE,
|
|
25
|
+
error: log.api === _browserCore.ConsoleApiName.error ? {
|
|
26
|
+
origin: _browserCore.ErrorSource.CONSOLE,
|
|
27
|
+
// Todo: Remove in the next major release
|
|
28
|
+
stack: log.stack
|
|
29
|
+
} : undefined,
|
|
30
|
+
status: LogStatusForApi[log.api]
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
return {
|
|
35
|
+
stop: function stop() {
|
|
36
|
+
consoleSubscription.unsubscribe();
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.STATUS_PRIORITIES = void 0;
|
|
7
|
+
exports.isAuthorized = isAuthorized;
|
|
8
|
+
exports.startLoggerCollection = startLoggerCollection;
|
|
9
|
+
|
|
10
|
+
var _browserCore = require("@cloudcare/browser-core");
|
|
11
|
+
|
|
12
|
+
var _logger = require("../../logger");
|
|
13
|
+
|
|
14
|
+
var _STATUS_PRIORITIES;
|
|
15
|
+
|
|
16
|
+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
17
|
+
|
|
18
|
+
var STATUS_PRIORITIES = (_STATUS_PRIORITIES = {}, _defineProperty(_STATUS_PRIORITIES, _logger.StatusType.debug, 0), _defineProperty(_STATUS_PRIORITIES, _logger.StatusType.info, 1), _defineProperty(_STATUS_PRIORITIES, _logger.StatusType.warn, 2), _defineProperty(_STATUS_PRIORITIES, _logger.StatusType.error, 3), _STATUS_PRIORITIES);
|
|
19
|
+
exports.STATUS_PRIORITIES = STATUS_PRIORITIES;
|
|
20
|
+
|
|
21
|
+
function startLoggerCollection(lifeCycle) {
|
|
22
|
+
function handleLog(logsMessage, logger, savedCommonContext, savedDate) {
|
|
23
|
+
var messageContext = logsMessage.context;
|
|
24
|
+
|
|
25
|
+
if (isAuthorized(logsMessage.status, _logger.HandlerType.console, logger)) {
|
|
26
|
+
(0, _browserCore.display)(logsMessage.status, logsMessage.message, (0, _browserCore.extend2Lev)(logger.getContext(), messageContext));
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
lifeCycle.notify(_browserCore.LifeCycleEventType.RAW_LOG_COLLECTED, {
|
|
30
|
+
rawLogsEvent: {
|
|
31
|
+
date: savedDate || (0, _browserCore.timeStampNow)(),
|
|
32
|
+
message: logsMessage.message,
|
|
33
|
+
status: logsMessage.status,
|
|
34
|
+
origin: _browserCore.ErrorSource.LOGGER
|
|
35
|
+
},
|
|
36
|
+
messageContext: messageContext,
|
|
37
|
+
savedCommonContext: savedCommonContext,
|
|
38
|
+
logger: logger
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return {
|
|
43
|
+
handleLog: handleLog
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function isAuthorized(status, handlerType, logger) {
|
|
48
|
+
var loggerHandler = logger.getHandler();
|
|
49
|
+
var sanitizedHandlerType = (0, _browserCore.isArray)(loggerHandler) ? loggerHandler : [loggerHandler];
|
|
50
|
+
return STATUS_PRIORITIES[status] >= STATUS_PRIORITIES[logger.getLevel()] && (0, _browserCore.includes)(sanitizedHandlerType, handlerType);
|
|
51
|
+
}
|
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.computeFetchErrorText = computeFetchErrorText;
|
|
7
|
+
exports.computeFetchResponseText = computeFetchResponseText;
|
|
8
|
+
exports.computeXhrResponseData = computeXhrResponseData;
|
|
9
|
+
exports.startNetworkErrorCollection = startNetworkErrorCollection;
|
|
10
|
+
|
|
11
|
+
var _browserCore = require("@cloudcare/browser-core");
|
|
12
|
+
|
|
13
|
+
var _logger = require("../../logger");
|
|
14
|
+
|
|
15
|
+
function startNetworkErrorCollection(configuration, lifeCycle) {
|
|
16
|
+
if (!configuration.forwardErrorsToLogs) {
|
|
17
|
+
return {
|
|
18
|
+
stop: _browserCore.noop
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
var xhrSubscription = (0, _browserCore.initXhrObservable)().subscribe(function (context) {
|
|
23
|
+
if (context.state === 'complete') {
|
|
24
|
+
handleCompleteRequest(_browserCore.RequestType.XHR, context, configuration);
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
var fetchSubscription = (0, _browserCore.initFetchObservable)().subscribe(function (context) {
|
|
28
|
+
if (context.state === 'complete') {
|
|
29
|
+
handleCompleteRequest(_browserCore.RequestType.FETCH, context, configuration);
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
function handleCompleteRequest(type, request) {
|
|
34
|
+
if (!configuration.isIntakeUrl(request.url) && (isRejected(request) || isServerError(request) || configuration.isServerError(request))) {
|
|
35
|
+
if ('xhr' in request) {
|
|
36
|
+
computeXhrResponseData(request.xhr, configuration, onResponseDataAvailable);
|
|
37
|
+
} else if (request.response) {
|
|
38
|
+
computeFetchResponseText(request.response, configuration, onResponseDataAvailable);
|
|
39
|
+
} else if (request.error) {
|
|
40
|
+
computeFetchErrorText(request.error, configuration, onResponseDataAvailable);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function onResponseDataAvailable(responseData) {
|
|
45
|
+
var urlObj = (0, _browserCore.urlParse)(request.url).getParse();
|
|
46
|
+
lifeCycle.notify(_browserCore.LifeCycleEventType.RAW_LOG_COLLECTED, {
|
|
47
|
+
rawLogsEvent: {
|
|
48
|
+
message: format(type) + ' error ' + request.method + ' ' + request.url,
|
|
49
|
+
date: request.startClocks.timeStamp,
|
|
50
|
+
error: {
|
|
51
|
+
origin: _browserCore.ErrorSource.NETWORK,
|
|
52
|
+
// Todo: Remove in the next major release
|
|
53
|
+
stack: responseData || 'Failed to load'
|
|
54
|
+
},
|
|
55
|
+
http: {
|
|
56
|
+
method: request.method,
|
|
57
|
+
// Cast resource method because of case mismatch cf issue RUMF-1152
|
|
58
|
+
status_code: request.status,
|
|
59
|
+
url: request.url,
|
|
60
|
+
statusGroup: (0, _browserCore.getStatusGroup)(request.status),
|
|
61
|
+
urlHost: urlObj.Host,
|
|
62
|
+
urlPath: urlObj.Path,
|
|
63
|
+
urlPathGroup: (0, _browserCore.replaceNumberCharByPath)(urlObj.Path)
|
|
64
|
+
},
|
|
65
|
+
status: _logger.StatusType.error,
|
|
66
|
+
origin: _browserCore.ErrorSource.NETWORK
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return {
|
|
73
|
+
stop: function stop() {
|
|
74
|
+
xhrSubscription.unsubscribe();
|
|
75
|
+
fetchSubscription.unsubscribe();
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
} // TODO: ideally, computeXhrResponseData should always call the callback with a string instead of
|
|
79
|
+
// `unknown`. But to keep backward compatibility, in the case of XHR with a `responseType` different
|
|
80
|
+
// than "text", the response data should be whatever `xhr.response` is. This is a bit confusing as
|
|
81
|
+
// Logs event 'stack' is expected to be a string. This should be changed in a future major version
|
|
82
|
+
// as it could be a breaking change.
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
function computeXhrResponseData(xhr, configuration, callback) {
|
|
86
|
+
if (typeof xhr.response === 'string') {
|
|
87
|
+
callback(truncateResponseText(xhr.response, configuration));
|
|
88
|
+
} else {
|
|
89
|
+
callback(xhr.response);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function computeFetchErrorText(error, configuration, callback) {
|
|
94
|
+
callback(truncateResponseText((0, _browserCore.toStackTraceString)((0, _browserCore.computeStackTrace)(error)), configuration));
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function computeFetchResponseText(response, configuration, callback) {
|
|
98
|
+
if (!window.TextDecoder) {
|
|
99
|
+
// If the browser doesn't support TextDecoder, let's read the whole response then truncate it.
|
|
100
|
+
//
|
|
101
|
+
// This should only be the case on early versions of Edge (before they migrated to Chromium).
|
|
102
|
+
// Even if it could be possible to implement a workaround for the missing TextDecoder API (using
|
|
103
|
+
// a Blob and FileReader), we found another issue preventing us from reading only the first
|
|
104
|
+
// bytes from the response: contrary to other browsers, when reading from the cloned response,
|
|
105
|
+
// if the original response gets canceled, the cloned response is also canceled and we can't
|
|
106
|
+
// know about it. In the following illustration, the promise returned by `reader.read()` may
|
|
107
|
+
// never be fulfilled:
|
|
108
|
+
//
|
|
109
|
+
// fetch('/').then((response) => {
|
|
110
|
+
// const reader = response.clone().body.getReader()
|
|
111
|
+
// readMore()
|
|
112
|
+
// function readMore() {
|
|
113
|
+
// reader.read().then(
|
|
114
|
+
// (result) => {
|
|
115
|
+
// if (result.done) {
|
|
116
|
+
// console.log('done')
|
|
117
|
+
// } else {
|
|
118
|
+
// readMore()
|
|
119
|
+
// }
|
|
120
|
+
// },
|
|
121
|
+
// () => console.log('error')
|
|
122
|
+
// )
|
|
123
|
+
// }
|
|
124
|
+
// response.body.getReader().cancel()
|
|
125
|
+
// })
|
|
126
|
+
response.clone().text().then(function (text) {
|
|
127
|
+
return callback(truncateResponseText(text, configuration));
|
|
128
|
+
}, function (error) {
|
|
129
|
+
return callback('Unable to retrieve response: ' + error);
|
|
130
|
+
});
|
|
131
|
+
} else if (!response.body) {
|
|
132
|
+
callback();
|
|
133
|
+
} else {
|
|
134
|
+
truncateResponseStream(response.clone().body, configuration.requestErrorResponseLengthLimit, function (error, responseText) {
|
|
135
|
+
if (error) {
|
|
136
|
+
callback('Unable to retrieve response: ' + error);
|
|
137
|
+
} else {
|
|
138
|
+
callback(responseText);
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
function isRejected(request) {
|
|
145
|
+
return request.status === 0 && request.responseType !== 'opaque';
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
function isServerError(request) {
|
|
149
|
+
return request.status >= 500;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
function truncateResponseText(responseText, configuration) {
|
|
153
|
+
if (responseText.length > configuration.requestErrorResponseLengthLimit) {
|
|
154
|
+
return responseText.substring(0, configuration.requestErrorResponseLengthLimit) + '...';
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
return responseText;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
function format(type) {
|
|
161
|
+
if (_browserCore.RequestType.XHR === type) {
|
|
162
|
+
return 'XHR';
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
return 'Fetch';
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
function truncateResponseStream(stream, limit, callback) {
|
|
169
|
+
readLimitedAmountOfBytes(stream, limit, function (error, bytes, limitExceeded) {
|
|
170
|
+
if (error) {
|
|
171
|
+
callback(error);
|
|
172
|
+
} else {
|
|
173
|
+
var responseText = new TextDecoder().decode(bytes);
|
|
174
|
+
|
|
175
|
+
if (limitExceeded) {
|
|
176
|
+
responseText += '...';
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
callback(undefined, responseText);
|
|
180
|
+
}
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Read bytes from a ReadableStream until at least `limit` bytes have been read (or until the end of
|
|
185
|
+
* the stream). The callback is invoked with the at most `limit` bytes, and indicates that the limit
|
|
186
|
+
* has been exceeded if more bytes were available.
|
|
187
|
+
*/
|
|
188
|
+
|
|
189
|
+
|
|
190
|
+
function readLimitedAmountOfBytes(stream, limit, callback) {
|
|
191
|
+
var reader = stream.getReader();
|
|
192
|
+
var chunks = [];
|
|
193
|
+
var readBytesCount = 0;
|
|
194
|
+
readMore();
|
|
195
|
+
|
|
196
|
+
function readMore() {
|
|
197
|
+
reader.read().then(function (result) {
|
|
198
|
+
if (result.done) {
|
|
199
|
+
onDone();
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
chunks.push(result.value);
|
|
204
|
+
readBytesCount += result.value.length;
|
|
205
|
+
|
|
206
|
+
if (readBytesCount > limit) {
|
|
207
|
+
onDone();
|
|
208
|
+
} else {
|
|
209
|
+
readMore();
|
|
210
|
+
}
|
|
211
|
+
}, function (error) {
|
|
212
|
+
return callback(error);
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
function onDone() {
|
|
217
|
+
reader.cancel()["catch"]( // we don't care if cancel fails, but we still need to catch the error to avoid reporting it
|
|
218
|
+
// as an unhandled rejection
|
|
219
|
+
_browserCore.noop);
|
|
220
|
+
var completeBuffer;
|
|
221
|
+
|
|
222
|
+
if (chunks.length === 1) {
|
|
223
|
+
// optim: if the response is small enough to fit in a single buffer (provided by the browser), just
|
|
224
|
+
// use it directly.
|
|
225
|
+
completeBuffer = chunks[0];
|
|
226
|
+
} else {
|
|
227
|
+
// else, we need to copy buffers into a larger buffer to concatenate them.
|
|
228
|
+
completeBuffer = new Uint8Array(readBytesCount);
|
|
229
|
+
var offset = 0;
|
|
230
|
+
(0, _browserCore.each)(chunks, function (chunk) {
|
|
231
|
+
completeBuffer.set(chunk, offset);
|
|
232
|
+
offset += chunk.length;
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
callback(undefined, completeBuffer.slice(0, limit), completeBuffer.length > limit);
|
|
237
|
+
}
|
|
238
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.startReportCollection = startReportCollection;
|
|
7
|
+
|
|
8
|
+
var _browserCore = require("@cloudcare/browser-core");
|
|
9
|
+
|
|
10
|
+
var _logger = require("../../logger");
|
|
11
|
+
|
|
12
|
+
var _LogStatusForReport;
|
|
13
|
+
|
|
14
|
+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
15
|
+
|
|
16
|
+
var LogStatusForReport = (_LogStatusForReport = {}, _defineProperty(_LogStatusForReport, _browserCore.RawReportType.cspViolation, _logger.StatusType.error), _defineProperty(_LogStatusForReport, _browserCore.RawReportType.intervention, _logger.StatusType.error), _defineProperty(_LogStatusForReport, _browserCore.RawReportType.deprecation, _logger.StatusType.warn), _LogStatusForReport);
|
|
17
|
+
|
|
18
|
+
function startReportCollection(configuration, lifeCycle) {
|
|
19
|
+
var reportSubscription = (0, _browserCore.initReportObservable)(configuration.forwardReports).subscribe(function (report) {
|
|
20
|
+
var message = report.message;
|
|
21
|
+
var status = LogStatusForReport[report.type];
|
|
22
|
+
var error;
|
|
23
|
+
|
|
24
|
+
if (status === _logger.StatusType.error) {
|
|
25
|
+
error = {
|
|
26
|
+
kind: report.subtype,
|
|
27
|
+
origin: _browserCore.ErrorSource.REPORT,
|
|
28
|
+
// Todo: Remove in the next major release
|
|
29
|
+
stack: report.stack
|
|
30
|
+
};
|
|
31
|
+
} else if (report.stack) {
|
|
32
|
+
message += ' Found in ' + (0, _browserCore.getFileFromStackTraceString)(report.stack);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
lifeCycle.notify(_browserCore.LifeCycleEventType.RAW_LOG_COLLECTED, {
|
|
36
|
+
rawLogsEvent: {
|
|
37
|
+
date: (0, _browserCore.timeStampNow)(),
|
|
38
|
+
message: message,
|
|
39
|
+
origin: _browserCore.ErrorSource.REPORT,
|
|
40
|
+
error: error,
|
|
41
|
+
status: status
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
return {
|
|
46
|
+
stop: function stop() {
|
|
47
|
+
reportSubscription.unsubscribe();
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.startRuntimeErrorCollection = startRuntimeErrorCollection;
|
|
7
|
+
|
|
8
|
+
var _browserCore = require("@cloudcare/browser-core");
|
|
9
|
+
|
|
10
|
+
var _logger = require("../../logger");
|
|
11
|
+
|
|
12
|
+
function startRuntimeErrorCollection(configuration, lifeCycle) {
|
|
13
|
+
if (!configuration.forwardErrorsToLogs) {
|
|
14
|
+
return {
|
|
15
|
+
stop: _browserCore.noop
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
var rawErrorObservable = new _browserCore.Observable();
|
|
20
|
+
|
|
21
|
+
var _trackRuntimeError = (0, _browserCore.trackRuntimeError)(rawErrorObservable);
|
|
22
|
+
|
|
23
|
+
var rawErrorSubscription = rawErrorObservable.subscribe(function (rawError) {
|
|
24
|
+
lifeCycle.notify(_browserCore.LifeCycleEventType.RAW_LOG_COLLECTED, {
|
|
25
|
+
rawLogsEvent: {
|
|
26
|
+
message: rawError.message,
|
|
27
|
+
date: rawError.startClocks.timeStamp,
|
|
28
|
+
error: {
|
|
29
|
+
kind: rawError.type,
|
|
30
|
+
origin: _browserCore.ErrorSource.SOURCE,
|
|
31
|
+
// Todo: Remove in the next major release
|
|
32
|
+
stack: rawError.stack
|
|
33
|
+
},
|
|
34
|
+
origin: _browserCore.ErrorSource.SOURCE,
|
|
35
|
+
status: _logger.StatusType.error
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
return {
|
|
40
|
+
stop: function stop() {
|
|
41
|
+
_trackRuntimeError.stop();
|
|
42
|
+
|
|
43
|
+
rawErrorSubscription.unsubscribe();
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
}
|
|
@@ -3,43 +3,39 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.LoggerTrackingType = exports.
|
|
7
|
-
exports.
|
|
6
|
+
exports.LoggerTrackingType = exports.LOGS_SESSION_KEY = void 0;
|
|
7
|
+
exports.startLogsSessionManager = startLogsSessionManager;
|
|
8
8
|
|
|
9
9
|
var _browserCore = require("@cloudcare/browser-core");
|
|
10
10
|
|
|
11
|
-
var
|
|
12
|
-
exports.
|
|
11
|
+
var LOGS_SESSION_KEY = 'logs';
|
|
12
|
+
exports.LOGS_SESSION_KEY = LOGS_SESSION_KEY;
|
|
13
13
|
var LoggerTrackingType = {
|
|
14
14
|
NOT_TRACKED: '0',
|
|
15
15
|
TRACKED: '1'
|
|
16
16
|
};
|
|
17
17
|
exports.LoggerTrackingType = LoggerTrackingType;
|
|
18
18
|
|
|
19
|
-
function
|
|
20
|
-
|
|
21
|
-
var _isTracked = computeTrackingType(configuration) === LoggerTrackingType.TRACKED;
|
|
22
|
-
|
|
23
|
-
return {
|
|
24
|
-
getId: function getId() {
|
|
25
|
-
return undefined;
|
|
26
|
-
},
|
|
27
|
-
isTracked: function isTracked() {
|
|
28
|
-
return _isTracked;
|
|
29
|
-
}
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
var session = (0, _browserCore.startSessionManagement)(configuration.cookieOptions, LOGGER_SESSION_KEY, function (rawTrackingType) {
|
|
19
|
+
function startLogsSessionManager(configuration) {
|
|
20
|
+
var sessionManager = (0, _browserCore.startSessionManager)(configuration.cookieOptions, LOGS_SESSION_KEY, function (rawTrackingType) {
|
|
34
21
|
return computeSessionState(configuration, rawTrackingType);
|
|
35
22
|
});
|
|
36
23
|
return {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
return session.
|
|
24
|
+
findTrackedSession: function findTrackedSession(startTime) {
|
|
25
|
+
var session = sessionManager.findActiveSession(startTime);
|
|
26
|
+
return session && session.trackingType === LoggerTrackingType.TRACKED ? {
|
|
27
|
+
id: session.id
|
|
28
|
+
} : undefined;
|
|
40
29
|
}
|
|
41
30
|
};
|
|
42
|
-
}
|
|
31
|
+
} // export function startLogsSessionManagerStub(configuration) {
|
|
32
|
+
// var isTracked = computeTrackingType(configuration) === LoggerTrackingType.TRACKED
|
|
33
|
+
// var session = isTracked ? {} : undefined
|
|
34
|
+
// return {
|
|
35
|
+
// findTrackedSession: function() { return session },
|
|
36
|
+
// }
|
|
37
|
+
// }
|
|
38
|
+
|
|
43
39
|
|
|
44
40
|
function computeTrackingType(configuration) {
|
|
45
41
|
if (!(0, _browserCore.performDraw)(configuration.sampleRate)) {
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.datafluxLogs = void 0;
|
|
7
|
+
|
|
8
|
+
var _browserCore = require("@cloudcare/browser-core");
|
|
9
|
+
|
|
10
|
+
var _logsPublicApi = require("../boot/logsPublicApi");
|
|
11
|
+
|
|
12
|
+
var _startLogs = require("../boot/startLogs");
|
|
13
|
+
|
|
14
|
+
var datafluxLogs = (0, _logsPublicApi.makeLogsPublicApi)(_startLogs.startLogs);
|
|
15
|
+
exports.datafluxLogs = datafluxLogs;
|
|
16
|
+
(0, _browserCore.defineGlobal)((0, _browserCore.getGlobalObject)(), 'DATAFLUX_LOGS', datafluxLogs);
|
package/cjs/index.js
CHANGED
|
@@ -6,8 +6,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
Object.defineProperty(exports, "datafluxLogs", {
|
|
7
7
|
enumerable: true,
|
|
8
8
|
get: function get() {
|
|
9
|
-
return
|
|
9
|
+
return _main.datafluxLogs;
|
|
10
10
|
}
|
|
11
11
|
});
|
|
12
12
|
|
|
13
|
-
var
|
|
13
|
+
var _main = require("./entries/main");
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.startLogsBatch = startLogsBatch;
|
|
7
|
+
|
|
8
|
+
var _browserCore = require("@cloudcare/browser-core");
|
|
9
|
+
|
|
10
|
+
function startLogsBatch(configuration, lifeCycle, reportError) {
|
|
11
|
+
var batch = (0, _browserCore.startBatchWithReplica)(configuration, configuration.logsEndpoint, reportError);
|
|
12
|
+
lifeCycle.subscribe(_browserCore.LifeCycleEventType.LOG_COLLECTED, function (serverLogsEvent) {
|
|
13
|
+
batch.add(serverLogsEvent);
|
|
14
|
+
});
|
|
15
|
+
}
|
package/esm/boot/buildEnv.js
CHANGED