2018-10-20 08:22:50 +02:00
|
|
|
const Sentry = require('@sentry/browser')
|
2018-04-03 18:51:33 +02:00
|
|
|
const METAMASK_DEBUG = process.env.METAMASK_DEBUG
|
2018-03-27 21:37:30 +02:00
|
|
|
const extractEthjsErrorMessage = require('./extractEthjsErrorMessage')
|
2018-10-20 08:22:50 +02:00
|
|
|
const SENTRY_DSN_PROD = 'https://3567c198f8a8412082d32655da2961d0@sentry.io/273505'
|
|
|
|
const SENTRY_DSN_DEV = 'https://f59f3dd640d2429d9d0e2445a87ea8e1@sentry.io/273496'
|
2018-01-17 23:59:15 +01:00
|
|
|
|
2018-10-20 08:22:50 +02:00
|
|
|
module.exports = setupSentry
|
2018-01-17 23:59:15 +01:00
|
|
|
|
2018-10-20 08:22:50 +02:00
|
|
|
// Setup sentry remote error reporting
|
|
|
|
function setupSentry (opts) {
|
2018-10-20 09:14:59 +02:00
|
|
|
const { release, getState } = opts
|
2018-10-20 08:22:50 +02:00
|
|
|
let sentryTarget
|
2018-07-19 08:22:56 +02:00
|
|
|
// detect brave
|
|
|
|
const isBrave = Boolean(window.chrome.ipcRenderer)
|
2018-01-17 23:59:15 +01:00
|
|
|
|
|
|
|
if (METAMASK_DEBUG) {
|
2018-10-20 08:22:50 +02:00
|
|
|
console.log('Setting up Sentry Remote Error Reporting: SENTRY_DSN_DEV')
|
|
|
|
sentryTarget = SENTRY_DSN_DEV
|
2018-01-17 23:59:15 +01:00
|
|
|
} else {
|
2018-10-20 08:22:50 +02:00
|
|
|
console.log('Setting up Sentry Remote Error Reporting: SENTRY_DSN_PROD')
|
|
|
|
sentryTarget = SENTRY_DSN_PROD
|
2018-01-17 23:59:15 +01:00
|
|
|
}
|
|
|
|
|
2018-10-20 08:22:50 +02:00
|
|
|
Sentry.init({
|
|
|
|
dsn: sentryTarget,
|
|
|
|
debug: METAMASK_DEBUG,
|
2018-08-09 22:49:40 +02:00
|
|
|
release,
|
2018-10-20 08:22:50 +02:00
|
|
|
beforeSend: (report) => rewriteReport(report),
|
|
|
|
})
|
2018-07-19 08:22:56 +02:00
|
|
|
|
2018-10-20 08:22:50 +02:00
|
|
|
Sentry.configureScope(scope => {
|
|
|
|
scope.setExtra('isBrave', isBrave)
|
2018-03-23 23:24:32 +01:00
|
|
|
})
|
2018-03-24 02:37:41 +01:00
|
|
|
|
2018-10-20 08:22:50 +02:00
|
|
|
function rewriteReport(report) {
|
|
|
|
try {
|
|
|
|
// simplify certain complex error messages (e.g. Ethjs)
|
|
|
|
simplifyErrorMessages(report)
|
|
|
|
// modify report urls
|
|
|
|
rewriteReportUrls(report)
|
2018-10-20 09:14:59 +02:00
|
|
|
// append app state
|
|
|
|
if (getState) {
|
|
|
|
const appState = getState()
|
|
|
|
report.extra.appState = appState
|
|
|
|
}
|
2018-10-20 08:22:50 +02:00
|
|
|
} catch (err) {
|
|
|
|
console.warn(err)
|
|
|
|
}
|
2018-10-20 09:14:59 +02:00
|
|
|
return report
|
2018-10-20 08:22:50 +02:00
|
|
|
}
|
2018-03-23 23:24:32 +01:00
|
|
|
|
2018-10-20 08:22:50 +02:00
|
|
|
return Sentry
|
2018-04-30 21:10:15 +02:00
|
|
|
}
|
|
|
|
|
2018-07-03 00:49:33 +02:00
|
|
|
function simplifyErrorMessages (report) {
|
2018-05-01 01:05:01 +02:00
|
|
|
rewriteErrorMessages(report, (errorMessage) => {
|
|
|
|
// simplify ethjs error messages
|
|
|
|
errorMessage = extractEthjsErrorMessage(errorMessage)
|
|
|
|
// simplify 'Transaction Failed: known transaction'
|
|
|
|
if (errorMessage.indexOf('Transaction Failed: known transaction') === 0) {
|
|
|
|
// cut the hash from the error message
|
|
|
|
errorMessage = 'Transaction Failed: known transaction'
|
|
|
|
}
|
|
|
|
return errorMessage
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2018-07-03 00:49:33 +02:00
|
|
|
function rewriteErrorMessages (report, rewriteFn) {
|
2018-05-01 01:05:01 +02:00
|
|
|
// rewrite top level message
|
2018-05-24 07:33:02 +02:00
|
|
|
if (typeof report.message === 'string') report.message = rewriteFn(report.message)
|
2018-05-01 01:05:01 +02:00
|
|
|
// rewrite each exception message
|
2018-04-30 21:07:48 +02:00
|
|
|
if (report.exception && report.exception.values) {
|
|
|
|
report.exception.values.forEach(item => {
|
2018-05-24 07:33:02 +02:00
|
|
|
if (typeof item.value === 'string') item.value = rewriteFn(item.value)
|
2018-04-30 21:07:48 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-03 00:49:33 +02:00
|
|
|
function rewriteReportUrls (report) {
|
2018-03-23 23:24:32 +01:00
|
|
|
// update request url
|
|
|
|
report.request.url = toMetamaskUrl(report.request.url)
|
|
|
|
// update exception stack trace
|
2018-04-29 22:46:07 +02:00
|
|
|
if (report.exception && report.exception.values) {
|
|
|
|
report.exception.values.forEach(item => {
|
|
|
|
item.stacktrace.frames.forEach(frame => {
|
|
|
|
frame.filename = toMetamaskUrl(frame.filename)
|
|
|
|
})
|
2018-03-23 23:24:32 +01:00
|
|
|
})
|
2018-04-29 22:46:07 +02:00
|
|
|
}
|
2018-03-23 23:24:32 +01:00
|
|
|
}
|
|
|
|
|
2018-07-03 00:49:33 +02:00
|
|
|
function toMetamaskUrl (origUrl) {
|
2018-03-23 23:24:32 +01:00
|
|
|
const filePath = origUrl.split(location.origin)[1]
|
|
|
|
if (!filePath) return origUrl
|
2018-03-24 02:37:41 +01:00
|
|
|
const metamaskUrl = `metamask${filePath}`
|
2018-03-23 23:24:32 +01:00
|
|
|
return metamaskUrl
|
|
|
|
}
|