Wrapped analytics tracker in try-catch

no issue

- the analytice-node v4 update contains a breaking change that throws an
  exception if the message is over 32kb
- I'm pretty sure we won't hit this, but it's good to track these errors
  anyway and stop Ghost from bombing out if there's an issue
- this commit wraps the tracking call and adds Sentry + logging to the
  error
This commit is contained in:
Daniel Lockyer 2021-02-24 15:51:15 +00:00
parent 1d48d5af7c
commit 0db07b57a0

View File

@ -1,6 +1,8 @@
const _ = require('lodash');
const Analytics = require('analytics-node');
const config = require('../shared/config');
const logging = require('../shared/logging');
const sentry = require('../shared/sentry');
const {events} = require('./lib/common');
module.exports.init = function () {
@ -35,7 +37,12 @@ module.exports.init = function () {
// extract desired properties from eventData and rename keys if necessary
const data = _.mapValues(track.data || {}, v => eventData[v]);
analytics.track(_.extend(trackDefaults, data, {event: prefix + track.name}));
try {
analytics.track(_.extend(trackDefaults, data, {event: prefix + track.name}));
} catch (err) {
logging.error(err);
sentry.captureException(err);
}
});
});
};