2018-11-24 09:56:41 +09:00
|
|
|
import { getSetting, sourceVersion } 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,
|
2018-11-24 09:56:41 +09:00
|
|
|
// see https://github.com/zodern/meteor-up/issues/807#issuecomment-346915622
|
|
|
|
release: sourceVersion,
|
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);
|