@error-reporting/node 0.1.0 → 0.2.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 +17 -0
- package/index.d.ts +3 -3
- package/package.json +2 -2
- package/src/index.js +5 -5
package/README.md
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# @error-reporting/node
|
|
2
|
+
|
|
3
|
+
```sh
|
|
4
|
+
npm install @error-reporting/node
|
|
5
|
+
```
|
|
6
|
+
|
|
7
|
+
```js
|
|
8
|
+
import { Init, CaptureException, Flush } from '@error-reporting/node'
|
|
9
|
+
|
|
10
|
+
Init({ dsn: process.env.ERROR_REPORTING_DSN, environment: 'production', release: 'git-sha' })
|
|
11
|
+
CaptureException(new Error('上报接入测试'), { requestId: 'request-42' })
|
|
12
|
+
await Flush()
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
在业务模块加载前调用一次 `Init`。SDK 自动捕获进程内未处理异常,并通过 `CaptureException` 补报已处理的异常。短脚本或进程退出前可用 `Flush(timeoutMs)` 等待发送。
|
|
16
|
+
|
|
17
|
+
从 0.1.x 升级到 0.2.x 时,把三个入口替换成示例中的大写开头写法。
|
package/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { CaptureContext, Options } from '@error-reporting/core'
|
|
2
2
|
|
|
3
3
|
export type { CaptureContext, Options, ReportEvent } from '@error-reporting/core'
|
|
4
|
-
export function
|
|
5
|
-
export function
|
|
6
|
-
export function
|
|
4
|
+
export function Init(options?: Options): void
|
|
5
|
+
export function CaptureException(error: unknown, context?: CaptureContext): string
|
|
6
|
+
export function Flush(timeout?: number): PromiseLike<boolean>
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@error-reporting/node",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Error Reporting Platform SDK for Node.js",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": { "node": ">=22.12.0 <23 || >=23.2.0" },
|
|
7
7
|
"exports": { ".": { "types": "./index.d.ts", "default": "./src/index.js" } },
|
|
8
8
|
"files": ["src", "index.d.ts"],
|
|
9
|
-
"dependencies": { "@error-reporting/core": "0.
|
|
9
|
+
"dependencies": { "@error-reporting/core": "0.2.0", "@sentry/node": "^11.17.0" },
|
|
10
10
|
"publishConfig": { "access": "public", "registry": "https://registry.npmjs.org/" },
|
|
11
11
|
"repository": { "type": "git", "url": "git+https://gitee.com/qglove/error-reporting-platform.git", "directory": "packages/javascript/node" }
|
|
12
12
|
}
|
package/src/index.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import * as Sentry from '@sentry/node'
|
|
2
|
-
import {
|
|
2
|
+
import { CreateReportOptions } from '@error-reporting/core'
|
|
3
3
|
|
|
4
4
|
let initialized = false
|
|
5
5
|
|
|
6
6
|
/** 在 Node.js 业务入口加载前安装默认异常监听。
|
|
7
7
|
* @param {import('@error-reporting/core').Options} options 显式配置优先于服务器环境变量。
|
|
8
8
|
*/
|
|
9
|
-
export function
|
|
10
|
-
const config =
|
|
9
|
+
export function Init(options = {}) {
|
|
10
|
+
const config = CreateReportOptions({
|
|
11
11
|
dsn: process.env.ERROR_REPORTING_DSN,
|
|
12
12
|
environment: process.env.NODE_ENV ?? 'development',
|
|
13
13
|
release: process.env.ERROR_REPORTING_RELEASE,
|
|
@@ -28,13 +28,13 @@ export function init(options = {}) {
|
|
|
28
28
|
* @param {unknown} error 原始异常或拒绝原因。
|
|
29
29
|
* @param {import('@error-reporting/core').CaptureContext} context 诊断用请求编号。
|
|
30
30
|
*/
|
|
31
|
-
export function
|
|
31
|
+
export function CaptureException(error, context = {}) {
|
|
32
32
|
return Sentry.captureException(error, context.requestId ? { tags: { request_id: context.requestId } } : undefined)
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
/** 等待待发送队列,适用于进程优雅退出和短脚本。
|
|
36
36
|
* @param {number} timeout 等待毫秒数。
|
|
37
37
|
*/
|
|
38
|
-
export function
|
|
38
|
+
export function Flush(timeout = 2000) {
|
|
39
39
|
return Sentry.flush(timeout)
|
|
40
40
|
}
|