From 37dc19a3524ffac394822b9f365d62b4d116db69 Mon Sep 17 00:00:00 2001 From: Mark Stacey Date: Tue, 18 May 2021 13:56:22 -0230 Subject: [PATCH] Migrate Sentry settings to environment variables (#11085) Sentry is now configured with environment variables, rather than with hard-coded values. This makes it easier to test Sentry functionality using a different Sentry account, as we did recently during QA of v9.5.1. The only change for the normal build process is the introduction of the `SENTRY_DSN_DEV` variable, which can be set via `.metamaskrc` or via an environment variable. This determines where error reports are sent. It still defaults to our team Sentry account's `metamask-testing` project. The `sentry:publish` script now requires SENTRY_ORG and SENTRY_PROJECT to be set in order to publish release artifacts. The CircleCI configuration has been updated with these values, so it should act the same as it did before. Previously we had used a CLI flag to specify the organization and project, but Sentry already natively supports these environment variables [1]. [1]: https://docs.sentry.io/product/cli/configuration/#configuration-values --- .circleci/config.yml | 2 +- app/scripts/lib/setupSentry.js | 3 +-- development/build/scripts.js | 4 ++++ development/sentry-publish.js | 26 +++++++++++--------------- development/sentry-upload-artifacts.sh | 8 +++++++- 5 files changed, 24 insertions(+), 19 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 1a62e1cf7..6648b608d 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -505,7 +505,7 @@ jobs: at: . - run: name: sentry sourcemaps upload - command: yarn sentry:publish + command: SENTRY_ORG=metamask SENTRY_PROJECT=metamask yarn sentry:publish - run: name: Create GitHub release command: | diff --git a/app/scripts/lib/setupSentry.js b/app/scripts/lib/setupSentry.js index 09482d24b..25bbd7a46 100644 --- a/app/scripts/lib/setupSentry.js +++ b/app/scripts/lib/setupSentry.js @@ -7,9 +7,8 @@ import extractEthjsErrorMessage from './extractEthjsErrorMessage'; // Destructuring breaks the inlining of the environment variables const METAMASK_DEBUG = process.env.METAMASK_DEBUG; const METAMASK_ENVIRONMENT = process.env.METAMASK_ENVIRONMENT; +const SENTRY_DSN_DEV = process.env.SENTRY_DSN_DEV; /* eslint-enable prefer-destructuring */ -const SENTRY_DSN_DEV = - 'https://f59f3dd640d2429d9d0e2445a87ea8e1@sentry.io/273496'; // This describes the subset of Redux state attached to errors sent to Sentry // These properties have some potential to be useful for debugging, and they do diff --git a/development/build/scripts.js b/development/build/scripts.js index c66a31e33..f0e399d47 100644 --- a/development/build/scripts.js +++ b/development/build/scripts.js @@ -20,6 +20,9 @@ const metamaskrc = require('rc')('metamask', { SEGMENT_HOST: process.env.SEGMENT_HOST, SEGMENT_WRITE_KEY: process.env.SEGMENT_WRITE_KEY, SEGMENT_LEGACY_WRITE_KEY: process.env.SEGMENT_LEGACY_WRITE_KEY, + SENTRY_DSN_DEV: + process.env.SENTRY_DSN_DEV || + 'https://f59f3dd640d2429d9d0e2445a87ea8e1@sentry.io/273496', }); const { version } = require('../../package.json'); @@ -431,6 +434,7 @@ function getEnvironmentVariables({ devMode, testing }) { PUBNUB_PUB_KEY: process.env.PUBNUB_PUB_KEY || '', CONF: devMode ? metamaskrc : {}, SENTRY_DSN: process.env.SENTRY_DSN, + SENTRY_DSN_DEV: metamaskrc.SENTRY_DSN_DEV, INFURA_PROJECT_ID: testing ? '00000000000000000000000000000000' : metamaskrc.INFURA_PROJECT_ID, diff --git a/development/sentry-publish.js b/development/sentry-publish.js index 6fee0f950..1ff7b0eb6 100644 --- a/development/sentry-publish.js +++ b/development/sentry-publish.js @@ -11,6 +11,12 @@ start().catch((error) => { }); async function start() { + if (!process.env.SENTRY_ORG) { + throw new Error('Missing required "SENTRY_ORG" environment variable'); + } else if (!process.env.SENTRY_PROJECT) { + throw new Error('Missing required "SENTRY_PROJECT" environment variable'); + } + const authWorked = await checkIfAuthWorks(); if (!authWorked) { throw new Error(`Sentry auth failed`); @@ -25,15 +31,11 @@ async function start() { } else { // create sentry release console.log(`creating Sentry release for "${VERSION}"...`); - await exec( - `sentry-cli releases --org 'metamask' --project 'metamask' new ${VERSION}`, - ); + await exec(`sentry-cli releases new ${VERSION}`); console.log( `removing any existing files from Sentry release "${VERSION}"...`, ); - await exec( - `sentry-cli releases --org 'metamask' --project 'metamask' files ${VERSION} delete --all`, - ); + await exec(`sentry-cli releases files ${VERSION} delete --all`); } // check if version has artifacts or not @@ -52,26 +54,20 @@ async function start() { async function checkIfAuthWorks() { const itWorked = await doesNotFail(async () => { - await exec( - `sentry-cli releases --org 'metamask' --project 'metamask' list`, - ); + await exec(`sentry-cli releases list`); }); return itWorked; } async function checkIfVersionExists() { const versionAlreadyExists = await doesNotFail(async () => { - await exec( - `sentry-cli releases --org 'metamask' --project 'metamask' info ${VERSION}`, - ); + await exec(`sentry-cli releases info ${VERSION}`); }); return versionAlreadyExists; } async function checkIfVersionHasArtifacts() { - const artifacts = await exec( - `sentry-cli releases --org 'metamask' --project 'metamask' files ${VERSION} list`, - ); + const artifacts = await exec(`sentry-cli releases files ${VERSION} list`); // When there's no artifacts, we get a response from the shell like this ['', ''] return artifacts[0] && artifacts[0].length > 0; } diff --git a/development/sentry-upload-artifacts.sh b/development/sentry-upload-artifacts.sh index 3a605eff2..71f88c750 100755 --- a/development/sentry-upload-artifacts.sh +++ b/development/sentry-upload-artifacts.sh @@ -30,7 +30,7 @@ EOF function upload_sourcemaps { local release="${1}"; shift - sentry-cli releases --org 'metamask' --project 'metamask' files "${release}" upload-sourcemaps ./dist/chrome/*.js ./dist/sourcemaps/ --rewrite --url-prefix 'metamask' + sentry-cli releases files "${release}" upload-sourcemaps ./dist/chrome/*.js ./dist/sourcemaps/ --rewrite --url-prefix 'metamask' } function main { @@ -62,6 +62,12 @@ function main { if [[ -z $release ]] then die 'Required parameter "release" missing; either include parameter or set VERSION environment variable' + elif [[ -z $SENTRY_ORG ]] + then + die 'Required environment variable "SENTRY_ORG" missing' + elif [[ -z $SENTRY_PROJECT ]] + then + die 'Required environment variable "SENTRY_PROJECT" missing' fi printf 'uploading source files and sourcemaps for Sentry release "%s"...\n' "${release}"