Skip to main content
Sentry CLI is designed to work seamlessly with monorepo structures where multiple projects/apps share a single repository. The CLI can detect all DSNs, resolve them to their respective Sentry projects, and generate short aliases for easy identification.

Multi-DSN Detection

The CLI scans the entire project tree to find all DSNs:

Detection Algorithm

The detectAllDsns() function finds all DSNs in priority order:

Package Path Tracking

Each detected DSN includes its location in the monorepo:
The packagePath is inferred from the directory structure:
  • apps/frontend/.envpackagePath: "apps/frontend"
  • packages/mobile/.envpackagePath: "packages/mobile"
  • .env at 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:
Common word prefix stripping:

Org-Aware Aliases

When projects span multiple organizations, aliases include org prefixes:
Example with cross-org collisions:

Alias Cache

Generated aliases are cached in SQLite keyed by a fingerprint of detected DSNs:
The fingerprint is a hash of all detected DSNs:
Cache entries are invalidated when:
  • 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

Output:

Resolution Logic

Prefix Relationships

The alias generator handles “one slug is prefix of another” relationships:
Example:
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:
Example:

Multi-Region Support

When projects span multiple Sentry regions, the CLI handles region resolution automatically:
This ensures API calls target the correct regional endpoint (e.g., 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
The caching strategy ensures that subsequent commands in monorepos are nearly instant, even with dozens of projects.

Best Practices

  1. Use package-specific .env files - Place .env files in each package directory for accurate detection
  2. Initialize Sentry in code - Explicit Sentry.init() calls have higher priority than env files
  3. Consistent naming - Use consistent project naming conventions to generate intuitive aliases
  4. Test detection - Run sentry config detect to verify all projects are detected correctly

Troubleshooting

Projects Not Detected

If projects aren’t detected:
  1. Verify DSN is present in source code or .env files
  2. Check that directories match monorepo patterns: apps/*/, packages/*/, etc.
  3. Ensure files aren’t in excluded directories (node_modules/, vendor/, etc.)

Duplicate Aliases

If aliases collide:
  1. The CLI will extend the prefix automatically
  2. For persistent collisions, rename projects to have more distinct prefixes
  3. Check cache with sentry config show --json and clear if needed

Cache Invalidation

To force cache refresh: