Vulcan/packages/vulcan-errors-sentry/lib/server/sentry-server.js

54 lines
1.2 KiB
JavaScript
Raw Normal View History

2018-11-27 09:39:51 +09:00
import { getSetting, getSourceVersion } from 'meteor/vulcan:core';
2018-11-04 16:34:19 +09:00
import { addInitFunction, addLogFunction, addUserFunction } from 'meteor/vulcan:errors';
import { serverDSNSetting } from '../modules/settings';
import Sentry from '@sentry/node';
import { getUserObject } from '../modules/sentry';
const serverDSN = getSetting(serverDSNSetting);
2018-11-04 17:29:04 +09:00
const environment = getSetting('environment');
2018-11-04 16:34:19 +09:00
/*
Initialize Sentry
*/
function initSentryForServer() {
Sentry.init({
dsn: serverDSN,
2018-11-04 17:29:04 +09:00
environment,
// see https://github.com/zodern/meteor-up/issues/807#issuecomment-346915622
2018-11-27 09:39:51 +09:00
release: getSourceVersion(),
2018-11-04 16:34:19 +09:00
});
}
addInitFunction(initSentryForServer);
/*
Log an error, and optionally set current user as well
*/
function logToSentry({ error, details, currentUser }) {
Sentry.withScope(scope => {
if (currentUser) {
scope.setUser(getUserObject(currentUser));
}
Object.keys(details).forEach(key => {
scope.setExtra(key, details[key]);
});
Sentry.captureException(error);
});
}
addLogFunction(logToSentry);
/*
Set the current user
*/
function setSentryUser(currentUser) {
Sentry.configureScope(scope => {
scope.setUser(getUserObject(currentUser));
});
}
addUserFunction(setSentryUser);