@cloudcare/browser-core 1.1.3 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (134) hide show
  1. package/cjs/{cookie.js → browser/cookie.js} +6 -37
  2. package/cjs/browser/fetchObservable.js +91 -0
  3. package/cjs/browser/xhrObservable.js +118 -0
  4. package/cjs/configuration/configuration.js +70 -0
  5. package/cjs/configuration/transportConfiguration.js +64 -0
  6. package/cjs/console/consoleObservable.js +84 -0
  7. package/cjs/dataMap.js +26 -21
  8. package/cjs/error/trackRuntimeError.js +27 -0
  9. package/cjs/helper/catchUserErrors.js +20 -0
  10. package/cjs/helper/contextHistory.js +134 -0
  11. package/cjs/helper/createEventRateLimiter.js +47 -0
  12. package/cjs/helper/deviceInfo.js +8 -25
  13. package/cjs/helper/display.js +31 -0
  14. package/cjs/helper/enums.js +28 -2
  15. package/cjs/helper/errorTools.js +63 -2
  16. package/cjs/helper/instrumentMethod.js +93 -0
  17. package/cjs/helper/lifeCycle.js +5 -3
  18. package/cjs/helper/observable.js +40 -2
  19. package/cjs/helper/tools.js +185 -9
  20. package/cjs/index.js +153 -23
  21. package/cjs/init.js +17 -27
  22. package/cjs/report/reportObservable.js +112 -0
  23. package/cjs/session/sessionConstants.js +13 -0
  24. package/cjs/session/sessionCookieStore.js +188 -0
  25. package/cjs/session/sessionManagement.js +96 -0
  26. package/cjs/session/sessionStore.js +150 -0
  27. package/cjs/synthetics/syntheticsWorkerValues.js +32 -0
  28. package/cjs/synthetics/usr.js +32 -0
  29. package/cjs/tracekit/computeStackTrace.js +73 -563
  30. package/cjs/tracekit/index.js +3 -15
  31. package/cjs/tracekit/tracekit.js +113 -0
  32. package/cjs/transport/batch.js +332 -0
  33. package/cjs/transport/httpRequest.js +112 -0
  34. package/cjs/transport/index.js +29 -0
  35. package/cjs/transport/sendWithRetryStrategy.js +177 -0
  36. package/cjs/transport/startBatchWithReplica.js +24 -0
  37. package/esm/{cookie.js → browser/cookie.js} +4 -35
  38. package/esm/browser/fetchObservable.js +77 -0
  39. package/esm/browser/xhrObservable.js +106 -0
  40. package/esm/configuration/configuration.js +55 -0
  41. package/esm/configuration/transportConfiguration.js +54 -0
  42. package/esm/console/consoleObservable.js +70 -0
  43. package/esm/dataMap.js +26 -21
  44. package/esm/error/trackRuntimeError.js +16 -0
  45. package/esm/helper/catchUserErrors.js +12 -0
  46. package/esm/helper/contextHistory.js +106 -0
  47. package/esm/helper/createEventRateLimiter.js +38 -0
  48. package/esm/helper/deviceInfo.js +6 -25
  49. package/esm/helper/display.js +21 -0
  50. package/esm/helper/enums.js +25 -1
  51. package/esm/helper/errorTools.js +58 -3
  52. package/esm/helper/instrumentMethod.js +81 -0
  53. package/esm/helper/lifeCycle.js +5 -3
  54. package/esm/helper/observable.js +39 -3
  55. package/esm/helper/tools.js +147 -1
  56. package/esm/index.js +17 -7
  57. package/esm/init.js +17 -22
  58. package/esm/report/reportObservable.js +98 -0
  59. package/esm/session/sessionConstants.js +3 -0
  60. package/esm/session/sessionCookieStore.js +168 -0
  61. package/esm/session/sessionManagement.js +78 -0
  62. package/esm/session/sessionStore.js +139 -0
  63. package/esm/synthetics/syntheticsWorkerValues.js +15 -0
  64. package/esm/synthetics/usr.js +18 -0
  65. package/esm/tracekit/computeStackTrace.js +73 -557
  66. package/esm/tracekit/index.js +1 -1
  67. package/esm/tracekit/tracekit.js +103 -0
  68. package/esm/transport/batch.js +316 -0
  69. package/esm/transport/httpRequest.js +104 -0
  70. package/esm/transport/index.js +3 -0
  71. package/esm/transport/sendWithRetryStrategy.js +165 -0
  72. package/esm/transport/startBatchWithReplica.js +15 -0
  73. package/package.json +2 -2
  74. package/src/.DS_Store +0 -0
  75. package/src/{cookie.js → browser/cookie.js} +6 -34
  76. package/src/browser/fetchObservable.js +86 -0
  77. package/src/browser/xhrObservable.js +102 -0
  78. package/src/configuration/configuration.js +61 -0
  79. package/src/configuration/transportConfiguration.js +42 -0
  80. package/src/console/consoleObservable.js +65 -0
  81. package/src/dataMap.js +26 -21
  82. package/src/error/trackRuntimeError.js +19 -0
  83. package/src/helper/catchUserErrors.js +12 -0
  84. package/src/helper/contextHistory.js +85 -0
  85. package/src/helper/createEventRateLimiter.js +37 -0
  86. package/src/helper/deviceInfo.js +5 -51
  87. package/src/helper/display.js +21 -0
  88. package/src/helper/enums.js +38 -14
  89. package/src/helper/errorTools.js +76 -12
  90. package/src/helper/instrumentMethod.js +97 -0
  91. package/src/helper/lifeCycle.js +5 -3
  92. package/src/helper/observable.js +33 -2
  93. package/src/helper/tools.js +135 -4
  94. package/src/index.js +18 -7
  95. package/src/init.js +17 -18
  96. package/src/report/reportObservable.js +113 -0
  97. package/src/session/sessionConstants.js +3 -0
  98. package/src/session/sessionCookieStore.js +159 -0
  99. package/src/session/sessionManagement.js +89 -0
  100. package/src/session/sessionStore.js +139 -0
  101. package/src/synthetics/syntheticsWorkerValues.js +22 -0
  102. package/src/synthetics/usr.js +18 -0
  103. package/src/tracekit/computeStackTrace.js +75 -551
  104. package/src/tracekit/index.js +1 -1
  105. package/src/tracekit/tracekit.js +100 -0
  106. package/src/transport/batch.js +289 -0
  107. package/src/transport/httpRequest.js +109 -0
  108. package/src/transport/index.js +3 -0
  109. package/src/transport/sendWithRetryStrategy.js +186 -0
  110. package/src/transport/startBatchWithReplica.js +26 -0
  111. package/cjs/configuration.js +0 -193
  112. package/cjs/errorCollection.js +0 -167
  113. package/cjs/fetchProxy.js +0 -161
  114. package/cjs/helper/errorFilter.js +0 -47
  115. package/cjs/sessionManagement.js +0 -221
  116. package/cjs/tracekit/report.js +0 -289
  117. package/cjs/transport.js +0 -373
  118. package/cjs/xhrProxy.js +0 -122
  119. package/esm/configuration.js +0 -176
  120. package/esm/errorCollection.js +0 -141
  121. package/esm/fetchProxy.js +0 -115
  122. package/esm/helper/errorFilter.js +0 -38
  123. package/esm/sessionManagement.js +0 -195
  124. package/esm/tracekit/report.js +0 -273
  125. package/esm/transport.js +0 -357
  126. package/esm/xhrProxy.js +0 -110
  127. package/src/configuration.js +0 -161
  128. package/src/errorCollection.js +0 -170
  129. package/src/fetchProxy.js +0 -108
  130. package/src/helper/errorFilter.js +0 -38
  131. package/src/sessionManagement.js +0 -224
  132. package/src/tracekit/report.js +0 -284
  133. package/src/transport.js +0 -380
  134. package/src/xhrProxy.js +0 -106
@@ -5,51 +5,16 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.COOKIE_ACCESS_DELAY = void 0;
7
7
  exports.areCookiesAuthorized = areCookiesAuthorized;
8
- exports.cacheCookieAccess = cacheCookieAccess;
8
+ exports.deleteCookie = deleteCookie;
9
9
  exports.getCookie = getCookie;
10
10
  exports.getCurrentSite = getCurrentSite;
11
11
  exports.setCookie = setCookie;
12
12
 
13
- var _tools = require("./helper/tools");
13
+ var _tools = require("../helper/tools");
14
14
 
15
15
  var COOKIE_ACCESS_DELAY = _tools.ONE_SECOND;
16
16
  exports.COOKIE_ACCESS_DELAY = COOKIE_ACCESS_DELAY;
17
17
 
18
- function cacheCookieAccess(name, options) {
19
- var timeout;
20
- var cache;
21
- var hasCache = false;
22
-
23
- var cacheAccess = function cacheAccess() {
24
- hasCache = true;
25
- window.clearTimeout(timeout);
26
- timeout = window.setTimeout(function () {
27
- hasCache = false;
28
- }, COOKIE_ACCESS_DELAY);
29
- };
30
-
31
- return {
32
- get: function get() {
33
- if (hasCache) {
34
- return cache;
35
- }
36
-
37
- cache = getCookie(name);
38
- cacheAccess();
39
- return cache;
40
- },
41
- set: function set(value, expireDelay) {
42
- setCookie(name, value, expireDelay, options);
43
- cache = value;
44
- cacheAccess();
45
- },
46
- clearCache: function clearCache() {
47
- window.clearTimeout(timeout);
48
- hasCache = false;
49
- }
50
- };
51
- }
52
-
53
18
  function setCookie(name, value, expireDelay, options) {
54
19
  var date = new Date();
55
20
  date.setTime(date.getTime() + expireDelay);
@@ -64,6 +29,10 @@ function getCookie(name) {
64
29
  return (0, _tools.findCommaSeparatedValue)(document.cookie, name);
65
30
  }
66
31
 
32
+ function deleteCookie(name, options) {
33
+ setCookie(name, '', 0, options);
34
+ }
35
+
67
36
  function areCookiesAuthorized(options) {
68
37
  if (document.cookie === undefined || document.cookie === null) {
69
38
  return false;
@@ -0,0 +1,91 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.initFetchObservable = initFetchObservable;
7
+
8
+ var _instrumentMethod = require("../helper/instrumentMethod");
9
+
10
+ var _observable = require("../helper/observable");
11
+
12
+ var _tools = require("../helper/tools");
13
+
14
+ var _urlPolyfill = require("../helper/urlPolyfill");
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); }
17
+
18
+ var fetchObservable;
19
+
20
+ function initFetchObservable() {
21
+ if (!fetchObservable) {
22
+ fetchObservable = createFetchObservable();
23
+ }
24
+
25
+ return fetchObservable;
26
+ }
27
+
28
+ function createFetchObservable() {
29
+ var observable = new _observable.Observable(function () {
30
+ if (!window.fetch) {
31
+ return;
32
+ }
33
+
34
+ var fetchMethod = (0, _instrumentMethod.instrumentMethod)(window, 'fetch', function (originalFetch) {
35
+ return function (input, init) {
36
+ var responsePromise;
37
+ var context = beforeSend(observable, input, init);
38
+
39
+ if (context) {
40
+ responsePromise = originalFetch.call(this, context.input, context.init);
41
+ afterSend(observable, responsePromise, context);
42
+ } else {
43
+ responsePromise = originalFetch.call(this, input, init);
44
+ }
45
+
46
+ return responsePromise;
47
+ };
48
+ });
49
+ return fetchMethod.stop;
50
+ });
51
+ return observable;
52
+ }
53
+
54
+ function beforeSend(observable, input, init) {
55
+ var method = init && init.method || _typeof(input) === 'object' && input.method || 'GET';
56
+ var url = (0, _urlPolyfill.normalizeUrl)(_typeof(input) === 'object' && input.url || input);
57
+ var startClocks = (0, _tools.clocksNow)();
58
+ var context = {
59
+ state: 'start',
60
+ init: init,
61
+ input: input,
62
+ method: method,
63
+ startClocks: startClocks,
64
+ url: url
65
+ };
66
+ observable.notify(context);
67
+ return context;
68
+ }
69
+
70
+ function afterSend(observable, responsePromise, startContext) {
71
+ var reportFetch = function reportFetch(response) {
72
+ var context = startContext;
73
+ context.state = 'complete';
74
+ context.duration = (0, _tools.elapsed)(context.startClocks.timeStamp, (0, _tools.timeStampNow)());
75
+
76
+ if ('stack' in response || response instanceof Error) {
77
+ context.status = 0;
78
+ context.isAborted = response instanceof DOMException && response.code === DOMException.ABORT_ERR;
79
+ context.error = response;
80
+ observable.notify(context);
81
+ } else if ('status' in response) {
82
+ context.response = response;
83
+ context.responseType = response.type;
84
+ context.status = response.status;
85
+ context.isAborted = false;
86
+ observable.notify(context);
87
+ }
88
+ };
89
+
90
+ responsePromise.then(reportFetch, reportFetch);
91
+ }
@@ -0,0 +1,118 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.initXhrObservable = initXhrObservable;
7
+
8
+ var _instrumentMethod = require("../helper/instrumentMethod");
9
+
10
+ var _observable = require("../helper/observable");
11
+
12
+ var _urlPolyfill = require("../helper/urlPolyfill");
13
+
14
+ var _tools = require("../helper/tools");
15
+
16
+ var xhrObservable;
17
+ var xhrContexts = {};
18
+ var DATA_FLUX_REQUEST_ID_KEY = '_DATAFLUX_REQUEST_UUID';
19
+
20
+ function initXhrObservable() {
21
+ if (!xhrObservable) {
22
+ xhrObservable = createXhrObservable();
23
+ }
24
+
25
+ return xhrObservable;
26
+ }
27
+
28
+ function createXhrObservable() {
29
+ var observable = new _observable.Observable(function () {
30
+ var openInstrumentMethod = (0, _instrumentMethod.instrumentMethodAndCallOriginal)(XMLHttpRequest.prototype, 'open', {
31
+ before: openXhr
32
+ });
33
+ var sendInstrumentMethod = (0, _instrumentMethod.instrumentMethodAndCallOriginal)(XMLHttpRequest.prototype, 'send', {
34
+ before: function before() {
35
+ sendXhr.call(this, observable);
36
+ }
37
+ });
38
+ var abortInstrumentMethod = (0, _instrumentMethod.instrumentMethodAndCallOriginal)(XMLHttpRequest.prototype, 'abort', {
39
+ before: abortXhr
40
+ });
41
+ return function () {
42
+ openInstrumentMethod.stop();
43
+ sendInstrumentMethod.stop();
44
+ abortInstrumentMethod.stop();
45
+ };
46
+ });
47
+ return observable;
48
+ }
49
+
50
+ function openXhr(method, url) {
51
+ var requestUUID = this[DATA_FLUX_REQUEST_ID_KEY] || (0, _tools.UUID)();
52
+ this[DATA_FLUX_REQUEST_ID_KEY] = requestUUID;
53
+ xhrContexts[requestUUID] = {
54
+ state: 'open',
55
+ method: method,
56
+ url: (0, _urlPolyfill.normalizeUrl)(String(url))
57
+ };
58
+ }
59
+
60
+ function sendXhr(observable) {
61
+ var context = xhrContexts[this[DATA_FLUX_REQUEST_ID_KEY]];
62
+
63
+ if (!context) {
64
+ return;
65
+ }
66
+
67
+ var startContext = context;
68
+ startContext.state = 'start';
69
+ startContext.startTime = (0, _tools.relativeNow)();
70
+ startContext.startClocks = (0, _tools.clocksNow)();
71
+ startContext.isAborted = false;
72
+ startContext.xhr = this;
73
+ var hasBeenReported = false;
74
+ var onreadyStateChangeInstrumentMethod = (0, _instrumentMethod.instrumentMethodAndCallOriginal)(this, 'onreadystatechange', {
75
+ before: function before() {
76
+ if (this.readyState === XMLHttpRequest.DONE) {
77
+ // Try to report the XHR as soon as possible, because the XHR may be mutated by the
78
+ // application during a future event. For example, Angular is calling .abort() on
79
+ // completed requests during a onreadystatechange event, so the status becomes '0'
80
+ // before the request is collected.
81
+ onEnd.call(this);
82
+ }
83
+ }
84
+ });
85
+
86
+ var onEnd = function onEnd() {
87
+ this.removeEventListener('loadend', onEnd);
88
+ onreadyStateChangeInstrumentMethod.stop();
89
+
90
+ if (hasBeenReported) {
91
+ return;
92
+ }
93
+
94
+ hasBeenReported = true;
95
+ var completeContext = context;
96
+ completeContext.state = 'complete';
97
+ completeContext.duration = (0, _tools.elapsed)(startContext.startClocks.timeStamp, (0, _tools.timeStampNow)());
98
+ completeContext.status = this.status;
99
+ observable.notify((0, _tools.shallowClone)(completeContext));
100
+ clearRequestId.call(this);
101
+ };
102
+
103
+ this.addEventListener('loadend', onEnd);
104
+ observable.notify(startContext);
105
+ }
106
+
107
+ function clearRequestId() {
108
+ delete xhrContexts[this[DATA_FLUX_REQUEST_ID_KEY]];
109
+ delete this[DATA_FLUX_REQUEST_ID_KEY];
110
+ }
111
+
112
+ function abortXhr() {
113
+ var context = xhrContexts[this[DATA_FLUX_REQUEST_ID_KEY]];
114
+
115
+ if (context) {
116
+ context.isAborted = true;
117
+ }
118
+ }
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.buildCookieOptions = buildCookieOptions;
7
+ exports.validateAndBuildConfiguration = validateAndBuildConfiguration;
8
+
9
+ var _cookie = require("../browser/cookie");
10
+
11
+ var _catchUserErrors = require("../helper/catchUserErrors");
12
+
13
+ var _display = require("../helper/display");
14
+
15
+ var _tools = require("../helper/tools");
16
+
17
+ var _transportConfiguration = require("./transportConfiguration");
18
+
19
+ function validateAndBuildConfiguration(initConfiguration) {
20
+ if (initConfiguration.sampleRate !== undefined && !(0, _tools.isPercentage)(initConfiguration.sampleRate)) {
21
+ _display.display.error('Sample Rate should be a number between 0 and 100');
22
+
23
+ return;
24
+ }
25
+
26
+ return (0, _tools.assign)({
27
+ beforeSend: initConfiguration.beforeSend && (0, _catchUserErrors.catchUserErrors)(initConfiguration.beforeSend, 'beforeSend threw an error:'),
28
+ cookieOptions: buildCookieOptions(initConfiguration),
29
+ sampleRate: (0, _tools.isNullUndefinedDefaultValue)(initConfiguration.sampleRate, 100),
30
+ service: initConfiguration.service,
31
+ version: initConfiguration.version,
32
+ env: initConfiguration.env,
33
+ silentMultipleInit: !!initConfiguration.silentMultipleInit,
34
+
35
+ /**
36
+ * beacon payload max queue size implementation is 64kb
37
+ * ensure that we leave room for logs, rum and potential other users
38
+ */
39
+ batchBytesLimit: 16 * _tools.ONE_KIBI_BYTE,
40
+ eventRateLimiterThreshold: 3000,
41
+
42
+ /**
43
+ * flush automatically, aim to be lower than ALB connection timeout
44
+ * to maximize connection reuse.
45
+ */
46
+ flushTimeout: 30 * _tools.ONE_SECOND,
47
+
48
+ /**
49
+ * Logs intake limit
50
+ */
51
+ batchMessagesLimit: 50,
52
+ messageBytesLimit: 256 * _tools.ONE_KIBI_BYTE
53
+ }, (0, _transportConfiguration.computeTransportConfiguration)(initConfiguration));
54
+ }
55
+
56
+ function buildCookieOptions(initConfiguration) {
57
+ var cookieOptions = {};
58
+ cookieOptions.secure = mustUseSecureCookie(initConfiguration);
59
+ cookieOptions.crossSite = !!initConfiguration.useCrossSiteSessionCookie;
60
+
61
+ if (initConfiguration.trackSessionAcrossSubdomains) {
62
+ cookieOptions.domain = (0, _cookie.getCurrentSite)();
63
+ }
64
+
65
+ return cookieOptions;
66
+ }
67
+
68
+ function mustUseSecureCookie(initConfiguration) {
69
+ return !!initConfiguration.useSecureSessionCookie || !!initConfiguration.useCrossSiteSessionCookie;
70
+ }
@@ -0,0 +1,64 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.computeTransportConfiguration = computeTransportConfiguration;
7
+ exports.isIntakeRequest = isIntakeRequest;
8
+
9
+ var _tools = require("../helper/tools");
10
+
11
+ var TRIM_REGIX = /^\s+|\s+$/g;
12
+
13
+ function getDatakitUrl(url) {
14
+ if (url.lastIndexOf('/') === url.length - 1) return trim(url) + 'v1/write/rum';
15
+ return trim(url) + '/v1/write/rum';
16
+ }
17
+
18
+ function trim(str) {
19
+ return str.replace(TRIM_REGIX, '');
20
+ }
21
+
22
+ function getLogsEndPoint(url) {
23
+ if (url.lastIndexOf('/') === url.length - 1) return trim(url) + 'v1/write/logging';
24
+ return trim(url) + '/v1/write/logging';
25
+ }
26
+
27
+ function computeTransportConfiguration(initConfiguration) {
28
+ var isIntakeUrl = function isIntakeUrl(url) {
29
+ return false;
30
+ };
31
+
32
+ if ('isIntakeUrl' in initConfiguration && (0, _tools.isFunction)(initConfiguration.isIntakeUrl) && (0, _tools.isBoolean)(initConfiguration.isIntakeUrl())) {
33
+ isIntakeUrl = initConfiguration.isIntakeUrl;
34
+ }
35
+
36
+ var isServerError = function isServerError(request) {
37
+ return false;
38
+ };
39
+
40
+ if ('isServerError' in initConfiguration && (0, _tools.isFunction)(initConfiguration.isServerError) && (0, _tools.isBoolean)(initConfiguration.isServerError())) {
41
+ isServerError = initConfiguration.isServerError;
42
+ }
43
+
44
+ return {
45
+ datakitUrl: getDatakitUrl(initConfiguration.datakitUrl || initConfiguration.datakitOrigin),
46
+ logsEndpoint: getLogsEndPoint(initConfiguration.datakitOrigin),
47
+ isIntakeUrl: isIntakeUrl,
48
+ isServerError: isServerError
49
+ };
50
+ }
51
+
52
+ function isIntakeRequest(url, configuration) {
53
+ // return haveSameOrigin(url, configuration.datakitUrl)
54
+ var notTakeRequest = [configuration.datakitUrl];
55
+
56
+ if (configuration.logsEndpoint) {
57
+ notTakeRequest.push(configuration.logsEndpoint);
58
+ } // datakit 地址,log 地址,以及客户自定义过滤方法定义url
59
+
60
+
61
+ return (0, _tools.some)(notTakeRequest, function (takeUrl) {
62
+ return url.indexOf(takeUrl) === 0;
63
+ }) || configuration.isIntakeUrl(url);
64
+ }
@@ -0,0 +1,84 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.initConsoleObservable = initConsoleObservable;
7
+
8
+ var _tracekit = require("../tracekit");
9
+
10
+ var _errorTools = require("../helper/errorTools");
11
+
12
+ var _observable = require("../helper/observable");
13
+
14
+ var _tools = require("../helper/tools");
15
+
16
+ var _display = require("../helper/display");
17
+
18
+ var consoleObservablesByApi = {};
19
+
20
+ function initConsoleObservable(apis) {
21
+ var consoleObservables = (0, _tools.map)(apis, function (api) {
22
+ if (!consoleObservablesByApi[api]) {
23
+ consoleObservablesByApi[api] = createConsoleObservable(api);
24
+ }
25
+
26
+ return consoleObservablesByApi[api];
27
+ });
28
+ return _observable.mergeObservables.apply(this, consoleObservables);
29
+ }
30
+ /* eslint-disable no-console */
31
+
32
+
33
+ function createConsoleObservable(api) {
34
+ var observable = new _observable.Observable(function () {
35
+ var originalConsoleApi = console[api];
36
+
37
+ console[api] = function () {
38
+ var params = [].slice.call(arguments);
39
+ originalConsoleApi.apply(console, arguments);
40
+ var handlingStack = (0, _errorTools.createHandlingStack)();
41
+ observable.notify(buildConsoleLog(params, api, handlingStack));
42
+ };
43
+
44
+ return function () {
45
+ console[api] = originalConsoleApi;
46
+ };
47
+ });
48
+ return observable;
49
+ }
50
+
51
+ function buildConsoleLog(params, api, handlingStack) {
52
+ // Todo: remove console error prefix in the next major version
53
+ var message = (0, _tools.map)(params, function (param) {
54
+ return formatConsoleParameters(param);
55
+ }).join(' ');
56
+ var stack;
57
+
58
+ if (api === _display.ConsoleApiName.error) {
59
+ var firstErrorParam = (0, _tools.find)(params, function (param) {
60
+ return param instanceof Error;
61
+ });
62
+ stack = firstErrorParam ? (0, _errorTools.toStackTraceString)((0, _tracekit.computeStackTrace)(firstErrorParam)) : undefined;
63
+ message = 'console error: ' + message;
64
+ }
65
+
66
+ return {
67
+ api: api,
68
+ message: message,
69
+ stack: stack,
70
+ handlingStack: handlingStack
71
+ };
72
+ }
73
+
74
+ function formatConsoleParameters(param) {
75
+ if (typeof param === 'string') {
76
+ return param;
77
+ }
78
+
79
+ if (param instanceof Error) {
80
+ return (0, _errorTools.formatErrorMessage)((0, _tracekit.computeStackTrace)(param));
81
+ }
82
+
83
+ return (0, _tools.jsonStringify)(param, undefined, 2);
84
+ }
package/cjs/dataMap.js CHANGED
@@ -8,12 +8,13 @@ exports.dataMap = exports.commonTags = void 0;
8
8
  var _enums = require("./helper/enums");
9
9
 
10
10
  var commonTags = {
11
+ action_id: 'action.id',
11
12
  sdk_name: '_dd.sdk_name',
12
13
  sdk_version: '_dd.sdk_version',
13
14
  app_id: 'application.id',
14
- env: '_dd.env',
15
- service: '_dd.service',
16
- version: '_dd.version',
15
+ env: 'env',
16
+ service: 'service',
17
+ version: 'version',
17
18
  userid: 'user.id',
18
19
  user_email: 'user.email',
19
20
  user_name: 'user.name',
@@ -101,27 +102,31 @@ var dataMap = {
101
102
  error: {
102
103
  type: _enums.RumEventType.ERROR,
103
104
  tags: {
105
+ error_id: 'error.id',
104
106
  trace_id: '_dd.trace_id',
105
107
  span_id: '_dd.span_id',
106
108
  error_source: 'error.source',
107
109
  error_type: 'error.type',
108
- error_handling: 'error.handling',
109
- resource_url: 'error.resource.url',
110
- resource_url_host: 'error.resource.url_host',
111
- resource_url_path: 'error.resource.url_path',
112
- resource_url_path_group: 'error.resource.url_path_group',
113
- resource_status: 'error.resource.status',
114
- resource_status_group: 'error.resource.status_group',
115
- resource_method: 'error.resource.method'
110
+ error_handling: 'error.handling' // resource_url: 'error.resource.url',
111
+ // resource_url_host: 'error.resource.url_host',
112
+ // resource_url_path: 'error.resource.url_path',
113
+ // resource_url_path_group: 'error.resource.url_path_group',
114
+ // resource_status: 'error.resource.status',
115
+ // resource_status_group: 'error.resource.status_group',
116
+ // resource_method: 'error.resource.method'
117
+
116
118
  },
117
119
  fields: {
118
120
  error_message: ['string', 'error.message'],
119
- error_stack: ['string', 'error.stack']
121
+ error_stack: ['string', 'error.stack'],
122
+ error_causes: ['string', 'error.causes']
120
123
  }
121
124
  },
122
125
  long_task: {
123
126
  type: _enums.RumEventType.LONG_TASK,
124
- tags: {},
127
+ tags: {
128
+ long_task_id: 'long_task.id'
129
+ },
125
130
  fields: {
126
131
  duration: 'long_task.duration'
127
132
  }
@@ -129,7 +134,6 @@ var dataMap = {
129
134
  action: {
130
135
  type: _enums.RumEventType.ACTION,
131
136
  tags: {
132
- action_id: 'action.id',
133
137
  action_name: 'action.target.name',
134
138
  action_type: 'action.type'
135
139
  },
@@ -137,6 +141,7 @@ var dataMap = {
137
141
  duration: 'action.loading_time',
138
142
  action_error_count: 'action.error.count',
139
143
  action_resource_count: 'action.resource.count',
144
+ action_frustration_types: 'action.frustration.type',
140
145
  action_long_task_count: 'action.long_task.count'
141
146
  }
142
147
  },
@@ -145,13 +150,13 @@ var dataMap = {
145
150
  tags: {
146
151
  error_source: 'error.source',
147
152
  error_type: 'error.type',
148
- error_resource_url: 'resource.url',
149
- error_resource_url_host: 'resource.url_host',
150
- error_resource_url_path: 'resource.url_path',
151
- error_resource_url_path_group: 'resource.url_path_group',
152
- error_resource_status: 'resource.status',
153
- error_resource_status_group: 'resource.status_group',
154
- error_resource_method: 'resource.method',
153
+ error_resource_url: 'http.url',
154
+ error_resource_url_host: 'http.url_host',
155
+ error_resource_url_path: 'http.url_path',
156
+ error_resource_url_path_group: 'http.url_path_group',
157
+ error_resource_status: 'http.status_code',
158
+ error_resource_status_group: 'http.status_group',
159
+ error_resource_method: 'http.method',
155
160
  action_id: 'user_action.id',
156
161
  service: 'service',
157
162
  status: 'status'
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.trackRuntimeError = trackRuntimeError;
7
+
8
+ var _errorTools = require("../helper/errorTools");
9
+
10
+ var _tools = require("../helper/tools");
11
+
12
+ var _enums = require("../helper/enums");
13
+
14
+ var _tracekit = require("../tracekit");
15
+
16
+ function trackRuntimeError(errorObservable) {
17
+ return (0, _tracekit.startUnhandledErrorCollection)(function (stackTrace, originalError) {
18
+ errorObservable.notify((0, _errorTools.computeRawError)({
19
+ stackTrace: stackTrace,
20
+ originalError: originalError,
21
+ startClocks: (0, _tools.clocksNow)(),
22
+ nonErrorPrefix: 'Uncaught',
23
+ source: _errorTools.ErrorSource.SOURCE,
24
+ handling: _enums.ErrorHandling.UNHANDLED
25
+ }));
26
+ });
27
+ }
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.catchUserErrors = catchUserErrors;
7
+
8
+ var _display = require("./display");
9
+
10
+ function catchUserErrors(fn, errorMsg) {
11
+ return function () {
12
+ var args = [].slice.call(arguments);
13
+
14
+ try {
15
+ return fn.apply(this, args);
16
+ } catch (err) {
17
+ _display.display.error(errorMsg, err);
18
+ }
19
+ };
20
+ }