|
| 1 | +--- |
| 2 | +name: setup-dev |
| 3 | +description: Set up and manage the Sentry development environment using devenv. Handles fresh setup, updating existing environments, starting dev services, and troubleshooting. Use when asked to "set up sentry", "setup dev environment", "get sentry running", "start dev server", "devenv setup", "devservices not working", "sentry won't start", or any development environment issue. |
| 4 | +--- |
| 5 | + |
| 6 | +# Set Up Sentry Development Environment |
| 7 | + |
| 8 | +Walk the user through getting Sentry running locally. The full process from a bare machine takes **30-45 minutes** — most of that is downloading dependencies and Docker images. Set expectations clearly at each step. |
| 9 | + |
| 10 | +**AL MCP**: If the `al` MCP server is available, use `al_search_docs` and `al_read_doc` for detailed troubleshooting. The AL docs cover devenv, devservices, and common issues in depth. The AL server is part of the [devinfra-mcp](https://github.com/getsentry/devinfra-mcp) project — see that repo for setup instructions if the server isn't configured yet. The SSE endpoint is configured in `.pi/mcp.json` (pi) or `.mcp.json` / `.cursor/mcp.json` (Claude Code / Cursor). |
| 11 | + |
| 12 | +## Step 1: Detect Current State |
| 13 | + |
| 14 | +Before doing anything, assess what's already installed. Run all of these: |
| 15 | + |
| 16 | +```bash |
| 17 | +# Check OS |
| 18 | +uname -s && uname -m |
| 19 | + |
| 20 | +# Check shell |
| 21 | +echo $SHELL |
| 22 | + |
| 23 | +# Check if devenv exists |
| 24 | +which devenv 2>/dev/null || ls ~/.local/share/sentry-devenv/bin/devenv 2>/dev/null |
| 25 | + |
| 26 | +# Check devenv version (outdated versions cause failures) |
| 27 | +devenv --version 2>/dev/null || ~/.local/share/sentry-devenv/bin/devenv --version 2>/dev/null |
| 28 | + |
| 29 | +# Check Docker runtime |
| 30 | +docker context ls 2>/dev/null |
| 31 | +docker info --format '{{.Name}}' 2>/dev/null |
| 32 | + |
| 33 | +# Check OrbStack |
| 34 | +which orbctl 2>/dev/null && orbctl status 2>/dev/null |
| 35 | + |
| 36 | +# Check Colima |
| 37 | +which colima 2>/dev/null && colima status 2>/dev/null |
| 38 | + |
| 39 | +# Check direnv |
| 40 | +which direnv 2>/dev/null |
| 41 | + |
| 42 | +# Check if repo is already set up |
| 43 | +ls .venv/bin/sentry 2>/dev/null && ls node_modules/.bin 2>/dev/null |
| 44 | +``` |
| 45 | + |
| 46 | +Based on results, skip to the appropriate step. If everything is installed, jump to Step 6. |
| 47 | + |
| 48 | +## Step 2: Install Prerequisites (macOS) |
| 49 | + |
| 50 | +### Xcode Command Line Tools |
| 51 | + |
| 52 | +```bash |
| 53 | +xcode-select -p 2>/dev/null || xcode-select --install |
| 54 | +``` |
| 55 | + |
| 56 | +If not installed, the user must complete the interactive install dialog (~10 min). Wait for it. |
| 57 | + |
| 58 | +### Homebrew |
| 59 | + |
| 60 | +```bash |
| 61 | +which brew || /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" |
| 62 | +``` |
| 63 | + |
| 64 | +### Docker Runtime — OrbStack or Colima |
| 65 | + |
| 66 | +Ask the user which they prefer. Explain the tradeoffs: |
| 67 | + |
| 68 | +| Runtime | Pros | Cons | |
| 69 | +| ------------ | ------------------------------------------------------ | -------------------------------------------------------- | |
| 70 | +| **Colima** | Official Sentry recommendation, all scripts support it | Can have DNS issues on WiFi changes | |
| 71 | +| **OrbStack** | Faster, lower resource usage, better UI | Some Sentry scripts assume Colima — may need workarounds | |
| 72 | + |
| 73 | +**If choosing OrbStack:** |
| 74 | + |
| 75 | +```bash |
| 76 | +brew install --cask orbstack |
| 77 | +``` |
| 78 | + |
| 79 | +Then start OrbStack from Applications. Verify: `docker info` |
| 80 | + |
| 81 | +**If choosing Colima:** |
| 82 | +Colima gets installed by `devenv bootstrap` — no separate step needed. |
| 83 | + |
| 84 | +**Important**: Do NOT run Docker Desktop alongside either runtime — it causes conflicts. |
| 85 | + |
| 86 | +## Step 3: Install devenv |
| 87 | + |
| 88 | +```bash |
| 89 | +# For external (non-Sentry-employee) contributors: |
| 90 | +# export SENTRY_EXTERNAL_CONTRIBUTOR=1 |
| 91 | + |
| 92 | +curl -fsSL https://raw.githubusercontent.com/getsentry/devenv/main/install-devenv.sh | bash |
| 93 | +``` |
| 94 | + |
| 95 | +This installs to `~/.local/share/sentry-devenv/bin/devenv`. |
| 96 | + |
| 97 | +### Shell Configuration |
| 98 | + |
| 99 | +The user's shell MUST have devenv on PATH and direnv hooked in. Check and fix: |
| 100 | + |
| 101 | +```bash |
| 102 | +# Check if already configured |
| 103 | +grep -q "sentry-devenv" ~/.zshrc 2>/dev/null || grep -q "sentry-devenv" ~/.bashrc 2>/dev/null |
| 104 | +``` |
| 105 | + |
| 106 | +If not configured, add to the appropriate shell config (`~/.zshrc` for zsh, `~/.bashrc` for bash): |
| 107 | + |
| 108 | +```bash |
| 109 | +# devenv |
| 110 | +export PATH="$HOME/.local/share/sentry-devenv/bin:$PATH" |
| 111 | + |
| 112 | +# direnv |
| 113 | +eval "$(direnv hook zsh)" # or: eval "$(direnv hook bash)" |
| 114 | +``` |
| 115 | + |
| 116 | +**Tell the user to restart their terminal** (or `source ~/.zshrc`) after this change. |
| 117 | + |
| 118 | +### Verify devenv Version |
| 119 | + |
| 120 | +Minimum version changes frequently. If devenv is already installed, check it's not outdated: |
| 121 | + |
| 122 | +```bash |
| 123 | +devenv --version |
| 124 | +``` |
| 125 | + |
| 126 | +If the version is old (e.g., < 1.22), upgrade: |
| 127 | + |
| 128 | +```bash |
| 129 | +devenv update |
| 130 | +``` |
| 131 | + |
| 132 | +If `devenv update` itself fails because the version is too old, reinstall: |
| 133 | + |
| 134 | +```bash |
| 135 | +curl -fsSL https://raw.githubusercontent.com/getsentry/devenv/main/install-devenv.sh | bash |
| 136 | +``` |
| 137 | + |
| 138 | +## Step 4: Bootstrap (First Time Only) |
| 139 | + |
| 140 | +For a completely fresh setup, run bootstrap first: |
| 141 | + |
| 142 | +```bash |
| 143 | +devenv bootstrap |
| 144 | +``` |
| 145 | + |
| 146 | +This is interactive (~5 min) — it prompts for SSH keys, coderoot directory, etc. It installs Homebrew, Colima, Docker CLI, and direnv. |
| 147 | + |
| 148 | +**After bootstrap completes, close and reopen the terminal.** |
| 149 | + |
| 150 | +## Step 5: Sync the Environment |
| 151 | + |
| 152 | +This is the longest step. Tell the user: |
| 153 | + |
| 154 | +> **This will take 10-20 minutes** on first run. It installs Python, Node, all pip/npm dependencies, and runs database migrations. Subsequent syncs are much faster (2-5 min). |
| 155 | +
|
| 156 | +### If direnv hangs |
| 157 | + |
| 158 | +The `.envrc` runs Docker checks. If the Docker runtime isn't running, direnv will hang. Symptoms: |
| 159 | + |
| 160 | +``` |
| 161 | +direnv: ([...]/direnv export zsh) is taking a while to execute. Use CTRL-C to give up. |
| 162 | +``` |
| 163 | + |
| 164 | +**Fix**: Start the Docker runtime first: |
| 165 | + |
| 166 | +- OrbStack: Open OrbStack.app or `open -a OrbStack` |
| 167 | +- Colima: `devenv colima start` |
| 168 | + |
| 169 | +Then `direnv allow` again. |
| 170 | + |
| 171 | +### Chicken-and-Egg Problem |
| 172 | + |
| 173 | +direnv checks node version and sentry installation. On a fresh setup, these don't exist yet, so direnv will fail. This is normal. **Bypass direnv and run devenv sync directly:** |
| 174 | + |
| 175 | +```bash |
| 176 | +~/.local/share/sentry-devenv/bin/devenv sync |
| 177 | +``` |
| 178 | + |
| 179 | +Or if devenv is on PATH: |
| 180 | + |
| 181 | +```bash |
| 182 | +devenv sync |
| 183 | +``` |
| 184 | + |
| 185 | +After sync completes, `direnv allow` should succeed. |
| 186 | + |
| 187 | +### If devenv sync fails |
| 188 | + |
| 189 | +Common causes: |
| 190 | + |
| 191 | +1. **Outdated devenv** — `devenv update` or reinstall |
| 192 | +2. **Docker not running** — start OrbStack/Colima first |
| 193 | +3. **Network issues** — retry; some downloads are large |
| 194 | + |
| 195 | +Run `devenv doctor` for automated diagnosis. |
| 196 | + |
| 197 | +## Step 6: Start Services |
| 198 | + |
| 199 | +### First: Start Docker Images |
| 200 | + |
| 201 | +```bash |
| 202 | +devservices up |
| 203 | +``` |
| 204 | + |
| 205 | +**⏱️ First run: 5-10 minutes.** It pulls many Docker images (PostgreSQL, Redis, Kafka, ClickHouse, Snuba, Relay, etc.). This is a one-time cost. Tell the user: |
| 206 | + |
| 207 | +> This is downloading all the Docker images Sentry needs. It looks like a lot — that's normal. Subsequent starts take ~30 seconds. |
| 208 | +
|
| 209 | +**Subsequent runs: ~30 seconds.** |
| 210 | + |
| 211 | +### OrbStack Socket Issue |
| 212 | + |
| 213 | +If `devservices up` or `devservices serve` fails with: |
| 214 | + |
| 215 | +``` |
| 216 | +Make sure colima is running. Run `devenv colima start`. |
| 217 | +``` |
| 218 | + |
| 219 | +...but the user is using OrbStack, the `devservices.py` command is checking for the Colima socket only. Check `src/sentry/runner/commands/devservices.py`: |
| 220 | + |
| 221 | +```bash |
| 222 | +grep -n "colima\|docker.sock\|orbstack" src/sentry/runner/commands/devservices.py |
| 223 | +``` |
| 224 | + |
| 225 | +The `_find_docker_socket()` function needs to check multiple socket paths. On macOS it should try, in order: |
| 226 | + |
| 227 | +1. `~/.colima/default/docker.sock` (Colima) |
| 228 | +2. `~/.orbstack/run/docker.sock` (OrbStack) |
| 229 | +3. `/var/run/docker.sock` (Docker Desktop / default) |
| 230 | + |
| 231 | +If only Colima is checked, patch it to support all runtimes. Read `${CLAUDE_SKILL_ROOT}/references/orbstack-fix.md` for the exact pattern. |
| 232 | + |
| 233 | +### Then: Seed the Database |
| 234 | + |
| 235 | +If this is a first-time setup, the database needs seeding: |
| 236 | + |
| 237 | +```bash |
| 238 | +.venv/bin/sentry upgrade --noinput |
| 239 | +``` |
| 240 | + |
| 241 | +This runs all Django migrations AND creates default data (organizations, roles, projects). Without this, the dev server will 500 on every page. |
| 242 | + |
| 243 | +**Do NOT just run `sentry django migrate`** — that only runs migrations without seeding the required default data. |
| 244 | + |
| 245 | +### Create Superuser |
| 246 | + |
| 247 | +```bash |
| 248 | +.venv/bin/sentry createuser --superuser --email admin@sentry.io --password admin --no-input |
| 249 | +``` |
| 250 | + |
| 251 | +## Step 7: Start the Dev Server |
| 252 | + |
| 253 | +```bash |
| 254 | +devservices serve |
| 255 | +``` |
| 256 | + |
| 257 | +Or directly: |
| 258 | + |
| 259 | +```bash |
| 260 | +.venv/bin/sentry devserver |
| 261 | +``` |
| 262 | + |
| 263 | +### What to Expect on Startup |
| 264 | + |
| 265 | +**Kafka topic warnings are normal.** On first start, you'll see many lines like: |
| 266 | + |
| 267 | +``` |
| 268 | +[WARNING] sentry.batching-kafka-consumer: Topic 'taskworker' or its partitions are not ready, retrying... |
| 269 | +``` |
| 270 | + |
| 271 | +These settle down after 30-60 seconds as Kafka auto-creates topics. Don't panic. |
| 272 | + |
| 273 | +### Access the Dev Server |
| 274 | + |
| 275 | +- **URL**: http://dev.sentry.localhost:8000 |
| 276 | +- **Login**: admin@sentry.io / admin |
| 277 | + |
| 278 | +### Required: Sentry Cookie Sync Extension |
| 279 | + |
| 280 | +**Without this extension, the UI shows a blank white screen.** Install it: |
| 281 | + |
| 282 | +https://chromewebstore.google.com/detail/sentry-cookie-sync/kchlmkcdfohlmobgojmipoppgpedhijh |
| 283 | + |
| 284 | +This syncs auth cookies between sentry.io and dev.sentry.localhost. It's not optional. |
| 285 | + |
| 286 | +## Day-to-Day Commands |
| 287 | + |
| 288 | +After initial setup, the daily workflow is: |
| 289 | + |
| 290 | +```bash |
| 291 | +cd ~/Projects/sentry # (or wherever the repo lives) |
| 292 | +devservices up # start background services (~30s) |
| 293 | +devservices serve # start dev server |
| 294 | +# → http://dev.sentry.localhost:8000 |
| 295 | +``` |
| 296 | + |
| 297 | +After pulling new code: |
| 298 | + |
| 299 | +```bash |
| 300 | +devenv sync # update dependencies + migrations (2-5 min) |
| 301 | +``` |
| 302 | + |
| 303 | +## Troubleshooting Decision Tree |
| 304 | + |
| 305 | +| Symptom | Likely Cause | Fix | |
| 306 | +| ----------------------------------------------- | ----------------------------------------- | ---------------------------------------------------- | |
| 307 | +| direnv hangs | Docker runtime not running | Start OrbStack / Colima | |
| 308 | +| `devenv sync` fails with version error | Outdated devenv | `devenv update` or reinstall | |
| 309 | +| `devservices up` says "colima not running" | Using OrbStack, script only checks Colima | Patch `devservices.py` — see Step 6 | |
| 310 | +| Server 500s on every page | DB not seeded | `.venv/bin/sentry upgrade --noinput` | |
| 311 | +| `relation "sentry_organization" does not exist` | Migrations not run | `.venv/bin/sentry upgrade --noinput` | |
| 312 | +| White/blank screen in browser | Cookie Sync extension missing | Install the Chrome extension | |
| 313 | +| Kafka topic warnings on startup | Normal first-boot behavior | Wait 30-60 seconds | |
| 314 | +| Port already in use | Stale containers | `docker rm -f $(docker ps -aq)` then retry | |
| 315 | +| Everything is broken | Nuclear option | `devservices purge && devenv sync && devservices up` | |
| 316 | +| DNS failures in Docker | Colima DNS stale | `devenv doctor` or `devenv colima restart` | |
| 317 | + |
| 318 | +For deeper troubleshooting, use the AL MCP if available ([devinfra-mcp](https://github.com/getsentry/devinfra-mcp)): |
| 319 | + |
| 320 | +``` |
| 321 | +al_search_docs(query="<symptom keywords>") |
| 322 | +al_read_doc(path="devenv/troubleshooting.md", query="<specific issue>") |
| 323 | +``` |
0 commit comments