@concordiq/error-sdk 1.0.2 → 1.0.4
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/package.json +32 -32
- package/readMe.md +81 -78
- package/src/client.js +43 -21
- package/src/handlers.js +48 -14
- package/src/index.d.ts +29 -29
- package/src/index.js +141 -72
- package/src/middleware.js +15 -15
- package/src/utils.js +13 -13
package/package.json
CHANGED
|
@@ -1,32 +1,32 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@concordiq/error-sdk",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"private": false,
|
|
5
|
-
"description": "Error monitoring SDK",
|
|
6
|
-
"type": "module",
|
|
7
|
-
"main": "./src/index.js",
|
|
8
|
-
"types": "./src/index.d.ts",
|
|
9
|
-
"keywords": [
|
|
10
|
-
"errors",
|
|
11
|
-
"monitoring",
|
|
12
|
-
"logging"
|
|
13
|
-
],
|
|
14
|
-
"author": "Arowolo Seyi Ebine",
|
|
15
|
-
"license": "MIT",
|
|
16
|
-
"exports": {
|
|
17
|
-
".": {
|
|
18
|
-
"import": "./src/index.js",
|
|
19
|
-
"require": "./src/index.js",
|
|
20
|
-
"types": "./src/index.d.ts"
|
|
21
|
-
}
|
|
22
|
-
},
|
|
23
|
-
"files": [
|
|
24
|
-
"src"
|
|
25
|
-
],
|
|
26
|
-
"dependencies": {
|
|
27
|
-
"node-fetch": "^3.3.2"
|
|
28
|
-
},
|
|
29
|
-
"peerDependencies": {
|
|
30
|
-
"express": "^4 || ^5"
|
|
31
|
-
}
|
|
32
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@concordiq/error-sdk",
|
|
3
|
+
"version": "1.0.4",
|
|
4
|
+
"private": false,
|
|
5
|
+
"description": "Error monitoring SDK",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "./src/index.js",
|
|
8
|
+
"types": "./src/index.d.ts",
|
|
9
|
+
"keywords": [
|
|
10
|
+
"errors",
|
|
11
|
+
"monitoring",
|
|
12
|
+
"logging"
|
|
13
|
+
],
|
|
14
|
+
"author": "Arowolo Seyi Ebine",
|
|
15
|
+
"license": "MIT",
|
|
16
|
+
"exports": {
|
|
17
|
+
".": {
|
|
18
|
+
"import": "./src/index.js",
|
|
19
|
+
"require": "./src/index.js",
|
|
20
|
+
"types": "./src/index.d.ts"
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
"files": [
|
|
24
|
+
"src"
|
|
25
|
+
],
|
|
26
|
+
"dependencies": {
|
|
27
|
+
"node-fetch": "^3.3.2"
|
|
28
|
+
},
|
|
29
|
+
"peerDependencies": {
|
|
30
|
+
"express": "^4 || ^5"
|
|
31
|
+
}
|
|
32
|
+
}
|
package/readMe.md
CHANGED
|
@@ -1,79 +1,82 @@
|
|
|
1
|
-
# @concordiq/error-sdk
|
|
2
|
-
|
|
3
|
-
Official ConcordIQ Error Tracking SDK for Node.js and Express.
|
|
4
|
-
|
|
5
|
-
---
|
|
6
|
-
|
|
7
|
-
## Installation
|
|
8
|
-
|
|
9
|
-
```bash
|
|
10
|
-
npm install @concordiq/error-sdk
|
|
11
|
-
|
|
12
|
-
```
|
|
13
|
-
## Initialization
|
|
14
|
-
|
|
15
|
-
```javascript and typescript
|
|
16
|
-
Initialize once when your app starts:
|
|
17
|
-
```
|
|
18
|
-
|
|
19
|
-
import ErrorSDK from "@concordiq/error-sdk";
|
|
20
|
-
|
|
21
|
-
ErrorSDK.init({
|
|
22
|
-
apiKey: "PROJECT_API_KEY",
|
|
23
|
-
|
|
24
|
-
endpoint: "https://api.mysaas.com/ingest",
|
|
25
|
-
|
|
26
|
-
env: "production",
|
|
27
|
-
|
|
28
|
-
service: "payment-api"
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
## Manual Error Capture
|
|
34
|
-
|
|
35
|
-
Use inside controllers or services:
|
|
36
|
-
|
|
37
|
-
---
|
|
38
|
-
try {
|
|
39
|
-
processPayment();
|
|
40
|
-
} catch (err) {
|
|
41
|
-
ErrorSDK.capture(err, {
|
|
42
|
-
userId: 22,
|
|
43
|
-
orderId: 991
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
## Express.js Integration
|
|
51
|
-
|
|
52
|
-
Automatically capture all server errors.
|
|
53
|
-
import express from "express";
|
|
54
|
-
import ErrorSDK from "@concordiq/error-sdk";
|
|
55
|
-
----
|
|
56
|
-
const app = express();
|
|
57
|
-
|
|
58
|
-
app.use("/pay", (req, res) => {
|
|
59
|
-
throw new Error("Payment failed");
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
1
|
+
# @concordiq/error-sdk
|
|
2
|
+
|
|
3
|
+
Official ConcordIQ Error Tracking SDK for Node.js and Express.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @concordiq/error-sdk
|
|
11
|
+
|
|
12
|
+
```
|
|
13
|
+
## Initialization
|
|
14
|
+
|
|
15
|
+
```javascript and typescript
|
|
16
|
+
Initialize once when your app starts:
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
import ErrorSDK from "@concordiq/error-sdk";
|
|
20
|
+
|
|
21
|
+
ErrorSDK.init({
|
|
22
|
+
apiKey: "PROJECT_API_KEY",
|
|
23
|
+
|
|
24
|
+
endpoint: "https://api.mysaas.com/ingest",
|
|
25
|
+
|
|
26
|
+
env: "production",
|
|
27
|
+
|
|
28
|
+
service: "payment-api"
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
## Manual Error Capture
|
|
34
|
+
|
|
35
|
+
Use inside controllers or services:
|
|
36
|
+
|
|
37
|
+
---
|
|
38
|
+
try {
|
|
39
|
+
processPayment();
|
|
40
|
+
} catch (err) {
|
|
41
|
+
ErrorSDK.capture(err, {
|
|
42
|
+
userId: 22,
|
|
43
|
+
orderId: 991
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
## Express.js Integration
|
|
51
|
+
|
|
52
|
+
Automatically capture all server errors.
|
|
53
|
+
import express from "express";
|
|
54
|
+
import ErrorSDK from "@concordiq/error-sdk";
|
|
55
|
+
----
|
|
56
|
+
const app = express();
|
|
57
|
+
``
|
|
58
|
+
app.use("/pay", (req, res) => {
|
|
59
|
+
throw new Error("Payment failed");
|
|
60
|
+
});
|
|
61
|
+
``
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Must be last middleware
|
|
65
|
+
*/
|
|
66
|
+
|
|
67
|
+
``
|
|
68
|
+
app.use(ErrorSDK.expressMiddleware());
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
## Features:
|
|
73
|
+
|
|
74
|
+
1. Manual error tracking
|
|
75
|
+
|
|
76
|
+
2. Express middleware
|
|
77
|
+
|
|
78
|
+
3. Global crash handling
|
|
79
|
+
|
|
80
|
+
4. TypeScript support
|
|
81
|
+
|
|
79
82
|
5. Lightweight
|
package/src/client.js
CHANGED
|
@@ -1,22 +1,44 @@
|
|
|
1
|
-
import fetch from "node-fetch";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
1
|
+
// import fetch from "node-fetch";
|
|
2
|
+
|
|
3
|
+
// export async function sendError(apiKey, url, payload) {
|
|
4
|
+
// try {
|
|
5
|
+
// await fetch(url, {
|
|
6
|
+
// method: "POST",
|
|
7
|
+
|
|
8
|
+
// headers: {
|
|
9
|
+
// "Content-Type": "application/json",
|
|
10
|
+
// "x-api-key": apiKey
|
|
11
|
+
// },
|
|
12
|
+
|
|
13
|
+
// body: JSON.stringify(payload)
|
|
14
|
+
// });
|
|
15
|
+
// } catch (err) {
|
|
16
|
+
// // Never crash client app
|
|
17
|
+
// console.error("SDK Send Failed:", err.message);
|
|
18
|
+
// }
|
|
19
|
+
// }
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
import fetch from "node-fetch";
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Send error to ConcordIQ API
|
|
26
|
+
*/
|
|
27
|
+
export async function sendError(apiKey, endpoint, payload) {
|
|
28
|
+
try {
|
|
29
|
+
await fetch(endpoint, {
|
|
30
|
+
method: "POST",
|
|
31
|
+
|
|
32
|
+
headers: {
|
|
33
|
+
"Content-Type": "application/json",
|
|
34
|
+
"Authorization": apiKey,
|
|
35
|
+
"x-api-key": apiKey
|
|
36
|
+
},
|
|
37
|
+
|
|
38
|
+
body: JSON.stringify(payload)
|
|
39
|
+
});
|
|
40
|
+
} catch (err) {
|
|
41
|
+
// Avoid crashing user app
|
|
42
|
+
console.error("[ErrorSDK] Failed to send error:", err);
|
|
43
|
+
}
|
|
22
44
|
}
|
package/src/handlers.js
CHANGED
|
@@ -1,14 +1,48 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
1
|
+
import { sendError } from "./client.js";
|
|
2
|
+
|
|
3
|
+
export function attachHandlers(config) {
|
|
4
|
+
// Promise errors
|
|
5
|
+
process.on("unhandledRejection", err => {
|
|
6
|
+
report(err, config);
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
// Crash errors
|
|
10
|
+
process.on("uncaughtException", err => {
|
|
11
|
+
report(err, config);
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function report(err, config) {
|
|
16
|
+
const payload = {
|
|
17
|
+
message: err.message,
|
|
18
|
+
stack: err.stack,
|
|
19
|
+
type: "system",
|
|
20
|
+
|
|
21
|
+
service: config.service,
|
|
22
|
+
env: config.env,
|
|
23
|
+
|
|
24
|
+
timestamp: new Date()
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
sendError(
|
|
28
|
+
config.apiKey,
|
|
29
|
+
config.endpoint,
|
|
30
|
+
payload
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
// import { capture } from "./index.js";
|
|
36
|
+
|
|
37
|
+
// /**
|
|
38
|
+
// * Attach process-level handlers
|
|
39
|
+
// */
|
|
40
|
+
// export function attachHandlers() {
|
|
41
|
+
// process.on("uncaughtException", (err) => {
|
|
42
|
+
// capture(err);
|
|
43
|
+
// });
|
|
44
|
+
|
|
45
|
+
// process.on("unhandledRejection", (err) => {
|
|
46
|
+
// capture(err);
|
|
47
|
+
// });
|
|
48
|
+
// }
|
package/src/index.d.ts
CHANGED
|
@@ -1,30 +1,30 @@
|
|
|
1
|
-
import { Request, Response, NextFunction } from "express";
|
|
2
|
-
|
|
3
|
-
export interface ErrorSDKOptions {
|
|
4
|
-
apiKey: string;
|
|
5
|
-
endpoint?: string;
|
|
6
|
-
env?: string;
|
|
7
|
-
service?: string;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export function init(options: ErrorSDKOptions): void;
|
|
11
|
-
|
|
12
|
-
export function capture(
|
|
13
|
-
error: any,
|
|
14
|
-
extra?: Record<string, any>
|
|
15
|
-
): Promise<void>;
|
|
16
|
-
|
|
17
|
-
export function expressMiddleware(): (
|
|
18
|
-
err: any,
|
|
19
|
-
req: Request,
|
|
20
|
-
res: Response,
|
|
21
|
-
next: NextFunction
|
|
22
|
-
) => void;
|
|
23
|
-
|
|
24
|
-
declare const ErrorSDK: {
|
|
25
|
-
init: typeof init;
|
|
26
|
-
capture: typeof capture;
|
|
27
|
-
expressMiddleware: typeof expressMiddleware;
|
|
28
|
-
};
|
|
29
|
-
|
|
1
|
+
import { Request, Response, NextFunction } from "express";
|
|
2
|
+
|
|
3
|
+
export interface ErrorSDKOptions {
|
|
4
|
+
apiKey: string;
|
|
5
|
+
endpoint?: string;
|
|
6
|
+
env?: string;
|
|
7
|
+
service?: string;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function init(options: ErrorSDKOptions): void;
|
|
11
|
+
|
|
12
|
+
export function capture(
|
|
13
|
+
error: any,
|
|
14
|
+
extra?: Record<string, any>
|
|
15
|
+
): Promise<void>;
|
|
16
|
+
|
|
17
|
+
export function expressMiddleware(): (
|
|
18
|
+
err: any,
|
|
19
|
+
req: Request,
|
|
20
|
+
res: Response,
|
|
21
|
+
next: NextFunction
|
|
22
|
+
) => void;
|
|
23
|
+
|
|
24
|
+
declare const ErrorSDK: {
|
|
25
|
+
init: typeof init;
|
|
26
|
+
capture: typeof capture;
|
|
27
|
+
expressMiddleware: typeof expressMiddleware;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
30
|
export default ErrorSDK;
|
package/src/index.js
CHANGED
|
@@ -1,72 +1,141 @@
|
|
|
1
|
-
import { expressMiddleware } from "./middleware.js";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { getMeta } from "./utils.js";
|
|
5
|
-
|
|
6
|
-
let config = null;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
export {
|
|
63
|
-
init,
|
|
64
|
-
capture,
|
|
65
|
-
expressMiddleware
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
};
|
|
1
|
+
import { expressMiddleware } from "./middleware.js";
|
|
2
|
+
import { attachHandlers } from "./handlers.js";
|
|
3
|
+
import { sendError } from "./client.js";
|
|
4
|
+
import { getMeta } from "./utils.js";
|
|
5
|
+
|
|
6
|
+
let config = null;
|
|
7
|
+
|
|
8
|
+
function init(options) {
|
|
9
|
+
if (!options.apiKey) {
|
|
10
|
+
throw new Error("apiKey required");
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
config = {
|
|
14
|
+
apiKey: options.apiKey,
|
|
15
|
+
|
|
16
|
+
endpoint:
|
|
17
|
+
options.endpoint ||
|
|
18
|
+
"https://concordiq.onrender.com/api/v1/ingest/events",
|
|
19
|
+
|
|
20
|
+
env: options.env || "production",
|
|
21
|
+
|
|
22
|
+
service: options.service || "app"
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
attachHandlers(config);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
async function capture(error, extra = {}) {
|
|
29
|
+
if (!config) return;
|
|
30
|
+
|
|
31
|
+
const payload = {
|
|
32
|
+
message: error.message || error,
|
|
33
|
+
stack: error.stack,
|
|
34
|
+
|
|
35
|
+
type: "manual",
|
|
36
|
+
|
|
37
|
+
env: config.env,
|
|
38
|
+
service: config.service,
|
|
39
|
+
|
|
40
|
+
meta: {
|
|
41
|
+
...getMeta(),
|
|
42
|
+
...extra
|
|
43
|
+
},
|
|
44
|
+
|
|
45
|
+
timestamp: new Date()
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
await sendError(
|
|
49
|
+
config.apiKey,
|
|
50
|
+
config.endpoint,
|
|
51
|
+
payload
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export {
|
|
56
|
+
init,
|
|
57
|
+
capture,
|
|
58
|
+
expressMiddleware
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
export default {
|
|
63
|
+
init,
|
|
64
|
+
capture,
|
|
65
|
+
expressMiddleware
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
// import { expressMiddleware } from "./middleware.js";
|
|
71
|
+
// import { sendError } from "./client.js";
|
|
72
|
+
// import { attachHandlers } from "./handlers.js";
|
|
73
|
+
// import { getMeta } from "./utils.js";
|
|
74
|
+
|
|
75
|
+
// let config = null;
|
|
76
|
+
|
|
77
|
+
// /**
|
|
78
|
+
// * Initialize SDK
|
|
79
|
+
// */
|
|
80
|
+
// function init(options) {
|
|
81
|
+
// if (!options?.apiKey) {
|
|
82
|
+
// throw new Error("apiKey is required");
|
|
83
|
+
// }
|
|
84
|
+
|
|
85
|
+
// config = {
|
|
86
|
+
// apiKey: options.apiKey,
|
|
87
|
+
|
|
88
|
+
// endpoint:
|
|
89
|
+
// options.endpoint ||
|
|
90
|
+
// "https://concordiq.onrender.com/api/v1/ingest/events",
|
|
91
|
+
|
|
92
|
+
// env: options.env || "production",
|
|
93
|
+
|
|
94
|
+
// service: options.service || "app"
|
|
95
|
+
// };
|
|
96
|
+
|
|
97
|
+
// attachHandlers(config);
|
|
98
|
+
// }
|
|
99
|
+
|
|
100
|
+
// /**
|
|
101
|
+
// * Capture error manually
|
|
102
|
+
// */
|
|
103
|
+
// async function capture(error, extra = {}) {
|
|
104
|
+
// if (!config) return;
|
|
105
|
+
|
|
106
|
+
// const payload = {
|
|
107
|
+
// message: error?.message || String(error),
|
|
108
|
+
|
|
109
|
+
// stack: error?.stack,
|
|
110
|
+
|
|
111
|
+
// type: "manual",
|
|
112
|
+
|
|
113
|
+
// env: config.env,
|
|
114
|
+
// service: config.service,
|
|
115
|
+
|
|
116
|
+
// meta: {
|
|
117
|
+
// ...getMeta(),
|
|
118
|
+
// ...extra
|
|
119
|
+
// },
|
|
120
|
+
|
|
121
|
+
// timestamp: new Date().toISOString()
|
|
122
|
+
// };
|
|
123
|
+
|
|
124
|
+
// await sendError(
|
|
125
|
+
// config.apiKey,
|
|
126
|
+
// config.endpoint,
|
|
127
|
+
// payload
|
|
128
|
+
// );
|
|
129
|
+
// }
|
|
130
|
+
|
|
131
|
+
// export {
|
|
132
|
+
// init,
|
|
133
|
+
// capture,
|
|
134
|
+
// expressMiddleware
|
|
135
|
+
// };
|
|
136
|
+
|
|
137
|
+
// export default {
|
|
138
|
+
// init,
|
|
139
|
+
// capture,
|
|
140
|
+
// expressMiddleware
|
|
141
|
+
// };
|
package/src/middleware.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import { capture } from "./index.js";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Express error middleware
|
|
5
|
-
*/
|
|
6
|
-
export function expressMiddleware() {
|
|
7
|
-
return function (err, req, res, next) {
|
|
8
|
-
capture(err, {
|
|
9
|
-
url: req.originalUrl,
|
|
10
|
-
method: req.method,
|
|
11
|
-
ip: req.ip
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
next(err);
|
|
15
|
-
};
|
|
1
|
+
import { capture } from "./index.js";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Express error middleware
|
|
5
|
+
*/
|
|
6
|
+
export function expressMiddleware() {
|
|
7
|
+
return function (err, req, res, next) {
|
|
8
|
+
capture(err, {
|
|
9
|
+
url: req.originalUrl,
|
|
10
|
+
method: req.method,
|
|
11
|
+
ip: req.ip
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
next(err);
|
|
15
|
+
};
|
|
16
16
|
}
|
package/src/utils.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import os from "os";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Collect runtime metadata
|
|
5
|
-
*/
|
|
6
|
-
export function getMeta() {
|
|
7
|
-
return {
|
|
8
|
-
platform: os.platform() || process.platform,
|
|
9
|
-
arch: os.arch(),
|
|
10
|
-
nodeVersion: process.version,
|
|
11
|
-
hostname: os.hostname(),
|
|
12
|
-
memory: process.memoryUsage().rss
|
|
13
|
-
};
|
|
1
|
+
import os from "os";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Collect runtime metadata
|
|
5
|
+
*/
|
|
6
|
+
export function getMeta() {
|
|
7
|
+
return {
|
|
8
|
+
platform: os.platform() || process.platform,
|
|
9
|
+
arch: os.arch(),
|
|
10
|
+
nodeVersion: process.version,
|
|
11
|
+
hostname: os.hostname(),
|
|
12
|
+
memory: process.memoryUsage().rss
|
|
13
|
+
};
|
|
14
14
|
}
|