Skip to content

Commit

Permalink
fix: Fix MV2 build sourcemap upload
Browse files Browse the repository at this point in the history
The sourcemaps for MV2 builds (used for Firefox) were not being
uploaded to Sentry at all. This resulted in invalid stack traces for
Firefox error reports.

The Sentry initiatization has been updated to use a `dist` option,
letting us differentiate between different types of build for the same
version. This is now used to signify which builds are mv2 and which are
mv3. Both distributions are uploaded separately as part of the release
process (for Flask and main builds; we don't have MV2 builds for MMI or
beta).

Fixes #26466
  • Loading branch information
Gudahtt committed Aug 21, 2024
1 parent 590f0a9 commit 8f6f13d
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 25 deletions.
6 changes: 6 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1564,9 +1564,15 @@ jobs:
- run:
name: Publish main release to Sentry
command: yarn sentry:publish
- run:
name: Publish main MV2 release to Sentry
command: yarn sentry:publish --dist mv2
- run:
name: Publish Flask release to Sentry
command: yarn sentry:publish --build-type flask
- run:
name: Publish Flask MV2 release to Sentry
command: yarn sentry:publish --build-type flask --dist mv2
- run:
name: Publish MMI release to Sentry
command: yarn sentry:publish --build-type mmi
Expand Down
2 changes: 2 additions & 0 deletions app/scripts/lib/setupSentry.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as Sentry from '@sentry/browser';
import { createModuleLogger, createProjectLogger } from '@metamask/utils';
import { logger } from '@sentry/utils';
import { AllProperties } from '../../../shared/modules/object.utils';
import { isManifestV3 } from '../../../shared/modules/mv3.utils';
import extractEthjsErrorMessage from './extractEthjsErrorMessage';
import { filterEvents } from './sentry-filter-events';

Expand Down Expand Up @@ -480,6 +481,7 @@ function getClientOptions() {
beforeBreadcrumb: beforeBreadcrumb(),
beforeSend: (report) => rewriteReport(report),
debug: METAMASK_DEBUG,
dist: isManifestV3 ? ' mv3' : 'mv2',
dsn: sentryTarget,
environment,
integrations: [
Expand Down
38 changes: 15 additions & 23 deletions development/sentry-publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,15 @@ async function start() {
default: 0,
description: 'The MetaMask extension build version',
type: 'number',
})
.option('dist', {
description:
'The MetaMask extension build distribution (typically for MV2 builds, omit for MV3)',
type: 'string',
}),
);

const { buildType, buildVersion, org, project } = argv;
const { buildType, buildVersion, dist, org, project } = argv;

process.env.SENTRY_ORG = org;
process.env.SENTRY_PROJECT = project;
Expand Down Expand Up @@ -75,19 +80,17 @@ async function start() {
]);
}

// check if version has artifacts or not
const versionHasArtifacts =
versionAlreadyExists && (await checkIfVersionHasArtifacts(version));
if (versionHasArtifacts) {
console.log(
`Version "${version}" already has artifacts on Sentry, skipping sourcemap upload`,
);
return;
}

const additionalUploadArgs = [];
if (dist) {
additionalUploadArgs.push('--dist', dist);
}
if (buildType !== loadBuildTypesConfig().default) {
additionalUploadArgs.push('--dist-directory', `dist-${buildType}`);
additionalUploadArgs.push(
'--dist-directory',
dist ? `dist-${buildType}-${dist}` : `dist-${buildType}`,
);
} else if (dist) {
additionalUploadArgs.push('--dist-directory', `dist-${dist}`);
}
// upload sentry source and sourcemaps
await runInShell('./development/sentry-upload-artifacts.sh', [
Expand All @@ -109,17 +112,6 @@ async function checkIfVersionExists(version) {
);
}

async function checkIfVersionHasArtifacts(version) {
const [artifact] = await runCommand('sentry-cli', [
'releases',
'files',
version,
'list',
]);
// When there's no artifacts, we get a response from the shell like this ['', '']
return artifact?.length > 0;
}

async function doesNotFail(asyncFn) {
try {
await asyncFn();
Expand Down
17 changes: 15 additions & 2 deletions development/sentry-upload-artifacts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,23 @@ Upload JavaScript bundles and sourcemaps to Sentry
Options:
-h, --help Show help text
-r, --release <release> Sentry release to upload files to (defaults to 'VERSION' environment variable)
-d, --dist <dist> Sentry distribution (typically used to identify MV2 builds)
--dist-directory <path> The 'dist' directory to use. Defaults to 'dist'.
EOF
}

function upload_sourcemaps {
local release="${1}"; shift
local dist="${1}"; shift
local dist_directory="${1}"; shift

sentry-cli releases files "${release}" upload-sourcemaps "${dist_directory}"/chrome/ "${dist_directory}"/sourcemaps/ --rewrite --url-prefix '/metamask'
sentry-cli releases files "${release}" upload-sourcemaps --dist "${dist}" "${dist_directory}"/chrome/ "${dist_directory}"/sourcemaps/ --rewrite --url-prefix '/metamask'
}

function main {
local release=VERSION
local dist_directory='dist'
local dist="mv3"

while :; do
case "${1-default}" in
Expand All @@ -54,6 +57,16 @@ function main {
release="${2}"
shift
;;
-d|--dist)
if [[ -z $2 ]]
then
printf "'dist' option requires an argument.\\n" >&2
printf '%s\n' "${__SEE_HELP_MESSAGE__}" >&2
exit 1
fi
dist="${2}"
shift
;;
--dist-directory)
if [[ -z $2 ]]
then
Expand Down Expand Up @@ -83,7 +96,7 @@ function main {
fi

printf 'uploading source files and sourcemaps for Sentry release "%s"...\n' "${release}"
upload_sourcemaps "${release}" "${dist_directory}"
upload_sourcemaps "${release}" "${dist_directory}" "${dist}"
printf 'all done!\n'
}

Expand Down

0 comments on commit 8f6f13d

Please sign in to comment.