Several files which are needed for developing on MetaMask.
Usually each file or directory contains information about its scope / usage.
To start the Mock Segment API:
- Add/replace the
SEGMENT_HOSTandSEGMENT_WRITE_KEYvariables in.metamaskrcSEGMENT_HOST='http://localhost:9090' SEGMENT_WRITE_KEY='FAKE' - Build the project to the
./dist/folder withyarn dist - Run the Mock Segment API from the command line
node development/mock-segment.js
Events triggered whilst using the extension will be logged to the console of the Mock Segment API.
More information on the API and its usage can be found here.
To debug in a production Segment environment:
- Create a free account on Segment
- Create a New Workspace
- Add a Source (Node.js)
- Copy the
Write Keyfrom the API Keys section under Settings - Add/replace the
SEGMENT_HOSTandSEGMENT_WRITE_KEYvariables in.metamaskrcSEGMENT_HOST='https://api.segment.io' SEGMENT_WRITE_KEY='COPIED_WRITE_KEY' - Build the project to the
./dist/folder withyarn dist
Events triggered whilst using the extension will be displayed in Segment's Debugger.
To opt in to MetaMetrics;
- Unlock the extension
- Open the Account menu
- Click the
Settingsmenu item - Click the
Security & Privacymenu item - Toggle the
Participate in MetaMetricsmenu option to theONposition
You can inspect the requests in the Network tab of your browser's Developer Tools (background.html)
by filtering for POST requests to /v1/batch. The full url will be http://localhost:9090/v1/batch
or https://api.segment.io/v1/batch respectively.
MetaMask uses Sentry for error tracking and performance monitoring. Events are automatically categorized by environment based on build target and GitHub context.
| Project | Purpose | DSN Variable |
|---|---|---|
| test-metamask | Local dev and one-off QA testing | SENTRY_DSN_DEV |
| metamask-performance | CI/CD and automated performance testing | SENTRY_DSN_PERFORMANCE |
| metamask-extension | Production events only | SENTRY_DSN |
⚠️ Important: Never useSENTRY_DSN(production) for local development or CI/CD builds. UseSENTRY_DSN_DEVfor local development and manual QA testing. UseSENTRY_DSN_PERFORMANCEfor CI/CD pipelines to send performance metrics to Sentry.
| Environment | When Used | Build Command | Webpack Command | Branch/Context |
|---|---|---|---|---|
production |
Production releases | yarn build prod |
yarn webpack --mode production --env production |
release/* branches |
staging |
Main branch builds | yarn build dist |
yarn webpack --mode production |
main branch |
development |
Local development | yarn start |
yarn webpack --mode development --watch |
Local |
testing |
E2E test builds | yarn build:test |
yarn webpack --mode production --test |
Any |
pull-request |
PR builds | yarn build dist |
yarn webpack --mode production |
pull_request event |
release-candidate |
Release branches | yarn build dist |
yarn webpack --mode production |
release/* branches |
other |
Local dist builds | yarn build dist |
yarn webpack --mode production |
Local builds |
For non-main build types (beta, flask, experimental), the environment includes the build type suffix:
staging-beta,staging-flask,staging-experimentaldevelopment-beta,development-flask, etc.testing-flask, etc.
Environments are determined by development/build/utils.js:getEnvironment():
-
Build target (highest priority):
prod→productiondevortestDev→developmenttest→testing
-
Branch name (for
distbuilds):release/*→release-candidatemain→staging
-
GitHub event (fallback):
pull_request→pull-request
-
Default:
other(local dist builds)
The Sentry target DSN is determined by app/scripts/lib/setupSentry.js:getSentryTarget():
if (IN_TEST && !SENTRY_DSN_DEV) → SENTRY_DSN_FAKE (no events sent)
if (METAMASK_ENVIRONMENT !== 'production') → SENTRY_DSN_DEV (test-metamask)
if (METAMASK_ENVIRONMENT === 'production') → SENTRY_DSN (production project)
Note:
SENTRY_DSN_PERFORMANCEis used by CI/CD pipelines to send performance metrics and benchmark data to Sentry. It is configured in GitHub Actions secrets.
Common Sentry search queries:
| What you want | Sentry Query |
|---|---|
| Development errors | environment:development OR environment:pull-request |
| Staging errors | environment:staging OR environment:staging-* |
| Test failures | environment:testing OR environment:testing-* |
| Production only | environment:production |
| Flask builds | environment:*-flask |
| Beta builds | environment:*-beta |
To enable Sentry error reporting for local development:
-
Copy the example config and set the DSN:
cp .metamaskrc.dist .metamaskrc # Uncomment SENTRY_DSN_DEV in .metamaskrc -
Enable Sentry debug logs (optional): add
DEBUG=metamask:sentry:*to.metamaskrc -
Enable MetaMetrics via
Settings > Security & privacy > Participate in MetaMetrics -
To test Sentry errors:
- Add
ENABLE_SETTINGS_PAGE_DEV_OPTIONS=trueto.metamaskrcand use Developer Options in Settings - Or call
window.stateHooks.throwTestError()in the browser console
- Add
- Go to Sentry and Create an Organization, by clicking
Account Menu > Switch organization > Create a new organization - Create a Javascript Project, by clicking
Projects > Create Project > Javascript - Create a User Auth Token, by clicking
Account Menu > User auth tokens - Select your newly created project and grant all permissions to your token
- Copy your token to your clipboard
- Go to your terminal, inside the
metamask-extensionproject - Login to Sentry using the command line
yarn sentry-cli login --auth-token YOUR_TOKEN - List your organizations and copy the id for the organization you want to see
yarn sentry-cli organizations list - List your organization projects and copy the id for the you created
yarn sentry-cli projects list --org YOUR_ORG_ID
- Build your desired MetaMask project. Examples:
yarn distto create an MV3 buildyarn dist:mv2to create an MV2 build- (and so on)
- Move the build to its corresponding folder. Ie:
mv dist dist-mv2(skip this step, if you did the regular MV3 build) - Publish the release to Sentry:
- If it's an MV3 build
yarn sentry:publish --org YOUR_ORG_ID --project YOUR_PROJECT_ID - If it's an MV2 build
yarn sentry:publish --dist mv2 --org YOUR_ORG_ID --project YOUR_PROJECT_ID
- If it's an MV3 build
- See build files and source maps are uploaded
- Go to Sentry
- Check the Source Maps have been uploaded correctly in Sentry: go to
Settings > Projects > Project Name > Source Maps
Extra Note: if you already uploaded one version, you can change the package.json version and run again the publish step, to test the complete flow.
To unbundle the extensions compiled and minified JavaScript using Source Maps:
- Open Chrome DevTools to inspect the
background.htmlorhome.htmlview - Click on the
Sourcestab in Chrome DevTools - In the Sources tab, click on the
Pagepanel - Expand the file directory in the Page panel until you see the source files you're after
- Select a source file in the Page panel
chrome-extension://{EXTENSION_ID}/common-0.js
- Double click the source file to open it in the Workspace
- Right click in the body of the source file and select
Add source map... - Enter the path to the corresponding source map file, and Click
Add
file:///{LOCAL_FILE_SYSTEM}/metamask-extension/dist/sourcemaps/common-0.js.map
- Repeat the steps above as necessary adding all the relevant source map files
- Your source maps should now be added to the DevTools Console, and you should be able to see your original source files when you debug your code


