Skip to content

Commit 4563265

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

File tree

2 files changed

+88
-12
lines changed

2 files changed

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

79154
### Debugging the Publish Release Flow
80155

0 commit comments

Comments
 (0)