@cortenz/sdk
v0.1.2
Published
Official JavaScript/Node.js SDK for Cortenz monitoring
Maintainers
Readme
Cortenz JavaScript SDK
Official JavaScript/Node.js SDK for Cortenz monitoring platform.
Installation
npm install @cortenz/sdkQuick Start
import { createClient } from "@cortenz/sdk";
// Initialize the client
const cortenz = createClient({
apiUrl: "https://api.cortenz.dev", // or your self-hosted URL
token: "your-jwt-token",
projectId: "your-project-id",
});
// Capture an exception
try {
// Your code that might throw
throw new Error("Something went wrong");
} catch (error) {
await cortenz.captureException(error, {
url: "/api/users",
method: "GET",
environment: "production",
});
}
// Or report a custom error
await cortenz.reportError({
message: "Custom error message",
stackTrace: "Error stack trace...",
context: {
userId: "123",
action: "createUser",
},
});
// Send heartbeat for cron jobs
await cortenz.sendHeartbeat("monitor-id", "Job completed successfully", {
recordsProcessed: 1000,
duration: 5000,
});API Reference
createClient(config)
Creates a new Cortenz client instance.
config.apiUrl(string): The Cortenz API URLconfig.token(string): Your JWT authentication tokenconfig.projectId(string): Your project ID
client.captureException(error, context?)
Captures an exception and reports it to Cortenz.
error(Error): The Error object to capturecontext(object, optional): Additional context (URL, method, user info, etc.)
client.reportError(error)
Reports a custom error to Cortenz.
error.message(string): Error messageerror.stackTrace(string, optional): Stack traceerror.context(object, optional): Additional context
client.sendHeartbeat(monitorId, message?, metadata?)
Sends a heartbeat for cron/heartbeat monitoring.
monitorId(string): The monitor IDmessage(string, optional): Optional messagemetadata(object, optional): Optional metadata
License
MIT
