Skip to content

Commit 80c4ceb

Browse files
committed
chore(5956): add documentation to sentry usage
1 parent 27aa96d commit 80c4ceb

File tree

2 files changed

+86
-12
lines changed

2 files changed

+86
-12
lines changed

.metamaskrc.dist

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,9 @@ BLOCKAID_PUBLIC_KEY=
5353
; Enables the Settings Page - Developer Options
5454
; ENABLE_SETTINGS_PAGE_DEV_OPTIONS=true
5555

56-
; The endpoint used to submit errors and tracing data to Sentry.
57-
; The below is the `test-metamask` project.
56+
; SENTRY CONFIGURATION
57+
; SENTRY_DSN - For production builds only (do NOT use in development)
58+
; SENTRY_DSN_DEV - For local dev, CI/CD, and testing (sends to 'test-metamask' project)
5859
; SENTRY_DSN_DEV=https://[email protected]/273496
5960

6061
; Enable/disable why did you render debug tool: https://github.com/welldone-software/why-did-you-render

development/README.md

Lines changed: 83 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -58,23 +58,96 @@ or `https://api.segment.io/v1/batch` respectively.
5858

5959
## Sentry
6060

61-
### Debugging Sentry
61+
### Overview
6262

63-
1. Set `SENTRY_DSN_DEV`, or `SENTRY_DSN` if using a production build, in `.metamaskrc` to a suitable Sentry URL.
63+
MetaMask uses Sentry for error tracking and performance monitoring. Events are
64+
automatically categorized by environment based on build target and GitHub context.
6465

65-
- The example value specified in `.metamaskrc.dist` uses the `test-metamask` project in the MetaMask account.
66-
- Alternatively, create a free Sentry account with a new organization and project.
67-
- The DSN is specified in: `Settings > Projects > [Project Name] > Client Keys (DSN)`.
66+
### Sentry Projects
6867

69-
2. To display Sentry logs, include `DEBUG=metamask:sentry:*` in `.metamaskrc`.
68+
| Project | Purpose | DSN Variable |
69+
|---------|---------|--------------|
70+
| **test-metamask** | Non-production events (dev, staging, CI/CD, testing) | `SENTRY_DSN_DEV` |
71+
| **metamask-extension** | Production events only | `SENTRY_DSN` |
7072

71-
3. To display more verbose logs if not in a developer build, include `METAMASK_DEBUG=1` in `.metamaskrc`.
73+
> ⚠️ **Important**: Never use `SENTRY_DSN` (production) for local development or CI/CD builds.
74+
> Always use `SENTRY_DSN_DEV` for non-production environments.
7275
73-
4. Ensure metrics are enabled during onboarding or via `Settings > Security & privacy > Participate in MetaMetrics`.
76+
### Environments
7477

75-
5. To test Sentry via the developer options in the UI, include `ENABLE_SETTINGS_PAGE_DEV_OPTIONS=true` in `.metamaskrc`.
78+
| Environment | When Used | Build Command | Branch/Context |
79+
|-------------|-----------|---------------|----------------|
80+
| `production` | Production releases | `yarn build prod` | Any |
81+
| `staging` | Main branch builds | `yarn build dist` | `main` branch |
82+
| `development` | PR builds, feature branches | `yarn build dist` | PR or feature branch |
83+
| `testing` | E2E test builds | `yarn build:test` | Any |
84+
| `pull-request` | PR builds (non-dist) | Various | `pull_request` event |
85+
| `release-candidate` | Release branches | `yarn build dist` | `release/*` branches |
86+
| `other` | Fallback (should not happen) | - | Uncategorized |
7687

77-
6. Alternatively, call `window.stateHooks.throwTestError()` or `window.stateHooks.throwTestBackgroundError()` via the UI console.
88+
For non-main build types (beta, flask, experimental), the environment includes the build type suffix:
89+
- `staging-beta`, `staging-flask`, `staging-experimental`
90+
- `development-beta`, `development-flask`, etc.
91+
- `testing-flask`, etc.
92+
93+
### Environment Determination Logic
94+
95+
Environments are determined by `development/build/utils.js:getEnvironment()`:
96+
97+
1. **Build target** (highest priority):
98+
- `prod``production`
99+
- `dev` or `testDev``development`
100+
- `test``testing`
101+
102+
2. **Branch name** (for `dist` builds):
103+
- `release/*``release-candidate`
104+
- `main``staging`
105+
106+
3. **GitHub event** (fallback):
107+
- `pull_request``pull-request`
108+
109+
4. **Default**: `other` (indicates misconfiguration)
110+
111+
### DSN Selection Logic
112+
113+
The Sentry target DSN is determined by `app/scripts/lib/setupSentry.js:getSentryTarget()`:
114+
115+
```
116+
if (IN_TEST && !SENTRY_DSN_DEV) → SENTRY_DSN_FAKE (no events sent)
117+
if (METAMASK_ENVIRONMENT !== 'production') → SENTRY_DSN_DEV (test-metamask)
118+
if (METAMASK_ENVIRONMENT === 'production') → SENTRY_DSN (production project)
119+
```
120+
121+
### Querying Sentry
122+
123+
Common Sentry search queries:
124+
125+
| What you want | Sentry Query |
126+
|---------------|--------------|
127+
| All PR errors | `environment:development OR environment:pull-request` |
128+
| Staging errors | `environment:staging OR environment:staging-*` |
129+
| Test failures | `environment:testing OR environment:testing-*` |
130+
| Production only | `environment:production` |
131+
| Flask builds | `environment:*-flask` |
132+
| Beta builds | `environment:*-beta` |
133+
134+
### Local Development Setup
135+
136+
To enable Sentry error reporting for local development:
137+
138+
1. Copy the example config and set the DSN:
139+
```bash
140+
cp .metamaskrc.dist .metamaskrc
141+
# Uncomment SENTRY_DSN_DEV in .metamaskrc
142+
```
143+
144+
2. Enable Sentry debug logs (optional): add `DEBUG=metamask:sentry:*` to `.metamaskrc`
145+
146+
3. Enable MetaMetrics via `Settings > Security & privacy > Participate in MetaMetrics`
147+
148+
4. To test Sentry errors:
149+
- Add `ENABLE_SETTINGS_PAGE_DEV_OPTIONS=true` to `.metamaskrc` and use Developer Options in Settings
150+
- Or call `window.stateHooks.throwTestError()` in the browser console
78151

79152
### Debugging the Publish Release Flow
80153

0 commit comments

Comments
 (0)