[mirotalksfu] - improve Sentry logs

هذا الالتزام موجود في:
Miroslav Pejic
2025-07-03 20:59:21 +02:00
الأصل 5c4e110f23
التزام 3292e7d058
8 ملفات معدلة مع 32 إضافات و21 حذوفات

عرض الملف

@@ -178,7 +178,7 @@ const restApi = {
// Sentry monitoring
const sentryEnabled = config.integrations?.sentry?.enabled || false;
const sentryDSN = config.integrations.sentry.DSN;
const sentryTracesSampleRate = parseFloat(config.integrations.sentry.tracesSampleRate || '0.0');
const sentryTracesSampleRate = config.integrations.sentry.tracesSampleRate;
if (sentryEnabled && typeof sentryDSN === 'string' && sentryDSN.trim()) {
log.info('Sentry monitoring started...');
@@ -187,20 +187,26 @@ if (sentryEnabled && typeof sentryDSN === 'string' && sentryDSN.trim()) {
tracesSampleRate: sentryTracesSampleRate,
});
const originalWarn = console.warn;
const originalError = console.error;
// Accept logLevels as an array, e.g., ['warn', 'error']
const logLevels = config.integrations?.sentry?.logLevels || ['error'];
console.warn = function (...args) {
//Sentry.captureMessage(args.join(' '), 'warning');
originalWarn.apply(console, args);
};
console.error = function (...args) {
args[0] instanceof Error
? Sentry.captureException(args[0])
: Sentry.captureException(new Error(args.join(' ')));
originalError.apply(console, args);
};
const originalConsole = {};
logLevels.forEach((level) => {
originalConsole[level] = console[level];
console[level] = function (...args) {
switch (level) {
case 'warn':
Sentry.captureMessage(args.join(' '), 'warning');
break;
case 'error':
args[0] instanceof Error
? Sentry.captureException(args[0])
: Sentry.captureException(new Error(args.join(' ')));
break;
}
originalConsole[level].apply(console, args);
};
});
// log.error('Sentry error', { foo: 'bar' });
// log.warn('Sentry warning');

عرض الملف

@@ -830,6 +830,7 @@ module.exports = {
* Core Settings:
* -------------
* enabled : Enable/disable Sentry [true/false] (default: false)
* logLevels : Array of log levels to capture (default: ['error'])
* DSN : Data Source Name (from Sentry dashboard)
* tracesSampleRate : Percentage of transactions to capture (0.0-1.0)
*
@@ -842,6 +843,9 @@ module.exports = {
*/
sentry: {
enabled: process.env.SENTRY_ENABLED === 'true',
logLevels: process.env.SENTRY_LOG_LEVELS
? process.env.SENTRY_LOG_LEVELS.split(splitChar).map((level) => level.trim())
: ['error'],
DSN: process.env.SENTRY_DSN || '',
tracesSampleRate: Math.min(Math.max(parseFloat(process.env.SENTRY_TRACES_SAMPLE_RATE) || 0.5, 0), 1),
},