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

52 lines
1.1 KiB
JavaScript
Raw Normal View History

2018-11-04 16:34:19 +09:00
import { getSetting } from 'meteor/vulcan:core';
import { addInitFunction, addLogFunction, addUserFunction } from 'meteor/vulcan:errors';
import Sentry from '@sentry/browser';
import { clientDSNSetting } from '../modules/settings';
import { getUserObject } from '../modules/sentry';
const clientDSN = getSetting(clientDSNSetting);
2018-11-04 17:29:04 +09:00
const environment = getSetting('environment');
2018-11-04 16:34:19 +09:00
/*
Initialize Sentry
*/
function initSentryForClient() {
Sentry.init({
dsn: clientDSN,
2018-11-04 17:29:04 +09:00
environment,
2018-11-04 16:34:19 +09:00
});
}
addInitFunction(initSentryForClient);
/*
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);