@sigil-dev/plugin-sentry 0.9.5 → 0.9.6
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/index.ts +60 -0
- package/package.json +4 -12
package/index.ts
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import * as Sentry from "@sentry/bun";
|
|
2
|
+
import type { GrimoirePlugin } from "@sigil-dev/grimoire";
|
|
3
|
+
import type { LogEntry, LogTransport } from "@sigil-dev/grimoire/logger";
|
|
4
|
+
import { log } from "@sigil-dev/grimoire/server";
|
|
5
|
+
|
|
6
|
+
export interface SentryPluginOptions {
|
|
7
|
+
dsn: string;
|
|
8
|
+
captureWarns?: boolean;
|
|
9
|
+
beforeSend?: (entry: LogEntry) => boolean;
|
|
10
|
+
sentryOptions?: Record<string, unknown>;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function sentryPlugin(options: SentryPluginOptions): GrimoirePlugin {
|
|
14
|
+
const transport: LogTransport = {
|
|
15
|
+
write(entry: LogEntry) {
|
|
16
|
+
if (options.beforeSend && !options.beforeSend(entry)) return;
|
|
17
|
+
|
|
18
|
+
if (entry.level === "error" || entry.level === "fatal") {
|
|
19
|
+
const err =
|
|
20
|
+
entry.data instanceof Error
|
|
21
|
+
? entry.data
|
|
22
|
+
: Object.assign(new Error(entry.message), { data: entry.data });
|
|
23
|
+
|
|
24
|
+
Sentry.captureException(err, {
|
|
25
|
+
tags: { scope: entry.scope, worker: entry.worker ?? "unknown" },
|
|
26
|
+
extra: { data: entry.data, requestId: entry.requestId },
|
|
27
|
+
});
|
|
28
|
+
} else if (entry.level === "warn" && options.captureWarns) {
|
|
29
|
+
Sentry.captureMessage(entry.message, {
|
|
30
|
+
level: "warning",
|
|
31
|
+
tags: { scope: entry.scope },
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
return {
|
|
38
|
+
name: "@sigil-dev/plugin-sentry",
|
|
39
|
+
|
|
40
|
+
config(cfg) {
|
|
41
|
+
Sentry.init({ dsn: options.dsn, ...options.sentryOptions });
|
|
42
|
+
log.addTransport(transport);
|
|
43
|
+
return cfg;
|
|
44
|
+
},
|
|
45
|
+
|
|
46
|
+
onRequest(req, next) {
|
|
47
|
+
Sentry.setContext("request", { url: req.url, method: req.method });
|
|
48
|
+
return next();
|
|
49
|
+
},
|
|
50
|
+
|
|
51
|
+
onWorkerDeath(worker, reason) {
|
|
52
|
+
if (reason === "crash") {
|
|
53
|
+
Sentry.captureMessage(`worker crashed: ${worker.name ?? worker.mode}`, {
|
|
54
|
+
level: "error",
|
|
55
|
+
tags: { worker: worker.name ?? "unknown", mode: worker.mode },
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
};
|
|
60
|
+
}
|
package/package.json
CHANGED
|
@@ -1,26 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sigil-dev/plugin-sentry",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.6",
|
|
4
4
|
"description": "Sentry error tracking plugin for grimoire",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"private": false,
|
|
7
|
-
"
|
|
8
|
-
"types": "./dist/index.d.ts",
|
|
7
|
+
"module": "index.ts",
|
|
9
8
|
"exports": {
|
|
10
|
-
".":
|
|
11
|
-
"import": "./dist/index.js",
|
|
12
|
-
"types": "./dist/index.d.ts"
|
|
13
|
-
}
|
|
9
|
+
".": "./index.ts"
|
|
14
10
|
},
|
|
15
|
-
"files": [
|
|
16
|
-
"dist"
|
|
17
|
-
],
|
|
18
11
|
"scripts": {
|
|
19
|
-
"build": "tsc --project tsconfig.json",
|
|
20
12
|
"typecheck": "tsc --noEmit"
|
|
21
13
|
},
|
|
22
14
|
"dependencies": {
|
|
23
|
-
"@sigil-dev/grimoire": "0.9.
|
|
15
|
+
"@sigil-dev/grimoire": "0.9.6",
|
|
24
16
|
"@sentry/bun": "^8.0.0"
|
|
25
17
|
},
|
|
26
18
|
"peerDependencies": {
|