Add build type to Sentry environment (#12441)

The build type (i.e. the distribution) is now included in the Sentry
environment during setup, for all builds except the "main" build. This
will allow us to track Flask and beta errors separately from other
errors.

A constant was created for the build types. The equivalent constant in
our build scripts was updated to match it more closely, for
consistency. We can't use the same constant in both places because our
shared constants are in modules that use ES6 exports, and our build
script does not yet support ES6 exports.

The singular `BuildType` was used rather than `BuildTypes` to match our
naming conventions elsewhere for enums. We name them like classes or
types, rather than like a collection.

Relates to #11896
feature/default_network_editable
Mark Stacey 3 years ago committed by GitHub
parent 06fafae7b4
commit 345ed9f6f2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 9
      app/scripts/lib/setupSentry.js
  2. 4
      development/build/etc.js
  3. 6
      development/build/index.js
  4. 4
      development/build/manifest.js
  5. 4
      development/build/static.js
  6. 6
      development/build/transforms/remove-fenced-code.js
  7. 30
      development/build/transforms/remove-fenced-code.test.js
  8. 11
      development/build/utils.js
  9. 11
      shared/constants/app.js

@ -1,6 +1,7 @@
import * as Sentry from '@sentry/browser'; import * as Sentry from '@sentry/browser';
import { Dedupe, ExtraErrorData } from '@sentry/integrations'; import { Dedupe, ExtraErrorData } from '@sentry/integrations';
import { BuildType } from '../../../shared/constants/app';
import extractEthjsErrorMessage from './extractEthjsErrorMessage'; import extractEthjsErrorMessage from './extractEthjsErrorMessage';
/* eslint-disable prefer-destructuring */ /* eslint-disable prefer-destructuring */
@ -8,6 +9,7 @@ import extractEthjsErrorMessage from './extractEthjsErrorMessage';
const METAMASK_DEBUG = process.env.METAMASK_DEBUG; const METAMASK_DEBUG = process.env.METAMASK_DEBUG;
const METAMASK_ENVIRONMENT = process.env.METAMASK_ENVIRONMENT; const METAMASK_ENVIRONMENT = process.env.METAMASK_ENVIRONMENT;
const SENTRY_DSN_DEV = process.env.SENTRY_DSN_DEV; const SENTRY_DSN_DEV = process.env.SENTRY_DSN_DEV;
const METAMASK_BUILD_TYPE = process.env.METAMASK_BUILD_TYPE;
/* eslint-enable prefer-destructuring */ /* eslint-enable prefer-destructuring */
// This describes the subset of Redux state attached to errors sent to Sentry // This describes the subset of Redux state attached to errors sent to Sentry
@ -87,10 +89,15 @@ export default function setupSentry({ release, getState }) {
sentryTarget = SENTRY_DSN_DEV; sentryTarget = SENTRY_DSN_DEV;
} }
const environment =
METAMASK_BUILD_TYPE === BuildType.main
? METAMASK_ENVIRONMENT
: `${METAMASK_ENVIRONMENT}-${METAMASK_BUILD_TYPE}`;
Sentry.init({ Sentry.init({
dsn: sentryTarget, dsn: sentryTarget,
debug: METAMASK_DEBUG, debug: METAMASK_DEBUG,
environment: METAMASK_ENVIRONMENT, environment,
integrations: [new Dedupe(), new ExtraErrorData()], integrations: [new Dedupe(), new ExtraErrorData()],
release, release,
beforeSend: (report) => rewriteReport(report), beforeSend: (report) => rewriteReport(report),

@ -6,7 +6,7 @@ const pify = require('pify');
const pump = pify(require('pump')); const pump = pify(require('pump'));
const { version } = require('../../package.json'); const { version } = require('../../package.json');
const { createTask, composeParallel } = require('./task'); const { createTask, composeParallel } = require('./task');
const { BuildTypes } = require('./utils'); const { BuildType } = require('./utils');
module.exports = createEtcTasks; module.exports = createEtcTasks;
@ -38,7 +38,7 @@ function createEtcTasks({ browserPlatforms, buildType, livereload }) {
function createZipTask(platform, buildType) { function createZipTask(platform, buildType) {
return async () => { return async () => {
const path = const path =
buildType === BuildTypes.main buildType === BuildType.main
? `metamask-${platform}-${version}` ? `metamask-${platform}-${version}`
: `metamask-${buildType}-${platform}-${version}`; : `metamask-${buildType}-${platform}-${version}`;
await pump( await pump(

@ -16,7 +16,7 @@ const createScriptTasks = require('./scripts');
const createStyleTasks = require('./styles'); const createStyleTasks = require('./styles');
const createStaticAssetTasks = require('./static'); const createStaticAssetTasks = require('./static');
const createEtcTasks = require('./etc'); const createEtcTasks = require('./etc');
const { BuildTypes, getBrowserVersionMap } = require('./utils'); const { BuildType, getBrowserVersionMap } = require('./utils');
// packages required dynamically via browserify configuration in dependencies // packages required dynamically via browserify configuration in dependencies
require('loose-envify'); require('loose-envify');
@ -149,7 +149,7 @@ function parseArgv() {
], ],
string: [NamedArgs.BuildType], string: [NamedArgs.BuildType],
default: { default: {
[NamedArgs.BuildType]: BuildTypes.main, [NamedArgs.BuildType]: BuildType.main,
[NamedArgs.LintFenceFiles]: true, [NamedArgs.LintFenceFiles]: true,
[NamedArgs.OmitLockdown]: false, [NamedArgs.OmitLockdown]: false,
[NamedArgs.SkipStats]: false, [NamedArgs.SkipStats]: false,
@ -168,7 +168,7 @@ function parseArgv() {
} }
const buildType = argv[NamedArgs.BuildType]; const buildType = argv[NamedArgs.BuildType];
if (!(buildType in BuildTypes)) { if (!(buildType in BuildType)) {
throw new Error(`MetaMask build: Invalid build type: "${buildType}"`); throw new Error(`MetaMask build: Invalid build type: "${buildType}"`);
} }

@ -6,7 +6,7 @@ const baseManifest = require('../../app/manifest/_base.json');
const betaManifestModifications = require('../../app/manifest/_beta_modifications.json'); const betaManifestModifications = require('../../app/manifest/_beta_modifications.json');
const { createTask, composeSeries } = require('./task'); const { createTask, composeSeries } = require('./task');
const { BuildTypes } = require('./utils'); const { BuildType } = require('./utils');
module.exports = createManifestTasks; module.exports = createManifestTasks;
@ -114,7 +114,7 @@ async function writeJson(obj, file) {
function getBuildModifications(buildType) { function getBuildModifications(buildType) {
const buildModifications = {}; const buildModifications = {};
if (buildType === BuildTypes.beta) { if (buildType === BuildType.beta) {
Object.assign(buildModifications, betaManifestModifications); Object.assign(buildModifications, betaManifestModifications);
} }
return buildModifications; return buildModifications;

@ -6,7 +6,7 @@ const glob = require('fast-glob');
const locales = require('../../app/_locales/index.json'); const locales = require('../../app/_locales/index.json');
const { createTask, composeSeries } = require('./task'); const { createTask, composeSeries } = require('./task');
const { BuildTypes } = require('./utils'); const { BuildType } = require('./utils');
const EMPTY_JS_FILE = './development/empty.js'; const EMPTY_JS_FILE = './development/empty.js';
@ -21,7 +21,7 @@ module.exports = function createStaticAssetTasks({
); );
const additionalBuildTargets = { const additionalBuildTargets = {
[BuildTypes.beta]: [ [BuildType.beta]: [
{ {
src: './app/build-types/beta/', src: './app/build-types/beta/',
dest: `images`, dest: `images`,

@ -1,6 +1,6 @@
const path = require('path'); const path = require('path');
const { PassThrough, Transform } = require('stream'); const { PassThrough, Transform } = require('stream');
const { BuildTypes } = require('../utils'); const { BuildType } = require('../utils');
const { lintTransformedFile } = require('./utils'); const { lintTransformedFile } = require('./utils');
const hasOwnProperty = (obj, key) => Reflect.hasOwnProperty.call(obj, key); const hasOwnProperty = (obj, key) => Reflect.hasOwnProperty.call(obj, key);
@ -86,7 +86,7 @@ function createRemoveFencedCodeTransform(
buildType, buildType,
shouldLintTransformedFiles = true, shouldLintTransformedFiles = true,
) { ) {
if (!hasOwnProperty(BuildTypes, buildType)) { if (!hasOwnProperty(BuildType, buildType)) {
throw new Error( throw new Error(
`Code fencing transform received unrecognized build type "${buildType}".`, `Code fencing transform received unrecognized build type "${buildType}".`,
); );
@ -136,7 +136,7 @@ const CommandValidators = {
} }
params.forEach((param) => { params.forEach((param) => {
if (!hasOwnProperty(BuildTypes, param)) { if (!hasOwnProperty(BuildType, param)) {
throw new Error( throw new Error(
getInvalidParamsMessage( getInvalidParamsMessage(
filePath, filePath,

@ -1,5 +1,5 @@
const deepFreeze = require('deep-freeze-strict'); const deepFreeze = require('deep-freeze-strict');
const { BuildTypes } = require('../utils'); const { BuildType } = require('../utils');
const { const {
createRemoveFencedCodeTransform, createRemoveFencedCodeTransform,
removeFencedCode, removeFencedCode,
@ -191,7 +191,7 @@ describe('build/transforms/remove-fenced-code', () => {
const mockFileName = 'file.js'; const mockFileName = 'file.js';
// Valid inputs // Valid inputs
Object.keys(BuildTypes).forEach((buildType) => { Object.keys(BuildType).forEach((buildType) => {
it(`transforms file with fences for build type "${buildType}"`, () => { it(`transforms file with fences for build type "${buildType}"`, () => {
expect( expect(
removeFencedCode( removeFencedCode(
@ -224,7 +224,7 @@ describe('build/transforms/remove-fenced-code', () => {
expect( expect(
removeFencedCode( removeFencedCode(
mockFileName, mockFileName,
BuildTypes.flask, BuildType.flask,
getMinimalFencedCode('main'), getMinimalFencedCode('main'),
), ),
).toStrictEqual(['', true]); ).toStrictEqual(['', true]);
@ -243,7 +243,7 @@ describe('build/transforms/remove-fenced-code', () => {
expect( expect(
removeFencedCode( removeFencedCode(
mockFileName, mockFileName,
BuildTypes.flask, BuildType.flask,
getMinimalFencedCode('main').concat(ignoredLine), getMinimalFencedCode('main').concat(ignoredLine),
), ),
).toStrictEqual([ignoredLine, true]); ).toStrictEqual([ignoredLine, true]);
@ -256,7 +256,7 @@ describe('build/transforms/remove-fenced-code', () => {
expect( expect(
removeFencedCode( removeFencedCode(
mockFileName, mockFileName,
BuildTypes.flask, BuildType.flask,
modifiedInputWithoutFences, modifiedInputWithoutFences,
), ),
).toStrictEqual([modifiedInputWithoutFences, false]); ).toStrictEqual([modifiedInputWithoutFences, false]);
@ -286,7 +286,7 @@ describe('build/transforms/remove-fenced-code', () => {
inputs.forEach((input) => { inputs.forEach((input) => {
expect(() => expect(() =>
removeFencedCode(mockFileName, BuildTypes.flask, input), removeFencedCode(mockFileName, BuildType.flask, input),
).toThrow( ).toThrow(
`Empty fence found in file "${mockFileName}":\n${emptyFence}`, `Empty fence found in file "${mockFileName}":\n${emptyFence}`,
); );
@ -313,7 +313,7 @@ describe('build/transforms/remove-fenced-code', () => {
expect(() => expect(() =>
removeFencedCode( removeFencedCode(
mockFileName, mockFileName,
BuildTypes.flask, BuildType.flask,
getMinimalFencedCode().replace( getMinimalFencedCode().replace(
fenceSentinelAndTerminusRegex, fenceSentinelAndTerminusRegex,
replacement, replacement,
@ -373,7 +373,7 @@ describe('build/transforms/remove-fenced-code', () => {
expect(() => expect(() =>
removeFencedCode( removeFencedCode(
mockFileName, mockFileName,
BuildTypes.flask, BuildType.flask,
getMinimalFencedCode().replace(directiveString, replacement), getMinimalFencedCode().replace(directiveString, replacement),
), ),
).toThrow( ).toThrow(
@ -419,7 +419,7 @@ describe('build/transforms/remove-fenced-code', () => {
expect(() => expect(() =>
removeFencedCode( removeFencedCode(
mockFileName, mockFileName,
BuildTypes.flask, BuildType.flask,
getMinimalFencedCode().replace(directiveString, replacement), getMinimalFencedCode().replace(directiveString, replacement),
), ),
).toThrow( ).toThrow(
@ -440,7 +440,7 @@ describe('build/transforms/remove-fenced-code', () => {
expect(() => expect(() =>
removeFencedCode( removeFencedCode(
mockFileName, mockFileName,
BuildTypes.flask, BuildType.flask,
getMinimalFencedCode().concat(addition), getMinimalFencedCode().concat(addition),
), ),
).toThrow( ).toThrow(
@ -460,7 +460,7 @@ describe('build/transforms/remove-fenced-code', () => {
expect(() => expect(() =>
removeFencedCode( removeFencedCode(
mockFileName, mockFileName,
BuildTypes.flask, BuildType.flask,
getMinimalFencedCode().replace(validTerminus, replacement), getMinimalFencedCode().replace(validTerminus, replacement),
), ),
).toThrow( ).toThrow(
@ -484,7 +484,7 @@ describe('build/transforms/remove-fenced-code', () => {
expect(() => expect(() =>
removeFencedCode( removeFencedCode(
mockFileName, mockFileName,
BuildTypes.flask, BuildType.flask,
getMinimalFencedCode().replace(validCommand, replacement), getMinimalFencedCode().replace(validCommand, replacement),
), ),
).toThrow( ).toThrow(
@ -513,7 +513,7 @@ describe('build/transforms/remove-fenced-code', () => {
expect(() => expect(() =>
removeFencedCode( removeFencedCode(
mockFileName, mockFileName,
BuildTypes.flask, BuildType.flask,
getMinimalFencedCode(replacement), getMinimalFencedCode(replacement),
), ),
).toThrow( ).toThrow(
@ -526,7 +526,7 @@ describe('build/transforms/remove-fenced-code', () => {
expect(() => expect(() =>
removeFencedCode( removeFencedCode(
mockFileName, mockFileName,
BuildTypes.flask, BuildType.flask,
getMinimalFencedCode('').replace('()', ''), getMinimalFencedCode('').replace('()', ''),
), ),
).toThrow(/No params specified.$/u); ).toThrow(/No params specified.$/u);
@ -562,7 +562,7 @@ describe('build/transforms/remove-fenced-code', () => {
expect(() => expect(() =>
removeFencedCode( removeFencedCode(
mockFileName, mockFileName,
BuildTypes.flask, BuildType.flask,
input.replace(target, replacement), input.replace(target, replacement),
), ),
).toThrow(expectedError); ).toThrow(expectedError);

@ -1,7 +1,12 @@
const semver = require('semver'); const semver = require('semver');
const { version } = require('../../package.json'); const { version } = require('../../package.json');
const BuildTypes = { /**
* The distribution this build is intended for.
*
* This should be kept in-sync with the `BuildType` map in `shared/constants/app.js`.
*/
const BuildType = {
beta: 'beta', beta: 'beta',
flask: 'flask', flask: 'flask',
main: 'main', main: 'main',
@ -35,7 +40,7 @@ function getBrowserVersionMap(platforms) {
[buildType, buildVersion] = prerelease; [buildType, buildVersion] = prerelease;
if (!String(buildVersion).match(/^\d+$/u)) { if (!String(buildVersion).match(/^\d+$/u)) {
throw new Error(`Invalid prerelease build version: '${buildVersion}'`); throw new Error(`Invalid prerelease build version: '${buildVersion}'`);
} else if (buildType !== BuildTypes.beta) { } else if (buildType !== BuildType.beta) {
throw new Error(`Invalid prerelease build type: ${buildType}`); throw new Error(`Invalid prerelease build type: ${buildType}`);
} }
} }
@ -58,6 +63,6 @@ function getBrowserVersionMap(platforms) {
} }
module.exports = { module.exports = {
BuildTypes, BuildType,
getBrowserVersionMap, getBrowserVersionMap,
}; };

@ -11,6 +11,17 @@ export const ENVIRONMENT_TYPE_NOTIFICATION = 'notification';
export const ENVIRONMENT_TYPE_FULLSCREEN = 'fullscreen'; export const ENVIRONMENT_TYPE_FULLSCREEN = 'fullscreen';
export const ENVIRONMENT_TYPE_BACKGROUND = 'background'; export const ENVIRONMENT_TYPE_BACKGROUND = 'background';
/**
* The distribution this build is intended for.
*
* This should be kept in-sync with the `BuildType` map in `development/build/utils.js`.
*/
export const BuildType = {
beta: 'beta',
flask: 'flask',
main: 'main',
};
export const PLATFORM_BRAVE = 'Brave'; export const PLATFORM_BRAVE = 'Brave';
export const PLATFORM_CHROME = 'Chrome'; export const PLATFORM_CHROME = 'Chrome';
export const PLATFORM_EDGE = 'Edge'; export const PLATFORM_EDGE = 'Edge';

Loading…
Cancel
Save