all files / clay-log/plugins/ sentry.js

90% Statements 9/10
50% Branches 2/4
100% Functions 1/1
90% Lines 9/10
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                                       
'use strict';
 
const Sentry = require('@sentry/node');
 
const { wrap } = require('./_utils');
 
Sentry.init({
  dsn: process.env.SENTRY_DSN,
  onunhandledrejection: false
});
 
/**
 * Reports error-level logs to Sentry.
 *
 * @param {object} data: The Error or data to report.
 * @param {string} msg: The name of the Error.
 */
function wrapper(data, msg) {
  Iif (msg instanceof Error) {
    Sentry.captureException(msg, { extra: data });
  } else {
    const err = new Error(msg);
    err.stack = data instanceof Object ? data.stack : '';
    Sentry.captureException(err, { extra: data });
  }
}
 
module.exports = wrap(wrapper, ['error']);