Skip to content

fix(dsn): make code scanner monorepo-aware and extend --fresh to bypass DSN cache#420

Merged
BYK merged 5 commits intomainfrom
fix/monorepo-dsn-scan-depth
Mar 13, 2026
Merged

fix(dsn): make code scanner monorepo-aware and extend --fresh to bypass DSN cache#420
BYK merged 5 commits intomainfrom
fix/monorepo-dsn-scan-depth

Conversation

@betegon
Copy link
Member

@betegon betegon commented Mar 13, 2026

Summary

The DSN code scanner missed files inside monorepo packages because MAX_SCAN_DEPTH=2 couldn't reach past packages/<name>/src/. For example, in the spotlight monorepo only 1 of 3 DSNs was detected — packages/website/sentry.client.config.mjs at depth 2 was found, but packages/spotlight/src/instrument.ts at depth 3 was not.

Even after fixing the scanner, stale cached results survive because mtime validation only checks files that were previously found — files missed by the old depth limit have no cache entries. Users had no way to force a re-scan.

Changes

Scanner fix:

  • Bump MAX_SCAN_DEPTH from 2 to 3 (also helps non-monorepo projects with deeper configs like src/lib/config/sentry.ts)
  • Reset depth to 0 when entering a monorepo package directory (packages/*, apps/*, libs/*, services/*, modules/*), giving each package its own depth-3 scanning budget
  • Uses the existing MONOREPO_ROOTS constant from types.ts, matching how the env file scanner already handles monorepos

Cache bypass (--fresh):

  • Add disableDsnCache()/enableDsnCache() following the same pattern as disableResponseCache()
  • Wire into applyFreshFlag() so --fresh now bypasses both HTTP response cache and DSN detection cache
  • Cache writes still proceed when disabled, so the re-scanned result gets stored for next time

Test plan

  • Added test: finds DSNs in monorepo packages deeper than MAX_SCAN_DEPTH
  • Added test: finds DSNs from multiple monorepo packages with correct packagePath
  • Added tests: getCachedDsn/getCachedDetection return undefined when cache disabled, writes persist
  • All code-scanner and dsn-cache tests pass
  • Typecheck passes
  • Lint passes
  • Manual test: run sentry issue list --fresh from spotlight monorepo, verify multiple projects detected

🤖 Generated with Claude Code

The code scanner used MAX_SCAN_DEPTH=2 which couldn't reach files inside
monorepo packages (e.g., packages/spotlight/src/instrument.ts at depth 3).
The packages/ prefix consumed the full depth budget, leaving nothing for src/.

Bump MAX_SCAN_DEPTH to 3 and reset depth to 0 when entering a monorepo
package directory (packages/*, apps/*, etc.), giving each package its own
depth budget. This matches how the env file scanner already handles monorepos.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@github-actions
Copy link
Contributor

github-actions bot commented Mar 13, 2026

Semver Impact of This PR

🟢 Patch (bug fixes)

📋 Changelog Preview

This is how your changes will appear in the changelog.
Entries from this PR are highlighted with a left border (blockquote style).


New Features ✨

Init

  • Add --team flag to relay team selection to project creation by MathurAditya724 in #403
  • Enforce canonical feature display order by betegon in #388
  • Accept multiple delimiter formats for --features flag by betegon in #386
  • Add git safety checks before wizard modifies files by betegon in #379
  • Add experimental warning before wizard runs by betegon in #378
  • Add init command for guided Sentry project setup by betegon in #283

Issue List

  • Auto-compact when table exceeds terminal height by BYK in #395
  • Redesign table to match Sentry web UI by BYK in #372

Other

  • (auth) Allow re-authentication without manual logout by BYK in #417
  • (trial) Auto-prompt for Seer trial + sentry trial list/start commands by BYK in #399
  • Support SENTRY_HOST as alias for SENTRY_URL by betegon in #409
  • Add --dry-run flag to mutating commands by BYK in #387
  • Return-based output with OutputConfig on buildCommand by BYK in #380
  • Add --fields flag for context-window-friendly JSON output by BYK in #373
  • Magic @ selectors (@latest, @most_frequent) for issue commands by BYK in #371
  • Input hardening against agent hallucinations by BYK in #370
  • Add response caching for read-only API calls by BYK in #330

Bug Fixes 🐛

Dsn

  • Make code scanner monorepo-aware and extend --fresh to bypass DSN cache by betegon in #420

Init

  • Remove implementation detail from help text by betegon in #385
  • Truncate uncommitted file list to first 5 entries by MathurAditya724 in #381

Other

  • (api) Convert --data to query params for GET requests by BYK in #383
  • (docs) Remove double borders and fix column alignment on landing page tables by betegon in #369
  • Show human-friendly names in trial list and surface plan trials by BYK in #412
  • Add trace ID validation to trace view + UUID dash-stripping by BYK in #375

Documentation 📚

  • Update credential storage docs and remove stale config.json references by betegon in #408

Internal Changes 🔧

Init

  • Remove --force flag by betegon in #377
  • Remove dead determine-pm step label by betegon in #374

Other

  • (log/list) Convert non-follow paths to return CommandOutput by BYK in #410
  • (tests) Remove redundant and low-value tests by BYK in #418
  • Convert list command handlers to return data instead of writing stdout by BYK in #404
  • Split api-client.ts into focused domain modules by BYK in #405
  • Migrate non-streaming commands to CommandOutput with markdown rendering by BYK in #398
  • Convert Tier 2-3 commands to return-based output and consola by BYK in #394
  • Convert remaining Tier 1 commands to return-based output by BYK in #382
  • Converge Tier 1 commands to writeOutput helper by BYK in #376

Other

  • Minify JSON on read and pretty-print on write in init local ops by MathurAditya724 in #396

🤖 This preview updates automatically when you update the PR.

@github-actions
Copy link
Contributor

github-actions bot commented Mar 13, 2026

Codecov Results 📊

111 passed | Total: 111 | Pass Rate: 100% | Execution Time: 0ms

📊 Comparison with Base Branch

Metric Change
Total Tests
Passed Tests
Failed Tests
Skipped Tests

✨ No test changes detected

All tests are passing successfully.

✅ Patch coverage is 96.43%. Project has 1065 uncovered lines.
✅ Project coverage is 95.03%. Comparing base (base) to head (head).

Files with missing lines (3)
File Patch % Lines
dsn-cache.ts 95.69% ⚠️ 10 Missing
code-scanner.ts 98.18% ⚠️ 6 Missing
list-command.ts 98.92% ⚠️ 2 Missing
Coverage diff
@@            Coverage Diff             @@
##          main       #PR       +/-##
==========================================
+ Coverage    95.02%    95.03%    +0.01%
==========================================
  Files          159       159         —
  Lines        21404     21428       +24
  Branches         0         0         —
==========================================
+ Hits         20339     20363       +24
- Misses        1065      1065         —
- Partials         0         0         —

Generated by Codecov Action

betegon and others added 2 commits March 13, 2026 17:29
After the scanner fix, stale cached results (with fewer DSNs) survive
because mtime validation only checks files that were previously found.
Users had no way to force a re-scan short of manually clearing SQLite.

Add disableDsnCache()/enableDsnCache() following the same pattern as
disableResponseCache(), and wire it into applyFreshFlag() so --fresh
now bypasses both HTTP response cache and DSN detection cache.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@betegon betegon marked this pull request as ready for review March 13, 2026 16:36
@betegon betegon changed the title fix(dsn): make code scanner monorepo-aware with depth reset fix(dsn): make code scanner monorepo-aware and extend --fresh to bypass DSN cache Mar 13, 2026
betegon and others added 2 commits March 13, 2026 17:49
Add projects, plugins, sites, workers, and functions to the list of
recognized monorepo root directories. These cover Google-style monorepos,
WordPress/Grafana plugin repos, multi-site setups, Cloudflare Workers,
and AWS Lambda serverless monorepos respectively.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add test for deeply nested monorepo files (depth 5 from root, the
specific case from the original bug) and a negative test confirming
non-monorepo directories still respect the depth limit.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@betegon betegon requested a review from BYK March 13, 2026 17:14
Copy link
Member

@BYK BYK left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀 let's ship this

@BYK BYK merged commit f2058cc into main Mar 13, 2026
22 checks passed
@BYK BYK deleted the fix/monorepo-dsn-scan-depth branch March 13, 2026 18:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants