@qiu_jun/monitors 0.0.7 → 0.0.9
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 +16 -6
- package/dist/exception/reporter.d.ts +1 -1
- package/dist/exception/reporter.js +5 -3
- package/dist/exception/types.d.ts +3 -0
- package/dist/interface/index.d.ts +11 -2
- package/dist/miniprogram.d.ts +2 -0
- package/dist/miniprogram.js +16 -4
- package/dist/modules/err.js +42 -71
- package/dist/modules/fetch.d.ts +1 -0
- package/dist/modules/fetch.js +85 -0
- package/dist/modules/index.d.ts +1 -0
- package/dist/modules/index.js +3 -1
- package/dist/modules/longTask.js +25 -24
- package/dist/modules/paint.js +41 -79
- package/dist/modules/timing.js +24 -37
- package/dist/modules/xhr.js +53 -18
- package/dist/monitor.d.ts +8 -0
- package/dist/monitor.js +178 -215
- package/dist/monitor.umd.js +1 -1
- package/dist/replay/index.js +111 -151
- package/dist/utils/businessError.d.ts +10 -0
- package/dist/utils/businessError.js +31 -0
- package/dist/utils/toExcEvent.js +6 -3
- package/package.json +2 -2
package/dist/modules/timing.js
CHANGED
|
@@ -1,43 +1,30 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
exports.default = onTiming;
|
|
4
|
-
/** 采集并上报页面加载时序(DOMContentLoaded / load) */
|
|
2
|
+
|
|
5
3
|
function reportTiming() {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
if (
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
const navigationEntry = perfEntries[0];
|
|
13
|
-
const { domContentLoadedEventStart, loadEventStart, fetchStart } = navigationEntry;
|
|
14
|
-
DOMContentLoadedTime = domContentLoadedEventStart - fetchStart;
|
|
15
|
-
loadTime = loadEventStart - fetchStart;
|
|
16
|
-
}
|
|
4
|
+
let t = 0, e = 0;
|
|
5
|
+
if (performance.getEntriesByType) {
|
|
6
|
+
const n = performance.getEntriesByType("navigation");
|
|
7
|
+
if (n.length > 0) {
|
|
8
|
+
const o = n[0], {domContentLoadedEventStart: i, loadEventStart: r, fetchStart: a} = o;
|
|
9
|
+
t = i - a, e = r - a;
|
|
17
10
|
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
console.log('[monitor] timing 上报', log);
|
|
29
|
-
this.send(log);
|
|
11
|
+
} else {
|
|
12
|
+
const {fetchStart: n, domContentLoadedEventStart: o, loadEventStart: i} = performance.timing;
|
|
13
|
+
t = o - n, e = i - n;
|
|
14
|
+
}
|
|
15
|
+
const n = {
|
|
16
|
+
type: "timing",
|
|
17
|
+
DOMContentLoadedTime: t,
|
|
18
|
+
loadTime: e
|
|
19
|
+
};
|
|
20
|
+
this.send(n);
|
|
30
21
|
}
|
|
31
|
-
|
|
32
|
-
* 监听页面加载时序。
|
|
33
|
-
* 若 SDK 在 window.load 之后才初始化,直接补报,避免永远收不到 timing。
|
|
34
|
-
*/
|
|
22
|
+
|
|
35
23
|
function onTiming() {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
console.log('[monitor] 页面已 load 完成,立即补报 timing');
|
|
39
|
-
run();
|
|
40
|
-
return;
|
|
41
|
-
}
|
|
42
|
-
window.addEventListener('load', run);
|
|
24
|
+
const t = () => reportTiming.call(this);
|
|
25
|
+
"complete" !== document.readyState ? window.addEventListener("load", t) : t();
|
|
43
26
|
}
|
|
27
|
+
|
|
28
|
+
Object.defineProperty(exports, "__esModule", {
|
|
29
|
+
value: !0
|
|
30
|
+
}), exports.default = onTiming;
|
package/dist/modules/xhr.js
CHANGED
|
@@ -1,6 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.default = onXHR;
|
|
4
|
+
const businessError_1 = require("../utils/businessError");
|
|
5
|
+
/** 读取 XHR 响应体:responseType 非 text/json 时访问 responseText 会抛 InvalidStateError,读不到返回 undefined */
|
|
6
|
+
function readXhrBody(xhr) {
|
|
7
|
+
try {
|
|
8
|
+
if (xhr.responseType === '' || xhr.responseType === 'text')
|
|
9
|
+
return xhr.responseText;
|
|
10
|
+
return xhr.responseType === 'json' ? xhr.response : undefined;
|
|
11
|
+
}
|
|
12
|
+
catch (_a) {
|
|
13
|
+
return undefined;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
4
16
|
function onXHR() {
|
|
5
17
|
const originalXHR = window.XMLHttpRequest;
|
|
6
18
|
// @ts-ignore
|
|
@@ -56,24 +68,47 @@ function onXHR() {
|
|
|
56
68
|
startTime: new Date().getTime()
|
|
57
69
|
});
|
|
58
70
|
});
|
|
59
|
-
//
|
|
60
|
-
//
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
71
|
+
// 请求完成:HTTP >= 400 与业务错误(HTTP 2xx 但响应体 code 非成功)。
|
|
72
|
+
// error/timeout 后 loadend 也会触发,但那时 status 为 0,走不进下面任一分支,不会重复上报
|
|
73
|
+
xhr.addEventListener('loadend', function () {
|
|
74
|
+
var _a;
|
|
75
|
+
const duration = new Date().getTime() - startTime;
|
|
76
|
+
const status = xhr.status;
|
|
77
|
+
const urlStr = String(reqUrl !== null && reqUrl !== void 0 ? reqUrl : '');
|
|
78
|
+
if (_this.endpoint && urlStr === _this.endpoint)
|
|
79
|
+
return;
|
|
80
|
+
// HTTP 层失败(4xx/5xx)
|
|
81
|
+
if (status >= 400) {
|
|
82
|
+
_this.captureRequest({
|
|
83
|
+
type: 'xhr',
|
|
84
|
+
url: reqUrl,
|
|
85
|
+
method: reqMethod || 'GET',
|
|
86
|
+
msg: `XHR请求失败: 状态码 ${status}`,
|
|
87
|
+
duration,
|
|
88
|
+
status,
|
|
89
|
+
success: false,
|
|
90
|
+
startTime
|
|
91
|
+
});
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
// 业务错误:需配置 isBusinessError 才会读响应体判定
|
|
95
|
+
if (status >= 200 && status < 300 && _this.isBusinessError) {
|
|
96
|
+
const business = (0, businessError_1.detectBusinessError)(readXhrBody(xhr), _this.isBusinessError);
|
|
97
|
+
if (business) {
|
|
98
|
+
_this.captureRequest({
|
|
99
|
+
type: 'xhr',
|
|
100
|
+
url: reqUrl,
|
|
101
|
+
method: reqMethod || 'GET',
|
|
102
|
+
msg: `XHR业务错误: ${(_a = business.message) !== null && _a !== void 0 ? _a : urlStr}`,
|
|
103
|
+
duration,
|
|
104
|
+
status,
|
|
105
|
+
success: false,
|
|
106
|
+
business,
|
|
107
|
+
startTime
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
});
|
|
77
112
|
return originalSend.apply(this, arguments);
|
|
78
113
|
};
|
|
79
114
|
return xhr;
|
package/dist/monitor.d.ts
CHANGED
|
@@ -6,6 +6,10 @@ export default class Monitor {
|
|
|
6
6
|
endpoint: string;
|
|
7
7
|
/** 接入项目 projectKey */
|
|
8
8
|
projectKey: string;
|
|
9
|
+
/** 回放上传地址(fetch 拦截排除用,未开启回放为空) */
|
|
10
|
+
replayEndpoint: string;
|
|
11
|
+
/** 业务错误判定:HTTP 2xx 但响应体 code 非成功时上报(XHR/fetch/wx.request) */
|
|
12
|
+
isBusinessError?: (body: unknown) => boolean;
|
|
9
13
|
timeoutDuration: number;
|
|
10
14
|
errorQueue: RequestLog[];
|
|
11
15
|
requestQueue: RequestLog[];
|
|
@@ -14,6 +18,8 @@ export default class Monitor {
|
|
|
14
18
|
reporter: ExcReporter;
|
|
15
19
|
private replay;
|
|
16
20
|
private readonly options;
|
|
21
|
+
/** errorDedupeMs 去重状态:errorType|message|filename → 上次放行时间 */
|
|
22
|
+
private errorSentAt;
|
|
17
23
|
originalXHR: {
|
|
18
24
|
new (): XMLHttpRequest;
|
|
19
25
|
prototype: XMLHttpRequest;
|
|
@@ -32,6 +38,8 @@ export default class Monitor {
|
|
|
32
38
|
init(): void;
|
|
33
39
|
/** 回放初始化:显式开启 + 采样命中 + 回放地址可解析 */
|
|
34
40
|
private initReplay;
|
|
41
|
+
/** errorDedupeMs 窗口内同类错误(errorType+message+filename 相同)直接丢弃,连回放触发一并跳过;只在放行时刷新时间戳(非滑动窗口),与 minUploadIntervalMs 的节奏一致 */
|
|
42
|
+
private isDuplicateError;
|
|
35
43
|
/** 统一上报:转异常平台格式 → reporter 批量 POST;错误触发回放切片上传并回填 device.replayId */
|
|
36
44
|
send(data: MonitorTypeLog): void;
|
|
37
45
|
/** 手动上报自定义事件 */
|
package/dist/monitor.js
CHANGED
|
@@ -1,218 +1,181 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const replay_1 = require("./replay");
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: !0
|
|
5
|
+
});
|
|
6
|
+
|
|
7
|
+
const exception_1 = require("./exception"), modules_1 = require("./modules"), index_1 = require("./utils/index"), toExcEvent_1 = require("./utils/toExcEvent"), replay_1 = require("./replay");
|
|
8
|
+
|
|
8
9
|
class Monitor {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
reportError()
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
if (!requestInfo.type || !validRequestTypes.includes(requestInfo.type)) {
|
|
179
|
-
console.warn(`监控系统: 无效的请求类型 ${requestInfo.type},无法上报`);
|
|
180
|
-
return;
|
|
181
|
-
}
|
|
182
|
-
if ((0, toExcEvent_1.isExceptionReportUrl)(String((_a = requestInfo.url) !== null && _a !== void 0 ? _a : ''), this.endpoint))
|
|
183
|
-
return;
|
|
184
|
-
const requiredFields = ['url', 'method', 'duration', 'status', 'success', 'startTime'];
|
|
185
|
-
for (const field of requiredFields) {
|
|
186
|
-
if (requestInfo[field] === undefined) {
|
|
187
|
-
console.warn(`监控系统: 请求信息中缺少必填字段 ${field},无法上报`);
|
|
188
|
-
return;
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
requestInfo.page = window.location.href;
|
|
192
|
-
this.requestQueue.push(requestInfo);
|
|
193
|
-
if (this.requestQueue.length >= this.maxQueueSize)
|
|
194
|
-
this.reportRequest();
|
|
195
|
-
}
|
|
196
|
-
sendQueuedData() {
|
|
197
|
-
if (this.errorQueue.length > 0)
|
|
198
|
-
this.reportError();
|
|
199
|
-
if (this.requestQueue.length > 0)
|
|
200
|
-
this.reportRequest();
|
|
201
|
-
}
|
|
202
|
-
destroy() {
|
|
203
|
-
var _a;
|
|
204
|
-
(_a = this.replay) === null || _a === void 0 ? void 0 : _a.stop();
|
|
205
|
-
this.sendQueuedData();
|
|
206
|
-
this.reporter.destroy();
|
|
207
|
-
window.XMLHttpRequest = this.originalXHR;
|
|
208
|
-
window.fetch = this.originalFetch;
|
|
209
|
-
window.onerror = this.originalOnerror;
|
|
210
|
-
if (this.sendTimer) {
|
|
211
|
-
clearInterval(this.sendTimer);
|
|
212
|
-
this.sendTimer = null;
|
|
213
|
-
}
|
|
214
|
-
this.errorQueue = [];
|
|
215
|
-
this.requestQueue = [];
|
|
216
|
-
}
|
|
10
|
+
constructor(e) {
|
|
11
|
+
var r, t;
|
|
12
|
+
Object.defineProperty(this, "endpoint", {
|
|
13
|
+
enumerable: !0,
|
|
14
|
+
configurable: !0,
|
|
15
|
+
writable: !0,
|
|
16
|
+
value: void 0
|
|
17
|
+
}), Object.defineProperty(this, "projectKey", {
|
|
18
|
+
enumerable: !0,
|
|
19
|
+
configurable: !0,
|
|
20
|
+
writable: !0,
|
|
21
|
+
value: void 0
|
|
22
|
+
}), Object.defineProperty(this, "replayEndpoint", {
|
|
23
|
+
enumerable: !0,
|
|
24
|
+
configurable: !0,
|
|
25
|
+
writable: !0,
|
|
26
|
+
value: ""
|
|
27
|
+
}), Object.defineProperty(this, "isBusinessError", {
|
|
28
|
+
enumerable: !0,
|
|
29
|
+
configurable: !0,
|
|
30
|
+
writable: !0,
|
|
31
|
+
value: void 0
|
|
32
|
+
}), Object.defineProperty(this, "timeoutDuration", {
|
|
33
|
+
enumerable: !0,
|
|
34
|
+
configurable: !0,
|
|
35
|
+
writable: !0,
|
|
36
|
+
value: void 0
|
|
37
|
+
}), Object.defineProperty(this, "errorQueue", {
|
|
38
|
+
enumerable: !0,
|
|
39
|
+
configurable: !0,
|
|
40
|
+
writable: !0,
|
|
41
|
+
value: void 0
|
|
42
|
+
}), Object.defineProperty(this, "requestQueue", {
|
|
43
|
+
enumerable: !0,
|
|
44
|
+
configurable: !0,
|
|
45
|
+
writable: !0,
|
|
46
|
+
value: void 0
|
|
47
|
+
}), Object.defineProperty(this, "maxQueueSize", {
|
|
48
|
+
enumerable: !0,
|
|
49
|
+
configurable: !0,
|
|
50
|
+
writable: !0,
|
|
51
|
+
value: void 0
|
|
52
|
+
}), Object.defineProperty(this, "sendTimer", {
|
|
53
|
+
enumerable: !0,
|
|
54
|
+
configurable: !0,
|
|
55
|
+
writable: !0,
|
|
56
|
+
value: void 0
|
|
57
|
+
}), Object.defineProperty(this, "reporter", {
|
|
58
|
+
enumerable: !0,
|
|
59
|
+
configurable: !0,
|
|
60
|
+
writable: !0,
|
|
61
|
+
value: void 0
|
|
62
|
+
}), Object.defineProperty(this, "replay", {
|
|
63
|
+
enumerable: !0,
|
|
64
|
+
configurable: !0,
|
|
65
|
+
writable: !0,
|
|
66
|
+
value: null
|
|
67
|
+
}), Object.defineProperty(this, "options", {
|
|
68
|
+
enumerable: !0,
|
|
69
|
+
configurable: !0,
|
|
70
|
+
writable: !0,
|
|
71
|
+
value: void 0
|
|
72
|
+
}), Object.defineProperty(this, "errorSentAt", {
|
|
73
|
+
enumerable: !0,
|
|
74
|
+
configurable: !0,
|
|
75
|
+
writable: !0,
|
|
76
|
+
value: new Map
|
|
77
|
+
}), Object.defineProperty(this, "originalXHR", {
|
|
78
|
+
enumerable: !0,
|
|
79
|
+
configurable: !0,
|
|
80
|
+
writable: !0,
|
|
81
|
+
value: void 0
|
|
82
|
+
}), Object.defineProperty(this, "originalFetch", {
|
|
83
|
+
enumerable: !0,
|
|
84
|
+
configurable: !0,
|
|
85
|
+
writable: !0,
|
|
86
|
+
value: void 0
|
|
87
|
+
}), Object.defineProperty(this, "originalOnerror", {
|
|
88
|
+
enumerable: !0,
|
|
89
|
+
configurable: !0,
|
|
90
|
+
writable: !0,
|
|
91
|
+
value: void 0
|
|
92
|
+
}), this.options = e, this.endpoint = e.endpoint, this.projectKey = e.projectKey,
|
|
93
|
+
this.isBusinessError = e.isBusinessError, this.timeoutDuration = null !== (r = e.timeoutDuration) && void 0 !== r ? r : 6e4,
|
|
94
|
+
this.errorQueue = [], this.requestQueue = [], this.maxQueueSize = null !== (t = e.maxQueueSize) && void 0 !== t ? t : 10,
|
|
95
|
+
this.sendTimer = null, this.originalXHR = window.XMLHttpRequest, this.originalFetch = window.fetch,
|
|
96
|
+
this.originalOnerror = window.onerror, this.reporter = (0, exception_1.createReporter)({
|
|
97
|
+
endpoint: e.endpoint,
|
|
98
|
+
projectKey: e.projectKey,
|
|
99
|
+
release: e.release,
|
|
100
|
+
environment: e.environment,
|
|
101
|
+
maxBatch: e.maxBatch,
|
|
102
|
+
flushInterval: e.flushInterval
|
|
103
|
+
}, (0, exception_1.makeH5Transport)(e.endpoint)), this.init(), this.initReplay();
|
|
104
|
+
}
|
|
105
|
+
init() {
|
|
106
|
+
modules_1.onWindowErr.call(this), modules_1.onLongTask.call(this), modules_1.onPaint.call(this),
|
|
107
|
+
modules_1.onTiming.call(this), modules_1.onXHR.call(this), modules_1.onFetch.call(this);
|
|
108
|
+
}
|
|
109
|
+
initReplay() {
|
|
110
|
+
var e, r;
|
|
111
|
+
const t = this.options.replay;
|
|
112
|
+
if (!(null == t ? void 0 : t.enabled)) return;
|
|
113
|
+
const i = null !== (e = t.sampleRate) && void 0 !== e ? e : 1;
|
|
114
|
+
if (Math.random() >= i) return;
|
|
115
|
+
const o = null !== (r = t.replayEndpoint) && void 0 !== r ? r : (0, replay_1.deriveReplayEndpoint)(this.endpoint);
|
|
116
|
+
o && (this.replayEndpoint = o, this.replay = new replay_1.ReplayController({
|
|
117
|
+
replayEndpoint: o,
|
|
118
|
+
projectKey: this.projectKey,
|
|
119
|
+
bufferSeconds: t.bufferSeconds,
|
|
120
|
+
maxUploadsPerSession: t.maxUploadsPerSession,
|
|
121
|
+
minUploadIntervalMs: t.minUploadIntervalMs,
|
|
122
|
+
maxReplayBytes: t.maxReplayBytes,
|
|
123
|
+
captureRequest: t.captureRequest,
|
|
124
|
+
maskTextClass: t.maskTextClass
|
|
125
|
+
}), this.replay.start());
|
|
126
|
+
}
|
|
127
|
+
isDuplicateError(e) {
|
|
128
|
+
var r, t;
|
|
129
|
+
const i = null !== (r = this.options.errorDedupeMs) && void 0 !== r ? r : 0;
|
|
130
|
+
if (i <= 0 || "error" !== e.type) return !1;
|
|
131
|
+
const o = `${e.errorType}|${e.message}|${null !== (t = e.filename) && void 0 !== t ? t : ""}`, n = Date.now(), s = this.errorSentAt.get(o);
|
|
132
|
+
if (void 0 !== s && n - s < i) return !0;
|
|
133
|
+
if (this.errorSentAt.size >= 100) for (const [e, r] of this.errorSentAt) n - r >= i && this.errorSentAt.delete(e);
|
|
134
|
+
return this.errorSentAt.set(o, n), !1;
|
|
135
|
+
}
|
|
136
|
+
send(e) {
|
|
137
|
+
var r;
|
|
138
|
+
if (this.isDuplicateError(e)) return;
|
|
139
|
+
const t = (0, index_1.getLogBaseData)(), i = (0, toExcEvent_1.toExcEvents)(e, t, this.options), o = null === (r = this.replay) || void 0 === r ? void 0 : r.captureIfTriggered(e);
|
|
140
|
+
if (o) for (const e of i) e.device = {
|
|
141
|
+
...e.device,
|
|
142
|
+
replayId: o
|
|
143
|
+
};
|
|
144
|
+
for (const e of i) this.reporter.capture(e);
|
|
145
|
+
}
|
|
146
|
+
capture(e) {
|
|
147
|
+
this.reporter.capture(e);
|
|
148
|
+
}
|
|
149
|
+
reportRequest() {
|
|
150
|
+
0 !== this.requestQueue.length && (this.send({
|
|
151
|
+
type: "batchXHR",
|
|
152
|
+
requests: [ ...this.requestQueue ]
|
|
153
|
+
}), this.requestQueue = []);
|
|
154
|
+
}
|
|
155
|
+
reportError() {
|
|
156
|
+
0 !== this.errorQueue.length && (this.send({
|
|
157
|
+
type: "batchXHR",
|
|
158
|
+
requests: [ ...this.errorQueue ]
|
|
159
|
+
}), this.errorQueue = []);
|
|
160
|
+
}
|
|
161
|
+
captureRequest(e) {
|
|
162
|
+
var r;
|
|
163
|
+
if (!e.type || ![ "xhr", "fetch" ].includes(e.type)) return;
|
|
164
|
+
if ((0, toExcEvent_1.isExceptionReportUrl)(String(null !== (r = e.url) && void 0 !== r ? r : ""), this.endpoint)) return;
|
|
165
|
+
const t = [ "url", "method", "duration", "status", "success", "startTime" ];
|
|
166
|
+
for (const r of t) if (void 0 === e[r]) return;
|
|
167
|
+
e.page = window.location.href, this.requestQueue.push(e), this.requestQueue.length >= this.maxQueueSize && this.reportRequest();
|
|
168
|
+
}
|
|
169
|
+
sendQueuedData() {
|
|
170
|
+
this.errorQueue.length > 0 && this.reportError(), this.requestQueue.length > 0 && this.reportRequest();
|
|
171
|
+
}
|
|
172
|
+
destroy() {
|
|
173
|
+
var e;
|
|
174
|
+
null === (e = this.replay) || void 0 === e || e.stop(), this.sendQueuedData(), this.reporter.destroy(),
|
|
175
|
+
window.XMLHttpRequest = this.originalXHR, window.fetch = this.originalFetch, window.onerror = this.originalOnerror,
|
|
176
|
+
this.sendTimer && (clearInterval(this.sendTimer), this.sendTimer = null), this.errorQueue = [],
|
|
177
|
+
this.requestQueue = [], this.errorSentAt.clear();
|
|
178
|
+
}
|
|
217
179
|
}
|
|
218
|
-
|
|
180
|
+
|
|
181
|
+
exports.default = Monitor;
|