@xifan0/monitor-core 0.0.2-beta.5 → 0.0.2-beta.7
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.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +13 -8
- package/dist/index.mjs +13 -8
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -27,4 +27,4 @@ interface Monitor {
|
|
|
27
27
|
|
|
28
28
|
declare function createMonitor<TOptions = any>(sentry: any): Monitor;
|
|
29
29
|
|
|
30
|
-
export { type CaptureContext, type Monitor, type MonitorUser, createMonitor
|
|
30
|
+
export { type CaptureContext, type Monitor, type MonitorUser, createMonitor };
|
package/dist/index.d.ts
CHANGED
|
@@ -27,4 +27,4 @@ interface Monitor {
|
|
|
27
27
|
|
|
28
28
|
declare function createMonitor<TOptions = any>(sentry: any): Monitor;
|
|
29
29
|
|
|
30
|
-
export { type CaptureContext, type Monitor, type MonitorUser, createMonitor
|
|
30
|
+
export { type CaptureContext, type Monitor, type MonitorUser, createMonitor };
|
package/dist/index.js
CHANGED
|
@@ -20,20 +20,25 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/index.ts
|
|
21
21
|
var index_exports = {};
|
|
22
22
|
__export(index_exports, {
|
|
23
|
-
createMonitor: () => createMonitor
|
|
24
|
-
default: () => createMonitor
|
|
23
|
+
createMonitor: () => createMonitor
|
|
25
24
|
});
|
|
26
25
|
module.exports = __toCommonJS(index_exports);
|
|
27
26
|
|
|
28
27
|
// src/createMonitor.ts
|
|
29
28
|
function createMonitor(sentry) {
|
|
29
|
+
const sentryInstance = sentry && typeof sentry === "object" && sentry.default ? sentry.default : sentry;
|
|
30
30
|
const monitor = {
|
|
31
31
|
init(options) {
|
|
32
|
-
|
|
32
|
+
if (!sentryInstance || typeof sentryInstance.init !== "function") {
|
|
33
|
+
throw new Error(
|
|
34
|
+
"Sentry.init is not a function. Please ensure @sentry/react is properly imported."
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
return sentryInstance.init(options);
|
|
33
38
|
},
|
|
34
39
|
/** 上报异常 */
|
|
35
40
|
captureException(error, ctx) {
|
|
36
|
-
return
|
|
41
|
+
return sentryInstance.captureException(error, (scope) => {
|
|
37
42
|
(ctx == null ? void 0 : ctx.tags) && scope.setTags(ctx.tags);
|
|
38
43
|
(ctx == null ? void 0 : ctx.extra) && scope.setExtras(ctx.extra);
|
|
39
44
|
return scope;
|
|
@@ -41,7 +46,7 @@ function createMonitor(sentry) {
|
|
|
41
46
|
},
|
|
42
47
|
/** 发送消息/提醒/日志 */
|
|
43
48
|
captureMessage(message, ctx) {
|
|
44
|
-
return
|
|
49
|
+
return sentryInstance.captureMessage(message, (scope) => {
|
|
45
50
|
(ctx == null ? void 0 : ctx.tags) && scope.setTags(ctx.tags);
|
|
46
51
|
(ctx == null ? void 0 : ctx.extra) && scope.setExtras(ctx.extra);
|
|
47
52
|
return scope;
|
|
@@ -49,7 +54,7 @@ function createMonitor(sentry) {
|
|
|
49
54
|
},
|
|
50
55
|
/** 设置用户信息 */
|
|
51
56
|
setUser(user) {
|
|
52
|
-
return
|
|
57
|
+
return sentryInstance.setUser(user);
|
|
53
58
|
}
|
|
54
59
|
};
|
|
55
60
|
const proxy = new Proxy(monitor, {
|
|
@@ -57,13 +62,13 @@ function createMonitor(sentry) {
|
|
|
57
62
|
if (key in target) {
|
|
58
63
|
return Reflect.get(target, key, receiver);
|
|
59
64
|
}
|
|
60
|
-
const sentryFn =
|
|
65
|
+
const sentryFn = sentryInstance[key];
|
|
61
66
|
if (typeof sentryFn === "function") {
|
|
62
67
|
const isClass = sentryFn.prototype && sentryFn.prototype.constructor === sentryFn && Object.getOwnPropertyNames(sentryFn.prototype).length > 1;
|
|
63
68
|
if (isClass) {
|
|
64
69
|
return sentryFn;
|
|
65
70
|
}
|
|
66
|
-
return sentryFn.bind(
|
|
71
|
+
return sentryFn.bind(sentryInstance);
|
|
67
72
|
}
|
|
68
73
|
return sentryFn;
|
|
69
74
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -1,12 +1,18 @@
|
|
|
1
1
|
// src/createMonitor.ts
|
|
2
2
|
function createMonitor(sentry) {
|
|
3
|
+
const sentryInstance = sentry && typeof sentry === "object" && sentry.default ? sentry.default : sentry;
|
|
3
4
|
const monitor = {
|
|
4
5
|
init(options) {
|
|
5
|
-
|
|
6
|
+
if (!sentryInstance || typeof sentryInstance.init !== "function") {
|
|
7
|
+
throw new Error(
|
|
8
|
+
"Sentry.init is not a function. Please ensure @sentry/react is properly imported."
|
|
9
|
+
);
|
|
10
|
+
}
|
|
11
|
+
return sentryInstance.init(options);
|
|
6
12
|
},
|
|
7
13
|
/** 上报异常 */
|
|
8
14
|
captureException(error, ctx) {
|
|
9
|
-
return
|
|
15
|
+
return sentryInstance.captureException(error, (scope) => {
|
|
10
16
|
(ctx == null ? void 0 : ctx.tags) && scope.setTags(ctx.tags);
|
|
11
17
|
(ctx == null ? void 0 : ctx.extra) && scope.setExtras(ctx.extra);
|
|
12
18
|
return scope;
|
|
@@ -14,7 +20,7 @@ function createMonitor(sentry) {
|
|
|
14
20
|
},
|
|
15
21
|
/** 发送消息/提醒/日志 */
|
|
16
22
|
captureMessage(message, ctx) {
|
|
17
|
-
return
|
|
23
|
+
return sentryInstance.captureMessage(message, (scope) => {
|
|
18
24
|
(ctx == null ? void 0 : ctx.tags) && scope.setTags(ctx.tags);
|
|
19
25
|
(ctx == null ? void 0 : ctx.extra) && scope.setExtras(ctx.extra);
|
|
20
26
|
return scope;
|
|
@@ -22,7 +28,7 @@ function createMonitor(sentry) {
|
|
|
22
28
|
},
|
|
23
29
|
/** 设置用户信息 */
|
|
24
30
|
setUser(user) {
|
|
25
|
-
return
|
|
31
|
+
return sentryInstance.setUser(user);
|
|
26
32
|
}
|
|
27
33
|
};
|
|
28
34
|
const proxy = new Proxy(monitor, {
|
|
@@ -30,13 +36,13 @@ function createMonitor(sentry) {
|
|
|
30
36
|
if (key in target) {
|
|
31
37
|
return Reflect.get(target, key, receiver);
|
|
32
38
|
}
|
|
33
|
-
const sentryFn =
|
|
39
|
+
const sentryFn = sentryInstance[key];
|
|
34
40
|
if (typeof sentryFn === "function") {
|
|
35
41
|
const isClass = sentryFn.prototype && sentryFn.prototype.constructor === sentryFn && Object.getOwnPropertyNames(sentryFn.prototype).length > 1;
|
|
36
42
|
if (isClass) {
|
|
37
43
|
return sentryFn;
|
|
38
44
|
}
|
|
39
|
-
return sentryFn.bind(
|
|
45
|
+
return sentryFn.bind(sentryInstance);
|
|
40
46
|
}
|
|
41
47
|
return sentryFn;
|
|
42
48
|
}
|
|
@@ -44,6 +50,5 @@ function createMonitor(sentry) {
|
|
|
44
50
|
return proxy;
|
|
45
51
|
}
|
|
46
52
|
export {
|
|
47
|
-
createMonitor
|
|
48
|
-
createMonitor as default
|
|
53
|
+
createMonitor
|
|
49
54
|
};
|