IMPORTANT: AGENTS.md files are the source of truth for AI agent instructions. Always update the relevant AGENTS.md file when adding or modifying agent guidance. Do not add to CLAUDE.md or Cursor rules.
Sentry is a developer-first error tracking and performance monitoring platform. This repository contains the main Sentry application, which is a large-scale Django application with a React frontend.
sentry/
├── src/
│ ├── sentry/ # Main Django application
│ │ ├── api/ # REST API endpoints
│ │ ├── models/ # Django models
│ │ ├── tasks/ # Celery tasks
│ │ ├── integrations/ # Third-party integrations
│ │ ├── issues/ # Issue tracking logic
│ │ └── web/ # Web views and middleware
│ ├── sentry_plugins/ # Plugin system
│ └── social_auth/ # Social authentication
├── static/ # Frontend application
├── tests/ # Backend test suite
├── fixtures/ # Test fixtures
├── devenv/ # Development environment config
├── migrations/ # Database migrations
└── config/ # Configuration files
This section contains critical command execution instructions that apply across all Sentry development.
CRITICAL: When running Python commands (pytest, mypy, pre-commit, etc.), you MUST use the virtual environment.
Use the full relative path to virtualenv executables:
cd /path/to/sentry && .venv/bin/pytest tests/...
cd /path/to/sentry && .venv/bin/python -m mypy ...Or source the activate script in your command:
cd /path/to/sentry && source .venv/bin/activate && pytest tests/...Important for AI agents:
- Always use
required_permissions: ['all']when running Python commands to avoid sandbox permission issues - The
.venv/bin/prefix ensures you're using the correct Python interpreter and dependencies
# Install dependencies and setup development environment
make develop
# Or use the newer devenv command
devenv sync
# Activate the Python virtual environment (required for running tests and Python commands)
direnv allow
# Start dev dependencies
devservices up
# Start the development server
devservices serve# Preferred: Run pre-commit hooks on specific files
pre-commit run --files src/sentry/path/to/file.py
# Run all pre-commit hooks
pre-commit run --all-filesBefore you consider a coding task complete, run pre-commit on any files you created or modified. Use the actual paths (e.g. src/sentry/foo/bar.py, tests/sentry/foo/test_bar.py, static/app/components/foo.tsx):
# From repo root; for automation use the venv
cd /path/to/sentry && .venv/bin/pre-commit run --files <file1> [file2 ...]If pre-commit fails, fix the reported issues and run it again until it passes. Do not push with --no-verify to skip hooks—fix the issues and try again instead. Only then treat the task as done.
# Run Python tests (always use these parameters)
pytest -svv --reuse-db
# Run specific test file
pytest -svv --reuse-db tests/sentry/api/test_base.py# Run migrations
sentry django migrate
# Create new migration
sentry django makemigrations
# Update migration after rebase conflict (handles renaming, dependencies, lockfile)
./bin/update-migration <migration_name_or_number> <app_label>
# Example: ./bin/update-migration 0101_workflow_when_condition_group_unique workflow_engine
# Reset database
make reset-db# Start the development server
pnpm run dev
# Start only the UI development server with hot reload
pnpm run dev-uiTypechecking only works on the entire project. Individual files cannot be checked.
pnpm run typecheck# JavaScript/TypeScript linting
pnpm run lint:js
# Linting for specific file(s)
pnpm run lint:js components/avatar.tsx [...other files]
# Fix linting issues
pnpm run fix# Run JavaScript tests (always use CI flag)
CI=true pnpm test <file_path>
# Run specific test file(s)
CI=true pnpm test components/avatar.spec.tsxEach worktree has its own .venv. When you create a new worktree with git worktree add, a post-checkout hook runs devenv sync in the new worktree to setup the dev environment. Otherwise run devenv sync once in the new worktree, then direnv allow to validate and activate the dev environment.
Cursor is configured to automatically load relevant AGENTS.md files based on the file being edited (via .cursor/rules/*.mdc). This provides context-specific guidance without token bloat:
- Editing
src/**/*.py→ Loadssrc/AGENTS.md(backend patterns) - Editing
tests/**/*.py→ Loadstests/AGENTS.md(testing patterns) - Editing
static/**/*.{ts,tsx,js,jsx}→ Loadsstatic/AGENTS.md(frontend patterns) - Always loads this file (
AGENTS.md) for general Sentry context
Note: These .mdc files only reference AGENTS.md files—they don't duplicate content. All actual guidance should be added to the appropriate AGENTS.md file, not to Cursor rules.
For backend development patterns, security guidelines, and architecture, see src/AGENTS.md.
For backend testing patterns and best practices, see tests/AGENTS.md.
For frontend development patterns, design system guidelines, and React testing best practices, see static/AGENTS.md.
New features should be gated behind a feature flag.
-
Register the flag in
src/sentry/features/temporary.py:manager.add("organizations:my-feature", OrganizationFeature, FeatureHandlerStrategy.FLAGPOLE, api_expose=True)
Use
api_expose=Trueif the frontend needs to check the flag. UseProjectFeatureand aprojects:prefix for project-scoped flags. -
Python check:
if features.has("organizations:my-feature", organization, actor=user):
-
Frontend check (requires
api_expose=True):organization.features.includes('my-feature');
-
Tests:
with self.feature("organizations:my-feature"): ...
-
Rollout: FlagPole YAML config lives in the
sentry-options-automatorrepo, not here.
See https://develop.sentry.dev/feature-flags/ for full docs.
Frontend (static/) and backend (src/, tests/) are not atomically deployed. A CI check enforces this.
- If your changes touch both frontend and backend, split them into separate PRs.
- Land the backend PR first when the frontend depends on new API changes.
- Pure test additions alongside
src/changes are fine in one PR.