|
|
|
import _ from 'lodash';
|
|
|
|
import * as sentry from '@sentry/browser';
|
|
|
|
import * as Integrations from '@sentry/integrations';
|
|
|
|
import parseUrl from 'Utilities/String/parseUrl';
|
|
|
|
|
|
|
|
function cleanseUrl(url) {
|
|
|
|
const properties = parseUrl(url);
|
|
|
|
|
|
|
|
return `${properties.pathname}${properties.search}`;
|
|
|
|
}
|
|
|
|
|
|
|
|
function cleanseData(data) {
|
|
|
|
const result = _.cloneDeep(data);
|
|
|
|
|
|
|
|
result.transaction = cleanseUrl(result.transaction);
|
|
|
|
|
|
|
|
if (result.exception) {
|
|
|
|
result.exception.values.forEach((exception) => {
|
|
|
|
const stacktrace = exception.stacktrace;
|
|
|
|
|
|
|
|
if (stacktrace) {
|
|
|
|
stacktrace.frames.forEach((frame) => {
|
|
|
|
frame.filename = cleanseUrl(frame.filename);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
result.request.url = cleanseUrl(result.request.url);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
function identity(stuff) {
|
|
|
|
return stuff;
|
|
|
|
}
|
|
|
|
|
|
|
|
function stripUrlBase(frame) {
|
|
|
|
if (frame.filename && window.Radarr.urlBase) {
|
|
|
|
frame.filename = frame.filename.replace(window.Radarr.urlBase, '');
|
|
|
|
}
|
|
|
|
return frame;
|
|
|
|
}
|
|
|
|
|
|
|
|
function createMiddleware() {
|
|
|
|
return (store) => (next) => (action) => {
|
|
|
|
try {
|
|
|
|
// Adds a breadcrumb for reporting later (if necessary).
|
|
|
|
sentry.addBreadcrumb({
|
|
|
|
category: 'redux',
|
|
|
|
message: action.type
|
|
|
|
});
|
|
|
|
|
|
|
|
return next(action);
|
|
|
|
} catch (err) {
|
|
|
|
console.error(`[sentry] Reporting error to Sentry: ${err}`);
|
|
|
|
|
|
|
|
// Send the report including breadcrumbs.
|
|
|
|
sentry.captureException(err, {
|
|
|
|
extra: {
|
|
|
|
action: identity(action),
|
|
|
|
state: identity(store.getState())
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export default function createSentryMiddleware() {
|
|
|
|
const {
|
|
|
|
analytics,
|
|
|
|
branch,
|
|
|
|
version,
|
|
|
|
release,
|
|
|
|
userHash,
|
|
|
|
isProduction
|
|
|
|
} = window.Radarr;
|
|
|
|
|
|
|
|
if (!analytics) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const dsn = isProduction ? 'https://cf0559cfe5c84ccfae3d907daef1b6bb@sentry.io/1523530' :
|
|
|
|
'https://df167d10dc51480b9e4f22e4e77c7315@sentry.io/1523531';
|
|
|
|
|
|
|
|
sentry.init({
|
|
|
|
dsn,
|
|
|
|
environment: branch,
|
|
|
|
release,
|
|
|
|
sendDefaultPii: true,
|
|
|
|
beforeSend: cleanseData,
|
|
|
|
integrations: [new Integrations.RewriteFrames({ iteratee: stripUrlBase })]
|
|
|
|
});
|
|
|
|
|
|
|
|
sentry.configureScope((scope) => {
|
|
|
|
scope.setUser({ username: userHash });
|
|
|
|
scope.setTag('version', version);
|
|
|
|
scope.setTag('production', isProduction);
|
|
|
|
});
|
|
|
|
|
|
|
|
return createMiddleware();
|
|
|
|
}
|