Detection Priority
DSNs are detected in priority order (highest to lowest):- Source code - Explicit DSN in
Sentry.init()calls - Environment files -
.env,.env.local,.env.production, etc. - Environment variable -
SENTRY_DSN
Higher-priority sources override lower-priority ones. For example, a DSN in source code takes precedence over
.env files.Source Code Detection
The CLI scans source files for DSN patterns inSentry.init() calls:
Supported Languages
JavaScript/TypeScript:Detection Algorithm
The code scanner uses language-specific patterns:Environment File Detection
The CLI searches for DSN in environment files following the priority order:.env.local.env.development.local.env.production.local.env.test.local.env.env.development.env.production.env.test
Environment File Format
DSN can be specified in various formats:Parsing Logic
The environment file parser handles various formats:Environment Variable Detection
As a fallback, the CLI checks theSENTRY_DSN environment variable:
Project Root Detection
Before scanning for DSNs, the CLI must determine the project root. It walks up from the current directory looking for markers:VCS Markers
.git/.hg/.svn/
Language Markers
JavaScript/Node.js:package.jsontsconfig.jsonjsconfig.json
pyproject.tomlsetup.pysetup.cfgrequirements.txtPipfile
go.modgo.sum
pom.xmlbuild.gradlebuild.gradle.kts
Gemfile.ruby-version
composer.json
Cargo.toml
Detection Flow
Finding a DSN in.env during walk-up stops the walk (determines project root) but does NOT short-circuit detection - the CLI still scans for code DSNs which have higher priority.
Caching Strategy
Detection results are cached in SQLite to avoid repeated scans:DSN Cache Schema
Cache Validation
Cached entries are validated before use:Cache entries are invalidated when the source file changes or the DSN value differs.
Monorepo Support
The CLI detects multiple DSNs in monorepo structures:detectAllDsns() to find all DSNs:
packagePath (e.g., apps/frontend) to track which package it belongs to.
DSN Format
Detected DSNs are parsed into components:DSN Parsing Example
Some DSN formats (especially self-hosted) may not include an org ID in the host. In these cases, the CLI resolves the project using the DSN public key via the
/api/0/projects?query=dsn:<key> endpoint.Detection Performance
- Fast path (cache hit): ~5ms - reads single file to verify
- Slow path (cache miss): ~2-5s - full glob scan