[call-me] - feat: integrate Sentry error monitoring

This commit is contained in:
Miroslav Pejic
2026-04-23 13:10:38 +02:00
parent e215c370b5
commit c7f63af48d
5 changed files with 975 additions and 10 deletions
+10
View File
@@ -67,3 +67,13 @@ PUSH_ENABLED=false # true or false
PUSH_VAPID_PUBLIC_KEY=''
PUSH_VAPID_PRIVATE_KEY=''
PUSH_VAPID_EMAIL='mailto:admin@example.com'
# Sentry
# 1. Goto https://sentry.io/
# 2. Create account
# 3. Goto Settings/Projects/YourProjectName/Client Keys (DSN)
SENTRY_ENABLED=false # true or false
SENTRY_LOG_LEVELS=error # Log levels to capture in Sentry (e.g., error,warn)
SENTRY_DSN=
SENTRY_TRACES_SAMPLE_RATE=0.5 # Adjust the sample rate for performance monitoring (0.0 to 1.0)
+26
View File
@@ -2,12 +2,33 @@
const util = require('util');
const colors = require('colors');
const Sentry = require('@sentry/node');
colors.enable(); // colors.disable();
const LOGS_DEBUG = process.env.LOGS_DEBUG !== undefined ? process.env.LOGS_DEBUG === 'true' : true;
const LOGS_JSON = process.env.LOGS_JSON ? process.env.LOGS_JSON === 'true' : false;
const LOGS_JSON_PRETTY = process.env.LOGS_JSON_PRETTY ? process.env.LOGS_JSON_PRETTY === 'true' : false;
const SENTRY_ENABLED = process.env.SENTRY_ENABLED === 'true';
const SENTRY_DSN = process.env.SENTRY_DSN;
const SENTRY_LOG_LEVELS = process.env.SENTRY_LOG_LEVELS
? process.env.SENTRY_LOG_LEVELS.split(',').map((l) => l.trim())
: ['error'];
function sentryCapture(level, msg, op) {
if (!SENTRY_ENABLED || !SENTRY_DSN || SENTRY_DSN === '') return;
if (!SENTRY_LOG_LEVELS.includes(level)) return;
if (level === 'error') {
const err = op instanceof Error ? op : new Error(String(msg));
Sentry.captureException(err, { extra: { message: msg, data: op } });
} else {
const sentryLevel = level === 'warn' ? 'warning' : level;
Sentry.captureMessage(String(msg), { level: sentryLevel, extra: { data: op } });
}
}
const options = {
depth: null,
colors: true,
@@ -41,6 +62,7 @@ module.exports = class Logs {
}
this.timeStart = Date.now();
}
sentryCapture('debug', msg, op);
}
log(msg, op = '') {
@@ -49,6 +71,7 @@ module.exports = class Logs {
} else {
console.log('[' + this.getDateTime() + '] [' + this.appName + '] ' + msg, util.inspect(op, options));
}
sentryCapture('log', msg, op);
}
info(msg, op = '') {
@@ -60,6 +83,7 @@ module.exports = class Logs {
util.inspect(op, options)
);
}
sentryCapture('info', msg, op);
}
warn(msg, op = '') {
@@ -71,6 +95,7 @@ module.exports = class Logs {
util.inspect(op, options)
);
}
sentryCapture('warn', msg, op);
}
error(msg, op = '') {
@@ -82,6 +107,7 @@ module.exports = class Logs {
util.inspect(op, options)
);
}
sentryCapture('error', msg, op);
}
jsonLog(level, appName, msg, op, extra = {}) {
const logObj = {
+22
View File
@@ -2,6 +2,21 @@
// Import necessary modules
const dotenv = require('dotenv').config();
// Sentry (initialize before all other modules so it can instrument them)
const Sentry = require('@sentry/node');
const sentryEnabled = process.env.SENTRY_ENABLED === 'true';
const sentryDsn = process.env.SENTRY_DSN;
const sentryTracesSampleRate = parseFloat(process.env.SENTRY_TRACES_SAMPLE_RATE) || 0.5;
if (sentryEnabled && sentryDsn && sentryDsn !== '') {
Sentry.init({
dsn: sentryDsn,
environment: process.env.NODE_ENV || 'development',
tracesSampleRate: sentryTracesSampleRate,
});
}
const express = require('express');
const cors = require('cors');
const fs = require('fs');
@@ -20,6 +35,8 @@ const packageJson = require('../package.json');
const logs = require('./logs');
const log = new logs('server');
//log.error('Sentry test error', new Error('This is a test error to verify Sentry integration'));
// Public directory location
const PUBLIC_DIR = path.join(__dirname, '../', 'public');
@@ -391,6 +408,11 @@ app.post('/api/hostPasswordValidate', (req, res) => {
res.json({ success: success });
});
// Sentry error handler (must be registered before other error handlers)
if (sentryEnabled && sentryDsn && sentryDsn !== '') {
Sentry.setupExpressErrorHandler(app);
}
// Page not found
app.use((req, res) => {
return notFound(res);
+915 -9
View File
File diff suppressed because it is too large Load Diff
+2 -1
View File
@@ -1,6 +1,6 @@
{
"name": "call-me",
"version": "1.3.41",
"version": "1.3.42",
"description": "Your Go-To for Instant Video Calls",
"author": "Miroslav Pejic - miroslav.pejic.85@gmail.com",
"license": "AGPLv3",
@@ -21,6 +21,7 @@
},
"dependencies": {
"@ngrok/ngrok": "1.7.0",
"@sentry/node": "^10.49.0",
"axios": "^1.15.2",
"colors": "^1.4.0",
"cors": "^2.8.6",