Skip to content

Commit

Permalink
Add Sentry environment (MetaMask#7923)
Browse files Browse the repository at this point in the history
Any error sent to Sentry will now be marked with the environment they
were sent from. The environment is set at build time, and is set
dependant upon the build flags and CI-related environment variables.

Setting the environment will let us filter error reports in Sentry to
focus specifically upon reports sent from production, release
candidates, PR testing, or whatever else.
  • Loading branch information
Gudahtt authored and yqrashawn committed Feb 10, 2020
1 parent accde31 commit f935bfe
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 16 deletions.
13 changes: 9 additions & 4 deletions app/scripts/lib/setupSentry.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import * as Sentry from '@sentry/browser'
import { Dedupe, ExtraErrorData } from '@sentry/integrations'

const METAMASK_DEBUG = process.env.METAMASK_DEBUG
import extractEthjsErrorMessage from './extractEthjsErrorMessage'

const METAMASK_DEBUG = process.env.METAMASK_DEBUG
const METAMASK_ENVIRONMENT = process.env.METAMASK_ENVIRONMENT
const SENTRY_DSN_PROD =
'https://9f364c1e50ff4c8b96f279b236019359@sentry.conflux-chain.org/10'
const SENTRY_DSN_DEV =
Expand All @@ -19,17 +20,21 @@ function setupSentry (opts) {
const isBrave = Boolean(window.chrome.ipcRenderer)

if (METAMASK_DEBUG || process.env.IN_TEST) {
console.log('Setting up Sentry Remote Error Reporting: SENTRY_DSN_DEV')
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: SENTRY_DSN_PROD')
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,
integrations: [new Dedupe(), new ExtraErrorData()],
environment: METAMASK_ENVIRONMENT,
integrations: [
new Dedupe(),
new ExtraErrorData(),
],
release,
beforeSend: report => rewriteReport(report),
})
Expand Down
39 changes: 27 additions & 12 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -662,19 +662,34 @@ function generateBundler (opts, performBundle) {
bundler = bundler.external(opts.externalDependencies)
}

let environment
if (opts.devMode) {
environment = 'development'
} else if (opts.testing) {
environment = 'testing'
} else if (process.env.CIRCLE_BRANCH === 'master') {
environment = 'production'
} else if (/^Version-v(\d+)[.](\d+)[.](\d+)/.test(process.env.CIRCLE_BRANCH)) {
environment = 'release-candidate'
} else if (process.env.CIRCLE_BRANCH === 'develop') {
environment = 'staging'
} else if (process.env.CIRCLE_PULL_REQUEST) {
environment = 'pull-request'
} else {
environment = 'other'
}

// Inject variables into bundle
bundler.transform(
envify({
METAMASK_DEBUG: opts.devMode,
NODE_ENV: opts.devMode ? 'development' : 'production',
IN_TEST: opts.testing,
PUBNUB_SUB_KEY: process.env.PUBNUB_SUB_KEY || '',
PUBNUB_PUB_KEY: process.env.PUBNUB_PUB_KEY || '',
}),
{
global: true,
}
)
bundler.transform(envify({
METAMASK_DEBUG: opts.devMode,
METAMASK_ENVIRONMENT: environment,
NODE_ENV: opts.devMode ? 'development' : 'production',
IN_TEST: opts.testing,
PUBNUB_SUB_KEY: process.env.PUBNUB_SUB_KEY || '',
PUBNUB_PUB_KEY: process.env.PUBNUB_PUB_KEY || '',
}), {
global: true,
})

if (opts.watch) {
bundler = watchify(bundler)
Expand Down

0 comments on commit f935bfe

Please sign in to comment.