mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
37da64aa7e
The state snapshot we were attaching to Sentry errors was too large. As a temporary solution, it has been removed completely. We can re-add it later after reducing its size.
106 lines
3.0 KiB
JavaScript
106 lines
3.0 KiB
JavaScript
import * as Sentry from '@sentry/browser'
|
|
import { Dedupe, ExtraErrorData } from '@sentry/integrations'
|
|
|
|
import extractEthjsErrorMessage from './extractEthjsErrorMessage'
|
|
|
|
const METAMASK_DEBUG = process.env.METAMASK_DEBUG
|
|
const METAMASK_ENVIRONMENT = process.env.METAMASK_ENVIRONMENT
|
|
const SENTRY_DSN_PROD = 'https://3567c198f8a8412082d32655da2961d0@sentry.io/273505'
|
|
const SENTRY_DSN_DEV = 'https://f59f3dd640d2429d9d0e2445a87ea8e1@sentry.io/273496'
|
|
|
|
export default function setupSentry ({ release }) {
|
|
let sentryTarget
|
|
// detect brave
|
|
const isBrave = Boolean(window.chrome.ipcRenderer)
|
|
|
|
if (METAMASK_DEBUG || process.env.IN_TEST) {
|
|
console.log(`Setting up Sentry Remote Error Reporting for '${METAMASK_ENVIRONMENT}': SENTRY_DSN_DEV`)
|
|
sentryTarget = SENTRY_DSN_DEV
|
|
} else {
|
|
console.log(`Setting up Sentry Remote Error Reporting for '${METAMASK_ENVIRONMENT}': SENTRY_DSN_PROD`)
|
|
sentryTarget = SENTRY_DSN_PROD
|
|
}
|
|
|
|
Sentry.init({
|
|
dsn: sentryTarget,
|
|
debug: METAMASK_DEBUG,
|
|
environment: METAMASK_ENVIRONMENT,
|
|
integrations: [
|
|
new Dedupe(),
|
|
new ExtraErrorData(),
|
|
],
|
|
release,
|
|
beforeSend: (report) => rewriteReport(report),
|
|
})
|
|
|
|
Sentry.configureScope((scope) => {
|
|
scope.setExtra('isBrave', isBrave)
|
|
})
|
|
|
|
function rewriteReport (report) {
|
|
try {
|
|
// simplify certain complex error messages (e.g. Ethjs)
|
|
simplifyErrorMessages(report)
|
|
// modify report urls
|
|
rewriteReportUrls(report)
|
|
} catch (err) {
|
|
console.warn(err)
|
|
}
|
|
return report
|
|
}
|
|
|
|
return Sentry
|
|
}
|
|
|
|
function simplifyErrorMessages (report) {
|
|
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
|
|
})
|
|
}
|
|
|
|
function rewriteErrorMessages (report, rewriteFn) {
|
|
// rewrite top level message
|
|
if (typeof report.message === 'string') {
|
|
report.message = rewriteFn(report.message)
|
|
}
|
|
// rewrite each exception message
|
|
if (report.exception && report.exception.values) {
|
|
report.exception.values.forEach((item) => {
|
|
if (typeof item.value === 'string') {
|
|
item.value = rewriteFn(item.value)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
function rewriteReportUrls (report) {
|
|
// update request url
|
|
report.request.url = toMetamaskUrl(report.request.url)
|
|
// update exception stack trace
|
|
if (report.exception && report.exception.values) {
|
|
report.exception.values.forEach((item) => {
|
|
if (item.stacktrace) {
|
|
item.stacktrace.frames.forEach((frame) => {
|
|
frame.filename = toMetamaskUrl(frame.filename)
|
|
})
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
function toMetamaskUrl (origUrl) {
|
|
const filePath = origUrl.split(window.location.origin)[1]
|
|
if (!filePath) {
|
|
return origUrl
|
|
}
|
|
const metamaskUrl = `metamask${filePath}`
|
|
return metamaskUrl
|
|
}
|