@lark-sentry/core 1.0.0 → 1.0.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/dist/index.cjs +104 -66
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +105 -67
- package/dist/index.js.map +1 -1
- package/dist/index.min.cjs +5 -5
- package/dist/index.min.cjs.map +1 -1
- package/dist/index.min.js +5 -5
- package/dist/index.min.js.map +1 -1
- package/index.ts +70 -0
- package/package.json +5 -21
- package/package.prod.json +39 -0
- package/src/breadcrumb.ts +26 -0
- package/src/bus.ts +31 -0
- package/src/decorate-publish.ts +276 -0
- package/src/handlers.ts +230 -0
- package/src/setup.ts +48 -0
- package/src/white-screen.ts +146 -0
package/dist/index.d.cts
CHANGED
|
@@ -7,6 +7,6 @@ declare const vuePlugin: Plugin;
|
|
|
7
7
|
declare class ReactErrorBoundary extends Component {
|
|
8
8
|
componentDidCatch(error: Error, errorInfo: ErrorInfo): void;
|
|
9
9
|
}
|
|
10
|
-
declare function use<T extends SentryPlugin, U =
|
|
10
|
+
declare function use<T extends SentryPlugin, U = unknown>(Plugin: new (options?: U) => T, options?: U): void;
|
|
11
11
|
|
|
12
12
|
export { ReactErrorBoundary, init, use, vuePlugin };
|
package/dist/index.d.ts
CHANGED
|
@@ -7,6 +7,6 @@ declare const vuePlugin: Plugin;
|
|
|
7
7
|
declare class ReactErrorBoundary extends Component {
|
|
8
8
|
componentDidCatch(error: Error, errorInfo: ErrorInfo): void;
|
|
9
9
|
}
|
|
10
|
-
declare function use<T extends SentryPlugin, U =
|
|
10
|
+
declare function use<T extends SentryPlugin, U = unknown>(Plugin: new (options?: U) => T, options?: U): void;
|
|
11
11
|
|
|
12
12
|
export { ReactErrorBoundary, init, use, vuePlugin };
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { MinHeap, sentry, getCssSelectors, getTime, isErrorEvent, isIExtendedErrorEvent, event2breadcrumb, isError, base64v2, transformHttpData, dom2str, decorateProp, isExcludedApi, throttle } from '@lark-sentry/utils';
|
|
2
|
-
import { WHITE_SCREEN_SAMPLE_INTERVAL, MAX_WHITE_SCREEN_SAMPLE_COUNT, UNKNOWN, DEFAULT_OPTIONS } from '@lark-sentry/constants';
|
|
3
1
|
import { Status, EventType, HttpMethod, HttpStatusCode } from '@lark-sentry/types';
|
|
2
|
+
import { MinHeap, sentry, getCssSelectors, getBaseData, isErrorEvent, isIExtendedErrorEvent, event2breadcrumb, isError, base64v2, transformHttpData, dom2str, decorateProp, isExcludedApi, throttle } from '@lark-sentry/utils';
|
|
3
|
+
import { WHITE_SCREEN_SAMPLE_INTERVAL, MAX_WHITE_SCREEN_SAMPLE_COUNT, UNKNOWN, DEFAULT_OPTIONS } from '@lark-sentry/constants';
|
|
4
4
|
import reporter from '@lark-sentry/reporter';
|
|
5
|
+
import { EventType as EventType$1 } from '@lark-sentry/types/dist/index.cjs';
|
|
5
6
|
|
|
6
7
|
var __typeError = (msg) => {
|
|
7
8
|
throw TypeError(msg);
|
|
@@ -96,12 +97,12 @@ function checkWhiteScreen(onReport) {
|
|
|
96
97
|
};
|
|
97
98
|
const report = () => {
|
|
98
99
|
const whiteScreenData = {
|
|
99
|
-
...
|
|
100
|
+
...getBaseData(),
|
|
100
101
|
type: EventType.WhiteScreen,
|
|
101
102
|
status: Status.Error,
|
|
102
|
-
id: crypto.randomUUID(),
|
|
103
103
|
name: "WhiteScreen",
|
|
104
|
-
message: `sample count ${sampleCount}
|
|
104
|
+
message: `sample count ${sampleCount}`,
|
|
105
|
+
extra: "WhiteScreen"
|
|
105
106
|
};
|
|
106
107
|
onReport(whiteScreenData);
|
|
107
108
|
stopSample();
|
|
@@ -144,7 +145,7 @@ const handleHttp = (data) => {
|
|
|
144
145
|
const { id, name, time, timestamp, message, status, type } = data;
|
|
145
146
|
if (!data.api.includes(sentry.options.dsn)) {
|
|
146
147
|
breadcrumb.push({
|
|
147
|
-
id
|
|
148
|
+
id,
|
|
148
149
|
name,
|
|
149
150
|
time,
|
|
150
151
|
timestamp,
|
|
@@ -158,7 +159,10 @@ const handleHttp = (data) => {
|
|
|
158
159
|
reporter.send(data);
|
|
159
160
|
}
|
|
160
161
|
};
|
|
161
|
-
const handleError$1 = (
|
|
162
|
+
const handleError$1 = ({
|
|
163
|
+
extra: err,
|
|
164
|
+
...rest
|
|
165
|
+
}) => {
|
|
162
166
|
if (isErrorEvent(err)) {
|
|
163
167
|
handleCodeError(err);
|
|
164
168
|
}
|
|
@@ -166,10 +170,9 @@ const handleError$1 = (err) => {
|
|
|
166
170
|
const { localName, src, href } = err.target;
|
|
167
171
|
const { message } = err;
|
|
168
172
|
const resourceError = {
|
|
169
|
-
|
|
173
|
+
...rest,
|
|
170
174
|
type: EventType.Resource,
|
|
171
175
|
status: Status.Error,
|
|
172
|
-
...getTime(),
|
|
173
176
|
name: localName,
|
|
174
177
|
src,
|
|
175
178
|
href,
|
|
@@ -185,12 +188,12 @@ const handleError$1 = (err) => {
|
|
|
185
188
|
if (isError(err)) {
|
|
186
189
|
const { name, message } = err;
|
|
187
190
|
const data2 = {
|
|
188
|
-
|
|
191
|
+
...rest,
|
|
189
192
|
type: EventType.Error,
|
|
190
193
|
name,
|
|
191
194
|
message,
|
|
192
195
|
status: Status.Error,
|
|
193
|
-
|
|
196
|
+
extra: err
|
|
194
197
|
};
|
|
195
198
|
breadcrumb.push({
|
|
196
199
|
...data2,
|
|
@@ -200,12 +203,12 @@ const handleError$1 = (err) => {
|
|
|
200
203
|
return;
|
|
201
204
|
}
|
|
202
205
|
const data = {
|
|
203
|
-
|
|
206
|
+
...rest,
|
|
204
207
|
type: EventType.Error,
|
|
205
208
|
name: "Unknown Error",
|
|
206
209
|
message: JSON.stringify(err),
|
|
207
210
|
status: Status.Error,
|
|
208
|
-
|
|
211
|
+
extra: err
|
|
209
212
|
};
|
|
210
213
|
breadcrumb.push({
|
|
211
214
|
...data,
|
|
@@ -213,78 +216,79 @@ const handleError$1 = (err) => {
|
|
|
213
216
|
});
|
|
214
217
|
reporter.send(data);
|
|
215
218
|
};
|
|
216
|
-
const handleHistory = (
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
219
|
+
const handleHistory = ({
|
|
220
|
+
from,
|
|
221
|
+
to,
|
|
222
|
+
...rest
|
|
223
|
+
}) => {
|
|
224
|
+
const routeChange = `${from} => ${to}`;
|
|
220
225
|
const routeData = {
|
|
221
|
-
|
|
222
|
-
name:
|
|
223
|
-
message:
|
|
226
|
+
...rest,
|
|
227
|
+
name: routeChange,
|
|
228
|
+
message: routeChange,
|
|
224
229
|
type: EventType.History,
|
|
225
230
|
from,
|
|
226
|
-
to
|
|
227
|
-
...getTime(),
|
|
228
|
-
status: Status.OK
|
|
231
|
+
to
|
|
229
232
|
};
|
|
230
233
|
breadcrumb.push({
|
|
231
234
|
...routeData,
|
|
232
235
|
userAction: event2breadcrumb(EventType.History)
|
|
233
236
|
});
|
|
234
237
|
};
|
|
235
|
-
const handleHashChange = (
|
|
236
|
-
|
|
237
|
-
|
|
238
|
+
const handleHashChange = ({
|
|
239
|
+
extra,
|
|
240
|
+
...rest
|
|
241
|
+
}) => {
|
|
242
|
+
const { oldURL: from = UNKNOWN, newURL: to = UNKNOWN } = extra;
|
|
238
243
|
const pathChange = `${from} => ${to}`;
|
|
239
244
|
const routeData = {
|
|
240
|
-
|
|
245
|
+
...rest,
|
|
241
246
|
name: pathChange,
|
|
242
247
|
message: pathChange,
|
|
243
248
|
type: EventType.HashChange,
|
|
244
249
|
from,
|
|
245
|
-
to
|
|
246
|
-
...getTime(),
|
|
247
|
-
status: Status.OK
|
|
250
|
+
to
|
|
248
251
|
};
|
|
249
252
|
breadcrumb.push({
|
|
250
253
|
...routeData,
|
|
251
254
|
userAction: event2breadcrumb(EventType.HashChange)
|
|
252
255
|
});
|
|
253
256
|
};
|
|
254
|
-
const handleUnhandledRejection = (
|
|
255
|
-
if (!isIExtendedErrorEvent(
|
|
256
|
-
handleError$1(
|
|
257
|
+
const handleUnhandledRejection = (data) => {
|
|
258
|
+
if (!isIExtendedErrorEvent(data.extra)) {
|
|
259
|
+
handleError$1(data);
|
|
257
260
|
return;
|
|
258
261
|
}
|
|
259
|
-
handleCodeError(
|
|
262
|
+
handleCodeError(data.extra);
|
|
260
263
|
};
|
|
261
|
-
const handleWhiteScreen = () => {
|
|
262
|
-
checkWhiteScreen((
|
|
264
|
+
const handleWhiteScreen = (data) => {
|
|
265
|
+
checkWhiteScreen(() => {
|
|
263
266
|
reporter.send(data);
|
|
264
267
|
});
|
|
265
268
|
return;
|
|
266
269
|
};
|
|
267
|
-
const handleClick = (
|
|
268
|
-
|
|
270
|
+
const handleClick = ({
|
|
271
|
+
extra,
|
|
272
|
+
...rest
|
|
273
|
+
}) => {
|
|
274
|
+
const typedEvent = extra;
|
|
275
|
+
const str = typedEvent.target instanceof HTMLElement ? dom2str(typedEvent.target) : "";
|
|
269
276
|
breadcrumb.push({
|
|
270
|
-
|
|
277
|
+
...rest,
|
|
271
278
|
type: EventType.Click,
|
|
272
279
|
name: str,
|
|
273
280
|
message: str,
|
|
274
|
-
status: Status.OK,
|
|
275
|
-
...getTime(),
|
|
276
281
|
userAction: event2breadcrumb(EventType.Click)
|
|
277
282
|
});
|
|
278
283
|
};
|
|
279
284
|
const handleCodeError = (err) => {
|
|
280
285
|
const { filename, colno: column, lineno: line, message } = err;
|
|
281
286
|
const data = {
|
|
282
|
-
|
|
287
|
+
...getBaseData(),
|
|
283
288
|
type: EventType.Error,
|
|
284
289
|
name: filename,
|
|
285
290
|
message,
|
|
286
|
-
status: Status.Error
|
|
287
|
-
...getTime()
|
|
291
|
+
status: Status.Error
|
|
288
292
|
};
|
|
289
293
|
const codeError = {
|
|
290
294
|
...data,
|
|
@@ -366,12 +370,20 @@ function decoratePublish(type) {
|
|
|
366
370
|
function pubClick() {
|
|
367
371
|
const throttledPub = throttle(pub, sentry.options.clickThrottleDelay);
|
|
368
372
|
document.addEventListener("click", function(ctx) {
|
|
369
|
-
throttledPub(EventType.Click,
|
|
373
|
+
throttledPub(EventType.Click, {
|
|
374
|
+
...getBaseData(),
|
|
375
|
+
type: EventType.Click,
|
|
376
|
+
extra: ctx
|
|
377
|
+
});
|
|
370
378
|
});
|
|
371
379
|
}
|
|
372
380
|
function pubError() {
|
|
373
381
|
globalThis.addEventListener("error", function(ctx) {
|
|
374
|
-
pub(EventType.Error,
|
|
382
|
+
pub(EventType.Error, {
|
|
383
|
+
...getBaseData(),
|
|
384
|
+
type: EventType.Error,
|
|
385
|
+
extra: ctx
|
|
386
|
+
});
|
|
375
387
|
});
|
|
376
388
|
}
|
|
377
389
|
function pubXhr() {
|
|
@@ -379,15 +391,12 @@ function pubXhr() {
|
|
|
379
391
|
decorateProp(xhrProto, "open", (oldPropVal) => {
|
|
380
392
|
return function(method, url, async, ...rest) {
|
|
381
393
|
const httpData = {
|
|
382
|
-
|
|
394
|
+
...getBaseData(),
|
|
383
395
|
name: "XMLHttpRequest",
|
|
384
|
-
status: Status.OK,
|
|
385
396
|
type: EventType.Xhr,
|
|
386
|
-
...getTime(),
|
|
387
397
|
method: method.toUpperCase(),
|
|
388
398
|
api: url,
|
|
389
399
|
elapsedTime: 0,
|
|
390
|
-
message: "",
|
|
391
400
|
statusCode: HttpStatusCode.OK
|
|
392
401
|
};
|
|
393
402
|
this.__sentry__ = httpData;
|
|
@@ -403,11 +412,11 @@ function pubXhr() {
|
|
|
403
412
|
}
|
|
404
413
|
const { status, responseType, response } = this;
|
|
405
414
|
this.__sentry__.statusCode = status;
|
|
406
|
-
this.__sentry__.requestData = body;
|
|
407
|
-
this.__sentry__.responseData =
|
|
415
|
+
this.__sentry__.requestData = { body };
|
|
416
|
+
this.__sentry__.responseData = {
|
|
408
417
|
responseType,
|
|
409
418
|
response
|
|
410
|
-
}
|
|
419
|
+
};
|
|
411
420
|
const endTime = Date.now();
|
|
412
421
|
this.__sentry__.elapsedTime = endTime - this.__sentry__.timestamp;
|
|
413
422
|
pub(EventType.Xhr, this.__sentry__);
|
|
@@ -421,16 +430,13 @@ function pubFetch() {
|
|
|
421
430
|
return async function(url, options) {
|
|
422
431
|
const method = options?.method?.toUpperCase() ?? HttpMethod.Get;
|
|
423
432
|
const httpData = {
|
|
424
|
-
|
|
425
|
-
...getTime(),
|
|
433
|
+
...getBaseData(),
|
|
426
434
|
type: EventType.Fetch,
|
|
427
435
|
method,
|
|
428
|
-
requestData: options?.body,
|
|
436
|
+
requestData: { body: options?.body },
|
|
429
437
|
name: "Fetch",
|
|
430
|
-
status: Status.OK,
|
|
431
438
|
api: url.toString(),
|
|
432
439
|
elapsedTime: 0,
|
|
433
|
-
message: "",
|
|
434
440
|
statusCode: HttpStatusCode.OK
|
|
435
441
|
};
|
|
436
442
|
return oldPropVal.call(globalThis, url, options).then((res) => {
|
|
@@ -460,7 +466,12 @@ function pubHistory() {
|
|
|
460
466
|
const from = latestHref;
|
|
461
467
|
const to = document.location.href;
|
|
462
468
|
latestHref = to;
|
|
463
|
-
pub(EventType.History, {
|
|
469
|
+
pub(EventType.History, {
|
|
470
|
+
...getBaseData(),
|
|
471
|
+
type: EventType.History,
|
|
472
|
+
from,
|
|
473
|
+
to
|
|
474
|
+
});
|
|
464
475
|
return oldOnpopstate.call(this, ev);
|
|
465
476
|
};
|
|
466
477
|
const historyDecorator = (oldPropsVal) => {
|
|
@@ -469,7 +480,12 @@ function pubHistory() {
|
|
|
469
480
|
const from = latestHref;
|
|
470
481
|
const to = url.toString();
|
|
471
482
|
latestHref = to;
|
|
472
|
-
pub(EventType.History, {
|
|
483
|
+
pub(EventType.History, {
|
|
484
|
+
...getBaseData(),
|
|
485
|
+
type: EventType.History,
|
|
486
|
+
from,
|
|
487
|
+
to
|
|
488
|
+
});
|
|
473
489
|
}
|
|
474
490
|
return oldPropsVal.call(this, data, unused, url);
|
|
475
491
|
};
|
|
@@ -481,17 +497,29 @@ function pubUnhandledRejection() {
|
|
|
481
497
|
globalThis.addEventListener(
|
|
482
498
|
"unhandledrejection",
|
|
483
499
|
function(ctx) {
|
|
484
|
-
pub(EventType.UnhandledRejection,
|
|
500
|
+
pub(EventType.UnhandledRejection, {
|
|
501
|
+
...getBaseData(),
|
|
502
|
+
type: EventType.UnhandledRejection,
|
|
503
|
+
extra: ctx
|
|
504
|
+
});
|
|
485
505
|
}
|
|
486
506
|
);
|
|
487
507
|
}
|
|
488
508
|
function pubHashChange() {
|
|
489
509
|
globalThis.addEventListener("hashchange", function(ctx) {
|
|
490
|
-
pub(EventType.HashChange,
|
|
510
|
+
pub(EventType.HashChange, {
|
|
511
|
+
...getBaseData(),
|
|
512
|
+
type: EventType.HashChange,
|
|
513
|
+
extra: ctx
|
|
514
|
+
});
|
|
491
515
|
});
|
|
492
516
|
}
|
|
493
517
|
function pubWhiteScreen() {
|
|
494
|
-
pub(EventType.WhiteScreen
|
|
518
|
+
pub(EventType.WhiteScreen, {
|
|
519
|
+
...getBaseData(),
|
|
520
|
+
type: EventType.WhiteScreen,
|
|
521
|
+
extra: "WhiteScreen"
|
|
522
|
+
});
|
|
495
523
|
}
|
|
496
524
|
|
|
497
525
|
function setup() {
|
|
@@ -3534,7 +3562,12 @@ function init(options) {
|
|
|
3534
3562
|
const vuePlugin = (app, options) => {
|
|
3535
3563
|
const handler = app.config.errorHandler;
|
|
3536
3564
|
app.config.errorHandler = (err, vueInstance, info) => {
|
|
3537
|
-
handleError$1(
|
|
3565
|
+
handleError$1({
|
|
3566
|
+
...getBaseData(),
|
|
3567
|
+
type: EventType$1.Vue,
|
|
3568
|
+
status: Status.Error,
|
|
3569
|
+
extra: err
|
|
3570
|
+
});
|
|
3538
3571
|
if (handler) {
|
|
3539
3572
|
handler.call(null, err, vueInstance, info);
|
|
3540
3573
|
}
|
|
@@ -3543,9 +3576,14 @@ const vuePlugin = (app, options) => {
|
|
|
3543
3576
|
};
|
|
3544
3577
|
class ReactErrorBoundary extends reactExports.Component {
|
|
3545
3578
|
componentDidCatch(error, errorInfo) {
|
|
3546
|
-
handleError$1(
|
|
3547
|
-
|
|
3548
|
-
|
|
3579
|
+
handleError$1({
|
|
3580
|
+
...getBaseData(),
|
|
3581
|
+
type: EventType$1.React,
|
|
3582
|
+
status: Status.Error,
|
|
3583
|
+
extra: {
|
|
3584
|
+
error,
|
|
3585
|
+
errorInfo
|
|
3586
|
+
}
|
|
3549
3587
|
});
|
|
3550
3588
|
}
|
|
3551
3589
|
}
|