@qiu_jun/monitors 0.0.7 → 0.0.8
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 +6 -5
- package/dist/interface/index.d.ts +4 -2
- package/dist/modules/err.js +42 -71
- package/dist/modules/longTask.js +25 -24
- package/dist/modules/paint.js +41 -79
- package/dist/modules/timing.js +24 -37
- package/dist/monitor.d.ts +4 -0
- package/dist/monitor.js +168 -215
- package/dist/monitor.umd.js +1 -1
- package/dist/replay/index.js +111 -151
- package/package.json +2 -2
package/dist/monitor.js
CHANGED
|
@@ -1,218 +1,171 @@
|
|
|
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
|
-
if (this.errorQueue.length === 0)
|
|
171
|
-
return;
|
|
172
|
-
this.send({ type: 'batchXHR', requests: [...this.errorQueue] });
|
|
173
|
-
this.errorQueue = [];
|
|
174
|
-
}
|
|
175
|
-
captureRequest(requestInfo) {
|
|
176
|
-
var _a;
|
|
177
|
-
const validRequestTypes = ['xhr', 'fetch'];
|
|
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 t, r;
|
|
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, "timeoutDuration", {
|
|
23
|
+
enumerable: !0,
|
|
24
|
+
configurable: !0,
|
|
25
|
+
writable: !0,
|
|
26
|
+
value: void 0
|
|
27
|
+
}), Object.defineProperty(this, "errorQueue", {
|
|
28
|
+
enumerable: !0,
|
|
29
|
+
configurable: !0,
|
|
30
|
+
writable: !0,
|
|
31
|
+
value: void 0
|
|
32
|
+
}), Object.defineProperty(this, "requestQueue", {
|
|
33
|
+
enumerable: !0,
|
|
34
|
+
configurable: !0,
|
|
35
|
+
writable: !0,
|
|
36
|
+
value: void 0
|
|
37
|
+
}), Object.defineProperty(this, "maxQueueSize", {
|
|
38
|
+
enumerable: !0,
|
|
39
|
+
configurable: !0,
|
|
40
|
+
writable: !0,
|
|
41
|
+
value: void 0
|
|
42
|
+
}), Object.defineProperty(this, "sendTimer", {
|
|
43
|
+
enumerable: !0,
|
|
44
|
+
configurable: !0,
|
|
45
|
+
writable: !0,
|
|
46
|
+
value: void 0
|
|
47
|
+
}), Object.defineProperty(this, "reporter", {
|
|
48
|
+
enumerable: !0,
|
|
49
|
+
configurable: !0,
|
|
50
|
+
writable: !0,
|
|
51
|
+
value: void 0
|
|
52
|
+
}), Object.defineProperty(this, "replay", {
|
|
53
|
+
enumerable: !0,
|
|
54
|
+
configurable: !0,
|
|
55
|
+
writable: !0,
|
|
56
|
+
value: null
|
|
57
|
+
}), Object.defineProperty(this, "options", {
|
|
58
|
+
enumerable: !0,
|
|
59
|
+
configurable: !0,
|
|
60
|
+
writable: !0,
|
|
61
|
+
value: void 0
|
|
62
|
+
}), Object.defineProperty(this, "errorSentAt", {
|
|
63
|
+
enumerable: !0,
|
|
64
|
+
configurable: !0,
|
|
65
|
+
writable: !0,
|
|
66
|
+
value: new Map
|
|
67
|
+
}), Object.defineProperty(this, "originalXHR", {
|
|
68
|
+
enumerable: !0,
|
|
69
|
+
configurable: !0,
|
|
70
|
+
writable: !0,
|
|
71
|
+
value: void 0
|
|
72
|
+
}), Object.defineProperty(this, "originalFetch", {
|
|
73
|
+
enumerable: !0,
|
|
74
|
+
configurable: !0,
|
|
75
|
+
writable: !0,
|
|
76
|
+
value: void 0
|
|
77
|
+
}), Object.defineProperty(this, "originalOnerror", {
|
|
78
|
+
enumerable: !0,
|
|
79
|
+
configurable: !0,
|
|
80
|
+
writable: !0,
|
|
81
|
+
value: void 0
|
|
82
|
+
}), this.options = e, this.endpoint = e.endpoint, this.projectKey = e.projectKey,
|
|
83
|
+
this.timeoutDuration = null !== (t = e.timeoutDuration) && void 0 !== t ? t : 6e4,
|
|
84
|
+
this.errorQueue = [], this.requestQueue = [], this.maxQueueSize = null !== (r = e.maxQueueSize) && void 0 !== r ? r : 10,
|
|
85
|
+
this.sendTimer = null, this.reporter = (0, exception_1.createReporter)({
|
|
86
|
+
endpoint: e.endpoint,
|
|
87
|
+
projectKey: e.projectKey,
|
|
88
|
+
release: e.release,
|
|
89
|
+
environment: e.environment,
|
|
90
|
+
maxBatch: e.maxBatch,
|
|
91
|
+
flushInterval: e.flushInterval
|
|
92
|
+
}, (0, exception_1.makeH5Transport)(e.endpoint)), this.init(), this.initReplay(),
|
|
93
|
+
this.originalXHR = window.XMLHttpRequest, this.originalFetch = window.fetch, this.originalOnerror = window.onerror;
|
|
94
|
+
}
|
|
95
|
+
init() {
|
|
96
|
+
modules_1.onWindowErr.call(this), modules_1.onLongTask.call(this), modules_1.onPaint.call(this),
|
|
97
|
+
modules_1.onTiming.call(this), modules_1.onXHR.call(this);
|
|
98
|
+
}
|
|
99
|
+
initReplay() {
|
|
100
|
+
var e, t;
|
|
101
|
+
const r = this.options.replay;
|
|
102
|
+
if (!(null == r ? void 0 : r.enabled)) return;
|
|
103
|
+
const i = null !== (e = r.sampleRate) && void 0 !== e ? e : 1;
|
|
104
|
+
if (Math.random() >= i) return;
|
|
105
|
+
const o = null !== (t = r.replayEndpoint) && void 0 !== t ? t : (0, replay_1.deriveReplayEndpoint)(this.endpoint);
|
|
106
|
+
o && (this.replay = new replay_1.ReplayController({
|
|
107
|
+
replayEndpoint: o,
|
|
108
|
+
projectKey: this.projectKey,
|
|
109
|
+
bufferSeconds: r.bufferSeconds,
|
|
110
|
+
maxUploadsPerSession: r.maxUploadsPerSession,
|
|
111
|
+
minUploadIntervalMs: r.minUploadIntervalMs,
|
|
112
|
+
maxReplayBytes: r.maxReplayBytes,
|
|
113
|
+
captureRequest: r.captureRequest,
|
|
114
|
+
maskTextClass: r.maskTextClass
|
|
115
|
+
}), this.replay.start());
|
|
116
|
+
}
|
|
117
|
+
isDuplicateError(e) {
|
|
118
|
+
var t, r;
|
|
119
|
+
const i = null !== (t = this.options.errorDedupeMs) && void 0 !== t ? t : 0;
|
|
120
|
+
if (i <= 0 || "error" !== e.type) return !1;
|
|
121
|
+
const o = `${e.errorType}|${e.message}|${null !== (r = e.filename) && void 0 !== r ? r : ""}`, n = Date.now(), s = this.errorSentAt.get(o);
|
|
122
|
+
if (void 0 !== s && n - s < i) return !0;
|
|
123
|
+
if (this.errorSentAt.size >= 100) for (const [e, t] of this.errorSentAt) n - t >= i && this.errorSentAt.delete(e);
|
|
124
|
+
return this.errorSentAt.set(o, n), !1;
|
|
125
|
+
}
|
|
126
|
+
send(e) {
|
|
127
|
+
var t;
|
|
128
|
+
if (this.isDuplicateError(e)) return;
|
|
129
|
+
const r = (0, index_1.getLogBaseData)(), i = (0, toExcEvent_1.toExcEvents)(e, r, this.options), o = null === (t = this.replay) || void 0 === t ? void 0 : t.captureIfTriggered(e);
|
|
130
|
+
if (o) for (const e of i) e.device = {
|
|
131
|
+
...e.device,
|
|
132
|
+
replayId: o
|
|
133
|
+
};
|
|
134
|
+
for (const e of i) this.reporter.capture(e);
|
|
135
|
+
}
|
|
136
|
+
capture(e) {
|
|
137
|
+
this.reporter.capture(e);
|
|
138
|
+
}
|
|
139
|
+
reportRequest() {
|
|
140
|
+
0 !== this.requestQueue.length && (this.send({
|
|
141
|
+
type: "batchXHR",
|
|
142
|
+
requests: [ ...this.requestQueue ]
|
|
143
|
+
}), this.requestQueue = []);
|
|
144
|
+
}
|
|
145
|
+
reportError() {
|
|
146
|
+
0 !== this.errorQueue.length && (this.send({
|
|
147
|
+
type: "batchXHR",
|
|
148
|
+
requests: [ ...this.errorQueue ]
|
|
149
|
+
}), this.errorQueue = []);
|
|
150
|
+
}
|
|
151
|
+
captureRequest(e) {
|
|
152
|
+
var t;
|
|
153
|
+
if (!e.type || ![ "xhr", "fetch" ].includes(e.type)) return;
|
|
154
|
+
if ((0, toExcEvent_1.isExceptionReportUrl)(String(null !== (t = e.url) && void 0 !== t ? t : ""), this.endpoint)) return;
|
|
155
|
+
const r = [ "url", "method", "duration", "status", "success", "startTime" ];
|
|
156
|
+
for (const t of r) if (void 0 === e[t]) return;
|
|
157
|
+
e.page = window.location.href, this.requestQueue.push(e), this.requestQueue.length >= this.maxQueueSize && this.reportRequest();
|
|
158
|
+
}
|
|
159
|
+
sendQueuedData() {
|
|
160
|
+
this.errorQueue.length > 0 && this.reportError(), this.requestQueue.length > 0 && this.reportRequest();
|
|
161
|
+
}
|
|
162
|
+
destroy() {
|
|
163
|
+
var e;
|
|
164
|
+
null === (e = this.replay) || void 0 === e || e.stop(), this.sendQueuedData(), this.reporter.destroy(),
|
|
165
|
+
window.XMLHttpRequest = this.originalXHR, window.fetch = this.originalFetch, window.onerror = this.originalOnerror,
|
|
166
|
+
this.sendTimer && (clearInterval(this.sendTimer), this.sendTimer = null), this.errorQueue = [],
|
|
167
|
+
this.requestQueue = [], this.errorSentAt.clear();
|
|
168
|
+
}
|
|
217
169
|
}
|
|
218
|
-
|
|
170
|
+
|
|
171
|
+
exports.default = Monitor;
|