@concordiq/error-sdk 1.0.0 → 1.0.2
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 -10
- package/readMe.md +79 -65
- package/src/client.js +22 -19
- package/src/handlers.js +14 -32
- package/src/index.d.ts +30 -0
- package/src/index.js +72 -57
- package/src/middleware.js +16 -0
- package/src/utils.js +14 -9
package/package.json
CHANGED
|
@@ -1,10 +1,32 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@concordiq/error-sdk",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
"type": "module",
|
|
7
|
-
"
|
|
8
|
-
"
|
|
9
|
-
"
|
|
10
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "@concordiq/error-sdk",
|
|
3
|
+
"version": "1.0.2",
|
|
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,65 +1,79 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
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
|
+
* Must be last middleware
|
|
64
|
+
*/
|
|
65
|
+
app.use(ErrorSDK.expressMiddleware());
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
## Features:
|
|
70
|
+
|
|
71
|
+
1. Manual error tracking
|
|
72
|
+
|
|
73
|
+
2. Express middleware
|
|
74
|
+
|
|
75
|
+
3. Global crash handling
|
|
76
|
+
|
|
77
|
+
4. TypeScript support
|
|
78
|
+
|
|
79
|
+
5. Lightweight
|
package/src/client.js
CHANGED
|
@@ -1,19 +1,22 @@
|
|
|
1
|
-
import fetch from "node-fetch";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}
|
|
19
|
-
|
|
1
|
+
import fetch from "node-fetch";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Send error to ConcordIQ API
|
|
5
|
+
*/
|
|
6
|
+
export async function sendError(apiKey, endpoint, payload) {
|
|
7
|
+
try {
|
|
8
|
+
await fetch(endpoint, {
|
|
9
|
+
method: "POST",
|
|
10
|
+
|
|
11
|
+
headers: {
|
|
12
|
+
"Content-Type": "application/json",
|
|
13
|
+
Authorization: apiKey
|
|
14
|
+
},
|
|
15
|
+
|
|
16
|
+
body: JSON.stringify(payload)
|
|
17
|
+
});
|
|
18
|
+
} catch (err) {
|
|
19
|
+
// Avoid crashing user app
|
|
20
|
+
console.error("[ErrorSDK] Failed to send error:", err);
|
|
21
|
+
}
|
|
22
|
+
}
|
package/src/handlers.js
CHANGED
|
@@ -1,32 +1,14 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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
|
-
}
|
|
1
|
+
import { capture } from "./index.js";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Attach process-level handlers
|
|
5
|
+
*/
|
|
6
|
+
export function attachHandlers() {
|
|
7
|
+
process.on("uncaughtException", (err) => {
|
|
8
|
+
capture(err);
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
process.on("unhandledRejection", (err) => {
|
|
12
|
+
capture(err);
|
|
13
|
+
});
|
|
14
|
+
}
|
package/src/index.d.ts
ADDED
|
@@ -0,0 +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
|
+
|
|
30
|
+
export default ErrorSDK;
|
package/src/index.js
CHANGED
|
@@ -1,57 +1,72 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { sendError } from "./client.js";
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
apiKey
|
|
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
|
-
|
|
1
|
+
import { expressMiddleware } from "./middleware.js";
|
|
2
|
+
import { sendError } from "./client.js";
|
|
3
|
+
import { attachHandlers } from "./handlers.js";
|
|
4
|
+
import { getMeta } from "./utils.js";
|
|
5
|
+
|
|
6
|
+
let config = null;
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Initialize SDK
|
|
10
|
+
*/
|
|
11
|
+
function init(options) {
|
|
12
|
+
if (!options?.apiKey) {
|
|
13
|
+
throw new Error("apiKey is required");
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
config = {
|
|
17
|
+
apiKey: options.apiKey,
|
|
18
|
+
|
|
19
|
+
endpoint:
|
|
20
|
+
options.endpoint ||
|
|
21
|
+
"https://concordiq.onrender.com/api/v1/ingest/events",
|
|
22
|
+
|
|
23
|
+
env: options.env || "production",
|
|
24
|
+
|
|
25
|
+
service: options.service || "app"
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
attachHandlers(config);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Capture error manually
|
|
33
|
+
*/
|
|
34
|
+
async function capture(error, extra = {}) {
|
|
35
|
+
if (!config) return;
|
|
36
|
+
|
|
37
|
+
const payload = {
|
|
38
|
+
message: error?.message || String(error),
|
|
39
|
+
|
|
40
|
+
stack: error?.stack,
|
|
41
|
+
|
|
42
|
+
type: "manual",
|
|
43
|
+
|
|
44
|
+
env: config.env,
|
|
45
|
+
service: config.service,
|
|
46
|
+
|
|
47
|
+
meta: {
|
|
48
|
+
...getMeta(),
|
|
49
|
+
...extra
|
|
50
|
+
},
|
|
51
|
+
|
|
52
|
+
timestamp: new Date().toISOString()
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
await sendError(
|
|
56
|
+
config.apiKey,
|
|
57
|
+
config.endpoint,
|
|
58
|
+
payload
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export {
|
|
63
|
+
init,
|
|
64
|
+
capture,
|
|
65
|
+
expressMiddleware
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
export default {
|
|
69
|
+
init,
|
|
70
|
+
capture,
|
|
71
|
+
expressMiddleware
|
|
72
|
+
};
|
|
@@ -0,0 +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
|
+
};
|
|
16
|
+
}
|
package/src/utils.js
CHANGED
|
@@ -1,9 +1,14 @@
|
|
|
1
|
-
import os from "os";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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
|
+
}
|