@guomain/monitor-types 0.1.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.
- package/README.md +27 -0
- package/index.d.ts +145 -0
- package/index.d.ts.map +1 -0
- package/index.js +1 -0
- package/package.json +30 -0
package/README.md
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# @gm Monitor SDK
|
|
2
|
+
|
|
3
|
+
前端错误监控:运行时错误、Promise、资源加载、接口异常、Vue/React、手动上报、catch 自动采集(需 Vite 插件)。
|
|
4
|
+
|
|
5
|
+
## 安装
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
pnpm add @guomain/monitor-web
|
|
9
|
+
pnpm add -D @guomain/monitor-plugins @guomain/monitor-types
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
## 快速开始
|
|
13
|
+
|
|
14
|
+
```ts
|
|
15
|
+
import { createWebMonitor } from '@guomain/monitor-web'
|
|
16
|
+
|
|
17
|
+
const monitor = createWebMonitor({
|
|
18
|
+
appId: 'your-app',
|
|
19
|
+
dsn: '/api/monitor',
|
|
20
|
+
vue: { app }
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
globalThis.__GM_MONITOR__ = monitor
|
|
24
|
+
monitor.start()
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
完整说明见仓库内 `SDK.md` 与 `PUBLISH.md`。
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 监控事件类型。
|
|
3
|
+
* 用于区分错误来源,方便后端按运行时、Promise、资源、请求、框架、SDK 自身等维度统计。
|
|
4
|
+
*/
|
|
5
|
+
export type MonitorEventType = 'runtime-error' | 'promise-error' | 'resource-error' | 'request-error' | 'vue-error' | 'react-error' | 'sdk-error' | 'caught-error' | 'manual-error';
|
|
6
|
+
/**
|
|
7
|
+
* 业务上下文字段值。
|
|
8
|
+
* 只允许简单可序列化值,避免上报复杂对象或敏感运行时引用。
|
|
9
|
+
*/
|
|
10
|
+
export type MonitorContextValue = string | number | boolean | null;
|
|
11
|
+
/**
|
|
12
|
+
* 业务上下文。
|
|
13
|
+
* 由宿主应用决定包含哪些字段,例如用户、租户、页面、业务场景等。
|
|
14
|
+
*/
|
|
15
|
+
export type MonitorContext = Record<string, MonitorContextValue>;
|
|
16
|
+
/**
|
|
17
|
+
* 上下文提供方式。
|
|
18
|
+
* - 对象:初始化后固定不变的静态上下文。
|
|
19
|
+
* - 函数:每次上报前动态读取运行时上下文。
|
|
20
|
+
*/
|
|
21
|
+
export type MonitorContextProvider = MonitorContext | (() => MonitorContext | Promise<MonitorContext>);
|
|
22
|
+
/**
|
|
23
|
+
* 事件附加信息。
|
|
24
|
+
* @property tags 用于筛选、聚合的低基数字段。
|
|
25
|
+
* @property extra 用于排查问题的补充数据。
|
|
26
|
+
*/
|
|
27
|
+
export interface MonitorEventMeta {
|
|
28
|
+
tags?: Record<string, string>;
|
|
29
|
+
extra?: Record<string, unknown>;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* SDK 内部统一事件结构。
|
|
33
|
+
* @property type 错误来源类型。
|
|
34
|
+
* @property message 错误摘要。
|
|
35
|
+
* @property timestamp 事件发生时间戳;未传时由 SDK 自动补齐。
|
|
36
|
+
* @property url 资源或请求地址。
|
|
37
|
+
* @property stack 错误堆栈。
|
|
38
|
+
* @property filename 运行时错误文件名。
|
|
39
|
+
* @property lineno 运行时错误行号。
|
|
40
|
+
* @property colno 运行时错误列号。
|
|
41
|
+
*/
|
|
42
|
+
export interface MonitorEvent extends MonitorEventMeta {
|
|
43
|
+
type: MonitorEventType;
|
|
44
|
+
message: string;
|
|
45
|
+
timestamp?: number;
|
|
46
|
+
url?: string;
|
|
47
|
+
stack?: string;
|
|
48
|
+
filename?: string;
|
|
49
|
+
lineno?: number;
|
|
50
|
+
colno?: number;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* 最终发送给 transport 的载荷。
|
|
54
|
+
* @property appId 应用标识。
|
|
55
|
+
* @property release 应用发布版本。
|
|
56
|
+
* @property context 上报时的业务上下文。
|
|
57
|
+
*/
|
|
58
|
+
export interface MonitorPayload extends MonitorEvent {
|
|
59
|
+
appId: string;
|
|
60
|
+
release?: string;
|
|
61
|
+
context?: MonitorContext;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* 自定义发送函数。
|
|
65
|
+
* @param payloads SDK 归一化后的批量上报数据。
|
|
66
|
+
*/
|
|
67
|
+
export type MonitorTransport = (payloads: MonitorPayload[]) => void | Promise<void>;
|
|
68
|
+
/**
|
|
69
|
+
* 采集阈值。
|
|
70
|
+
* @property maxQueueSize 最大待发送队列长度。
|
|
71
|
+
*/
|
|
72
|
+
export interface MonitorLimits {
|
|
73
|
+
maxQueueSize: number;
|
|
74
|
+
}
|
|
75
|
+
export type PartialMonitorLimits = Partial<MonitorLimits>;
|
|
76
|
+
/**
|
|
77
|
+
* Vue 错误适配配置。
|
|
78
|
+
* @property app Vue 应用实例,SDK 会接入 app.config.errorHandler。
|
|
79
|
+
*/
|
|
80
|
+
export interface VueMonitorOptions {
|
|
81
|
+
app: {
|
|
82
|
+
config: {
|
|
83
|
+
errorHandler?: (err: unknown, instance: unknown, info: string) => void;
|
|
84
|
+
};
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* SDK 初始化配置。
|
|
89
|
+
* @property appId 应用标识,必填。
|
|
90
|
+
* @property dsn 默认上报地址;未提供 transport 时使用。
|
|
91
|
+
* @property release 发布版本,用于定位错误属于哪次构建。
|
|
92
|
+
* @property error 是否启用 Web 错误监控,默认开启。
|
|
93
|
+
* @property context 业务上下文,可静态传入,也可运行时动态计算。
|
|
94
|
+
* @property limits 队列、限流、重试阈值。
|
|
95
|
+
* @property transport 自定义发送函数,优先级高于 dsn。
|
|
96
|
+
* @property vue Vue 错误适配配置。
|
|
97
|
+
*/
|
|
98
|
+
export interface MonitorConfig {
|
|
99
|
+
appId: string;
|
|
100
|
+
dsn?: string;
|
|
101
|
+
release?: string;
|
|
102
|
+
error?: boolean;
|
|
103
|
+
context?: MonitorContextProvider;
|
|
104
|
+
limits?: PartialMonitorLimits;
|
|
105
|
+
transport?: MonitorTransport;
|
|
106
|
+
vue?: VueMonitorOptions;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* SDK 插件协议。
|
|
110
|
+
* @property name 插件名称,用于 SDK 自身错误定位。
|
|
111
|
+
* @property setup 插件安装函数;返回函数时会在 stop 阶段执行清理。
|
|
112
|
+
*/
|
|
113
|
+
export interface MonitorPlugin {
|
|
114
|
+
name: string;
|
|
115
|
+
setup: (monitor: MonitorInstance) => void | (() => void);
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* React 渲染根节点的最小接口。
|
|
119
|
+
* @property render React root.render 方法。
|
|
120
|
+
*/
|
|
121
|
+
export interface ReactRenderRoot {
|
|
122
|
+
render: (node: unknown) => void;
|
|
123
|
+
}
|
|
124
|
+
export type ReactElementLike = unknown;
|
|
125
|
+
/**
|
|
126
|
+
* SDK 实例 API。
|
|
127
|
+
* @property config 初始化配置。
|
|
128
|
+
* @property limits 合并默认值后的阈值配置。
|
|
129
|
+
* @property start 启动监听和插件。
|
|
130
|
+
* @property stop 停止监听并清理插件。
|
|
131
|
+
* @property use 注册插件。
|
|
132
|
+
* @property capture SDK 对外唯一上报入口,接收已归一化事件。
|
|
133
|
+
* @property flush 等待当前队列中的发送任务完成。
|
|
134
|
+
*/
|
|
135
|
+
export interface MonitorInstance {
|
|
136
|
+
readonly config: MonitorConfig;
|
|
137
|
+
readonly limits: MonitorLimits;
|
|
138
|
+
start: () => void;
|
|
139
|
+
stop: () => void;
|
|
140
|
+
use: (plugin: MonitorPlugin) => MonitorInstance;
|
|
141
|
+
capture: (event: MonitorEvent) => void;
|
|
142
|
+
flush: () => Promise<void>;
|
|
143
|
+
renderReact?: (root: ReactRenderRoot, element: ReactElementLike) => void;
|
|
144
|
+
}
|
|
145
|
+
//# sourceMappingURL=index.d.ts.map
|
package/index.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,MAAM,gBAAgB,GACxB,eAAe,GACf,eAAe,GACf,gBAAgB,GAChB,eAAe,GACf,WAAW,GACX,aAAa,GACb,WAAW,GACX,cAAc,GACd,cAAc,CAAA;AAElB;;;GAGG;AACH,MAAM,MAAM,mBAAmB,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,CAAA;AAElE;;;GAGG;AACH,MAAM,MAAM,cAAc,GAAG,MAAM,CAAC,MAAM,EAAE,mBAAmB,CAAC,CAAA;AAEhE;;;;GAIG;AACH,MAAM,MAAM,sBAAsB,GAC9B,cAAc,GACd,CAAC,MAAM,cAAc,GAAG,OAAO,CAAC,cAAc,CAAC,CAAC,CAAA;AAEpD;;;;GAIG;AACH,MAAM,WAAW,gBAAgB;IAC/B,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAC7B,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CAChC;AAED;;;;;;;;;;GAUG;AACH,MAAM,WAAW,YAAa,SAAQ,gBAAgB;IACpD,IAAI,EAAE,gBAAgB,CAAA;IACtB,OAAO,EAAE,MAAM,CAAA;IACf,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,KAAK,CAAC,EAAE,MAAM,CAAA;CACf;AAED;;;;;GAKG;AACH,MAAM,WAAW,cAAe,SAAQ,YAAY;IAClD,KAAK,EAAE,MAAM,CAAA;IACb,OAAO,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,WAAW,eAAe;IAC9B,QAAQ,CAAC,MAAM,EAAE,aAAa,CAAA;IAC9B,QAAQ,CAAC,MAAM,EAAE,aAAa,CAAA;IAC9B,KAAK,EAAE,MAAM,IAAI,CAAA;IACjB,IAAI,EAAE,MAAM,IAAI,CAAA;IAChB,GAAG,EAAE,CAAC,MAAM,EAAE,aAAa,KAAK,eAAe,CAAA;IAC/C,OAAO,EAAE,CAAC,KAAK,EAAE,YAAY,KAAK,IAAI,CAAA;IACtC,KAAK,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAA;IAC1B,WAAW,CAAC,EAAE,CAAC,IAAI,EAAE,eAAe,EAAE,OAAO,EAAE,gBAAgB,KAAK,IAAI,CAAA;CACzE"}
|
package/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": "0.1.0",
|
|
3
|
+
"license": "MIT",
|
|
4
|
+
"repository": {
|
|
5
|
+
"type": "git",
|
|
6
|
+
"url": "git+http://192.168.200.220/GomainFE/stamp.git",
|
|
7
|
+
"directory": "monitor/packages/monitor-types"
|
|
8
|
+
},
|
|
9
|
+
"publishConfig": {
|
|
10
|
+
"access": "public",
|
|
11
|
+
"registry": "https://registry.npmjs.org/"
|
|
12
|
+
},
|
|
13
|
+
"name": "@guomain/monitor-types",
|
|
14
|
+
"description": "Type definitions for @gm monitor SDK",
|
|
15
|
+
"type": "module",
|
|
16
|
+
"sideEffects": false,
|
|
17
|
+
"main": "./index.js",
|
|
18
|
+
"module": "./index.js",
|
|
19
|
+
"types": "./index.d.ts",
|
|
20
|
+
"exports": {
|
|
21
|
+
".": {
|
|
22
|
+
"types": "./index.d.ts",
|
|
23
|
+
"import": "./index.js",
|
|
24
|
+
"default": "./index.js"
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
"files": [
|
|
28
|
+
"**/*"
|
|
29
|
+
]
|
|
30
|
+
}
|