@concordiq/error-sdk
v1.0.7
Published
Error monitoring SDK
Maintainers
Readme
📦 @concordiq/error-sdk
Official ConcordIQ Error Tracking SDK for Node.js and Express applications.
Easily capture, monitor, and analyze application errors with rich context and detailed stack traces.
✨ Features
- ✅ Manual error tracking
- ✅ Express middleware support
- ✅ Global crash handling
- ✅ TypeScript support
- ✅ Lightweight and fast
📥 Installation
Install the SDK using npm:
npm install @concordiq/error-sdk
## Initialize the SDK once when your application starts.
`Example (JavaScript / TypeScript)`
import ErrorSDK from "@concordiq/error-sdk";
ErrorSDK.init({
apiKey: "PROJECT_API_KEY",
endpoint: "https://api.mysaas.com/ingest/events",
env: "production",
service: "payment-api",
});
📌 Import Methods
`Choose the import style that fits your project.`
`✅ Default Import (Recommended)`
import ErrorSDK from "@concordiq/error-sdk";
ErrorSDK.init({ ... });
`✅ Named Import (Tree-Shaking Support)`
import { init, capture } from "@concordiq/error-sdk";
init({ ... });
`✅ CommonJS`
const ErrorSDK = require("@concordiq/error-sdk");
.
## 🚀 Recommended Usage in Controllers / Services
Using the SDK inside controllers and services is the best practice, especially for business-logic errors.
Example (Express + TypeScript)
import { Request, Response, NextFunction } from "express";
import ErrorSDK from "@concordiq/error-sdk";
export const createPayment = async (
req: Request,
res: Response,
next: NextFunction
) => {
try {
const { amount } = req.body;
if (!amount) {
throw new Error("Amount is required");
}
if (amount < 100) {
throw new Error("Minimum payment is 100");
}
res.status(201).json({
success: true,
message: "Payment created",
});
} catch (error: any) {
/**
* Capture error manually
*/
ErrorSDK.capture(error, {
controller: "createPayment",
message: error.message,
body: req.body,
stack: error.stack,
user: req.user?.name,
});
/**
* Forward to global error handler
*/
next(error);
}
};
# for Application entry points (e.g. Express routes), use the SDK middleware.
import ErrorSDK from "@concordiq/error-sdk";
import { Request, Response, NextFunction } from "express";
/**
* Initialize ErrorSDK once on application startup
*/
ErrorSDK.init({
apiKey: process.env.CONCORDIQ_API_KEY || "YOUR_API_KEY",
endpoint: "https://concordiq.onrender.com/api/v1/ingest/events",
env: process.env.NODE_ENV || "production",
service: "payment-api",
});
/**
* Custom Express error handler (Optional)
* Captures errors before forwarding to the global handler
*/
export function expressHandler() {
return (
err: Error,
req: Request,
res: Response,
next: NextFunction
) => {
ErrorSDK.capture(err, {
url: req.originalUrl,
method: req.method,
user: (req as any).user?.id,
});
next(err);
};
}
/**
* Register SDK middleware (MUST be last)
* Ensures all unhandled errors are captured
*/
app.use(ErrorSDK.expressMiddleware());
/**
* Confirm SDK initialization (Optional debug log)
*/
console.log("ErrorSDK successfully initialized");
💡 Why Use @concordiq/error-sdk?
This SDK provides rich, structured error reports including:
✔ Controller name
✔ User information
✔ Request payload
✔ Business context
✔ Stack trace
✔ Global error handling support
## Your dashboard becomes:
📊 Clear, actionable, and highly informative.
# 📊 Dashboard Data
# Each error report includes:
Application environment
Service name
Error message
Stack trace
Custom metadata
User/session details
This helps you debug issues faster and more accurately.