@@ -24,6 +24,7 @@ import {
2424 getCachedProjectRoot ,
2525 setCachedProjectRoot ,
2626} from "../db/project-root-cache.js" ;
27+ import { logger } from "../logger.js" ;
2728import {
2829 extractFirstDsnFromContent ,
2930 scanCodeForDsns ,
@@ -44,6 +45,8 @@ import type {
4445 DsnSource ,
4546} from "./types.js" ;
4647
48+ const log = logger . withTag ( "dsn-detect" ) ;
49+
4750/**
4851 * Detect DSN with project root detection and caching support.
4952 *
@@ -86,6 +89,7 @@ export async function detectDsn(cwd: string): Promise<DetectedDsn | null> {
8689 }
8790
8891 // Cache hit! Return with resolved info if available
92+ log . debug ( `DSN cache hit for ${ projectRoot } ` ) ;
8993 return {
9094 ...verified ,
9195 resolved : cached . resolved ,
@@ -98,6 +102,9 @@ export async function detectDsn(cwd: string): Promise<DetectedDsn | null> {
98102 const detected = await fullScanFirst ( projectRoot ) ;
99103
100104 if ( detected ) {
105+ log . debug (
106+ `DSN detected: ${ detected . raw } from ${ getDsnSourceDescription ( detected ) } `
107+ ) ;
101108 // Cache for next time (without resolved info yet)
102109 setCachedDsn ( projectRoot , {
103110 dsn : detected . raw ,
@@ -106,6 +113,8 @@ export async function detectDsn(cwd: string): Promise<DetectedDsn | null> {
106113 source : detected . source ,
107114 sourcePath : detected . sourcePath ,
108115 } ) ;
116+ } else {
117+ log . debug ( `No DSN found after full scan of ${ projectRoot } ` ) ;
109118 }
110119
111120 return detected ;
@@ -144,11 +153,16 @@ export async function detectAllDsns(cwd: string): Promise<DsnDetectionResult> {
144153 } ) ;
145154 }
146155
156+ log . debug ( `DSN detection starting from project root: ${ projectRoot } ` ) ;
157+
147158 // 2. Try cached detection result
148159 const cachedDetection = await getCachedDetection ( projectRoot ) ;
149160
150161 if ( cachedDetection ) {
151162 // Cache hit! Return cached result
163+ log . debug (
164+ `DSN detection cache hit: ${ cachedDetection . allDsns . length } DSN(s) cached`
165+ ) ;
152166 return {
153167 primary : cachedDetection . allDsns [ 0 ] ?? null ,
154168 all : cachedDetection . allDsns ,
@@ -182,6 +196,9 @@ export async function detectAllDsns(cwd: string): Promise<DsnDetectionResult> {
182196 }
183197 Object . assign ( allSourceMtimes , codeMtimes ) ;
184198 Object . assign ( allDirMtimes , codeDirMtimes ) ;
199+ if ( codeDsns . length > 0 ) {
200+ log . debug ( `Found ${ codeDsns . length } DSN(s) in source code` ) ;
201+ }
185202
186203 // 3b. Check all .env files from project root (includes monorepo packages/apps)
187204 const { dsns : envFileDsns , sourceMtimes : envMtimes } =
@@ -190,11 +207,15 @@ export async function detectAllDsns(cwd: string): Promise<DsnDetectionResult> {
190207 addDsn ( dsn ) ;
191208 }
192209 Object . assign ( allSourceMtimes , envMtimes ) ;
210+ if ( envFileDsns . length > 0 ) {
211+ log . debug ( `Found ${ envFileDsns . length } DSN(s) in .env files` ) ;
212+ }
193213
194214 // 3c. Check env var (lowest priority) - no mtime for env vars
195215 const envDsn = detectFromEnv ( ) ;
196216 if ( envDsn ) {
197217 addDsn ( envDsn ) ;
218+ log . debug ( "Found DSN in SENTRY_DSN environment variable" ) ;
198219 }
199220
200221 // 4. Compute fingerprint and cache result
@@ -222,6 +243,16 @@ export async function detectAllDsns(cwd: string): Promise<DsnDetectionResult> {
222243 // Multiple DSNs is valid in monorepos (different packages/apps)
223244 const hasMultiple = allDsns . length > 1 ;
224245
246+ if ( allDsns . length > 0 ) {
247+ log . debug ( `DSN detection complete: ${ allDsns . length } total DSN(s) found` ) ;
248+ for ( const dsn of allDsns ) {
249+ const isPrimary = dsn === allDsns [ 0 ] ? " [primary]" : "" ;
250+ log . debug ( ` ${ dsn . raw } — ${ getDsnSourceDescription ( dsn ) } ${ isPrimary } ` ) ;
251+ }
252+ } else {
253+ log . debug ( "DSN detection complete: no DSNs found" ) ;
254+ }
255+
225256 return {
226257 primary : allDsns [ 0 ] ?? null ,
227258 all : allDsns ,
0 commit comments