Multi-DSN Detection
The CLI scans the entire project tree to find all DSNs:Detection Algorithm
ThedetectAllDsns() function finds all DSNs in priority order:
Package Path Tracking
Each detected DSN includes its location in the monorepo:packagePath is inferred from the directory structure:
apps/frontend/.env→packagePath: "apps/frontend"packages/mobile/.env→packagePath: "packages/mobile".envat root →packagePath: undefined
Environment File Scanning
The CLI scans common monorepo directory patterns:Alias Generation
When multiple projects are detected, the CLI generates short aliases for easy reference:Alias Algorithm
Aliases are generated using shortest unique prefixes:Examples
Simple prefixes:Org-Aware Aliases
When projects span multiple organizations, aliases include org prefixes:Alias Cache
Generated aliases are cached in SQLite keyed by a fingerprint of detected DSNs:- DSNs are added/removed
- DSN values change
- Source files are modified
Multi-Project Commands
Commands that support multiple projects process all detected targets:Issue List Example
Resolution Logic
Prefix Relationships
The alias generator handles “one slug is prefix of another” relationships:Prefix stripping is skipped if it would create a collision with another slug (e.g., won’t strip “cli-” if “website” is also a project).
Common Word Prefix
When multiple projects share a common word prefix, it’s stripped for cleaner aliases:Multi-Region Support
When projects span multiple Sentry regions, the CLI handles region resolution automatically:us.sentry.io, de.sentry.io).
Performance Considerations
Fast path (cached): ~5-10ms to load cached aliasesSlow path (first run): ~2-5s to detect all DSNs and generate aliases
Best Practices
- Use package-specific .env files - Place
.envfiles in each package directory for accurate detection - Initialize Sentry in code - Explicit
Sentry.init()calls have higher priority than env files - Consistent naming - Use consistent project naming conventions to generate intuitive aliases
- Test detection - Run
sentry config detectto verify all projects are detected correctly
Troubleshooting
Projects Not Detected
If projects aren’t detected:- Verify DSN is present in source code or
.envfiles - Check that directories match monorepo patterns:
apps/*/,packages/*/, etc. - Ensure files aren’t in excluded directories (
node_modules/,vendor/, etc.)
Duplicate Aliases
If aliases collide:- The CLI will extend the prefix automatically
- For persistent collisions, rename projects to have more distinct prefixes
- Check cache with
sentry config show --jsonand clear if needed