Skip to content

ref(core): Use DEBUG_BUILD ternaries so esbuild drops debug-only code - #26142

Open
sentry-junior[bot] wants to merge 1 commit into
developfrom
ref/debug-build-positive-guards
Open

sentry-junior[bot] wants to merge 1 commit into
developfrom
ref/debug-build-positive-guards

Conversation

@sentry-junior

@sentry-junior sentry-junior Bot commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

Why: esbuild inlines the imported DEBUG_BUILD constant only after its dead-code pass. So with __SENTRY_DEBUG__: false, logSpanStart/logSpanEnd, validateDsn and one idleSpan debug block stayed in the bundle as if(!!1)return;… / if(!1){let …}. Switching to the positive if (DEBUG_BUILD) { … } form doesn't fix it: esbuild still keeps the block whenever it declares let/const. What does work is the module-level DEBUG_BUILD ? fn : () => {} ternary already used in double-wrap-warning.ts, plus guarded blocks that contain no declarations. The debug-logger.ts early returns already compile away (no declarations follow them), so I left them alone. Behavior in debug builds is unchanged.

Savings with esbuild 0.27.7 (minify, ESM, browser, __SENTRY_DEBUG__: false) on a tracing-only setup (BrowserClient + browserTracingIntegration): 1,273 B raw / 329 B br-11 (131,185 → 129,912 B raw).

This PR adds an esbuild size-limit entry, because every current entry uses webpack + terser and can't see this. On the new entry, gzip goes from 53,333 to 52,906 B. The webpack entries with treeshaking flags don't change. Those without a define grow by about 11–14 B gzip from the ternary wrappers.

How to review: Most of the logSpans.ts/dsn.ts diff is re-indentation (view with whitespace hidden). dsn.test.ts now re-imports the module with vi.resetModules() to test the non-debug path, because the ternary is evaluated at import time. double-wrap-warning.test.ts does the same.

Unsure about: Whether you want the new esbuild size-limit entry, or would rather track this some other way.

Closes #26140

via @BYK.

--

View Session in Sentry

esbuild inlines the imported DEBUG_BUILD constant after its dead-code
pass, so early-return guards and guarded blocks with declarations stayed
in non-debug bundles. Also adds an esbuild size-limit entry.

Closes #26140

Co-Authored-By: BYK <126780+BYK@users.noreply.github.com>
@sentry-junior
sentry-junior Bot requested review from a team as code owners November 5, 2026 13:28
@sentry-junior
sentry-junior Bot requested review from Lms24, andreiborza, logaretm, mydea and s1gr1d and removed request for a team November 5, 2026 13:28
@github-actions

github-actions Bot commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

size-limit report 📦

Compared: 0f36283 (PR test merge using develop at c054e7a)

Against: c054e7a (develop) · base run #65086

✅ Baseline matches: this diff contains only this PR's changes.

Path Size % Change Change
@sentry/browser 30.41 kB +0.04% +11 B 🔺
@sentry/browser - with treeshaking flags 28.54 kB - -
@sentry/browser - with treeshaking flags tracing without tracing 28.43 kB - -
@sentry/browser (incl. Tracing) 52.74 kB +0.03% +14 B 🔺
@sentry/browser (incl. Tracing + Span Streaming) 52.74 kB +0.02% +8 B 🔺
@sentry/browser (incl. Tracing, Profiling) 55.7 kB -0.01% -2 B 🔽
@sentry/browser (incl. Tracing, Replay) 93.04 kB +0.02% +10 B 🔺
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 81.63 kB - -
@sentry/browser (incl. Tracing, Replay with Canvas) 97.78 kB +0.01% +4 B 🔺
@sentry/browser (incl. Tracing, Replay, Feedback) 110.78 kB +0.02% +15 B 🔺
@sentry/browser (incl. Feedback) 47.99 kB +0.02% +7 B 🔺
@sentry/browser (incl. sendFeedback) 35.51 kB +0.02% +6 B 🔺
@sentry/browser (incl. FeedbackAsync) 40.62 kB +0.03% +11 B 🔺
@sentry/browser (incl. Metrics) 31.44 kB +0.02% +4 B 🔺
@sentry/browser (incl. Logs) 31.75 kB +0.05% +15 B 🔺
@sentry/browser (incl. Metrics & Logs) 32.47 kB +0.05% +15 B 🔺
@sentry/react 32.3 kB +0.05% +13 B 🔺
@sentry/react (incl. Tracing) 55.1 kB +0.01% +2 B 🔺
@sentry/vue 38.69 kB +0.05% +16 B 🔺
@sentry/vue (incl. Tracing) 55.74 kB -0.02% -8 B 🔽
@sentry/svelte 30.44 kB +0.04% +11 B 🔺
@sentry/remix (Remix 3 client bundle) 57.84 kB +0.04% +18 B 🔺
CDN Bundle 32.2 kB - -
CDN Bundle (incl. Tracing) 53.26 kB - -
CDN Bundle (incl. Logs, Metrics) 34.47 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) 55.2 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) 75.88 kB - -
CDN Bundle (incl. Tracing, Replay) 91.47 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 93.4 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) 97.58 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 99.58 kB - -
CDN Bundle - uncompressed 94.67 kB - -
CDN Bundle (incl. Tracing) - uncompressed 157.67 kB - -
CDN Bundle (incl. Logs, Metrics) - uncompressed 101.14 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 163.41 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 232.71 kB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 279.36 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 285.08 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 293.06 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 298.77 kB - -
@sentry/nextjs (client) 58.06 kB +0.01% +4 B 🔺
@sentry/sveltekit (client) 53.27 kB +0.04% +21 B 🔺
@sentry/core/server 44.29 kB +0.11% +45 B 🔺
@sentry/core/browser 13.93 kB +0.04% +5 B 🔺
@sentry/node 156.06 kB +0.02% +16 B 🔺
@sentry/node/import (ESM hook with diagnostics-channel injection) 82.28 kB - -
@sentry/node - without tracing 96.92 kB +0.03% +28 B 🔺
@sentry/node - without channel injection 136.41 kB +0.04% +53 B 🔺
@sentry/aws-serverless 105.11 kB +0.02% +16 B 🔺
@sentry/cloudflare (withSentry) - minified 200.59 kB -0.05% -87 B 🔽
@sentry/cloudflare (withSentry) 498.92 kB -0.03% -122 B 🔽
@sentry/nextjs/cloudflare (withSentry) - minified 222.59 kB -0.04% -87 B 🔽
@sentry/browser (incl. Tracing) - esbuild with treeshaking flags 52.91 kB added added

View base workflow run

@github-actions

github-actions Bot commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

Optional E2E tests

Some optional checks were not successful. They do not block the merge. 6 not successful, 50 successful. See the run.

Check Status
❌ CI: Optional E2E Tests / E2E cloudflare-pi-durable (latest) Test (optional) Failing after 48s Details
❌ CI: Optional E2E Tests / E2E node-eve (orchestrion) Test (optional) Failing after 2m Details
❌ CI: Optional E2E Tests / E2E node-flue (latest) Test (optional) Failing after 39s Details
⛔ CI: Optional E2E Tests / E2E nextjs-16-cacheComponents (cloudflare) Test (optional) Cancelled after 15m Details
❌ CI: Optional E2E Tests / E2E node-eve Test (optional) Failing after 2m Details
❌ CI: Optional E2E Tests / E2E node-eve (latest) Test (optional) Failing after 1m Details
Successful checks
Check Status
✅ CI: Optional E2E Tests / E2E cloudflare-mastra Test (optional) Successful in 53s Details
✅ CI: Optional E2E Tests / E2E cloudflare-think Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E cloudflare-agent Test (optional) Successful in 41s Details
✅ CI: Optional E2E Tests / E2E nextjs-14 (latest) Test (optional) Successful in 11m Details
✅ CI: Optional E2E Tests / E2E deno (latest) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E astro-7-static Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E gen-ai-libraries Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E cloudflare-think (ai v6) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E nextjs-16 (vinext) Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E nuxt-5-sourcemaps (static / nuxt generate) Test (optional) Successful in 58s Details
✅ CI: Optional E2E Tests / E2E gen-ai-libraries (latest) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E node-pi-durable (latest) Test (optional) Successful in 43s Details
✅ CI: Optional E2E Tests / E2E cloudflare-flue-send-to-sentry Test (optional) Successful in 8m Details
✅ CI: Optional E2E Tests / E2E node-express-send-to-sentry-static Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E nextjs-15 (turbo) Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E astro-7 Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E cloudflare-workers-send-to-sentry Test (optional) Successful in 3m Details
✅ CI: Optional E2E Tests / E2E nestjs-12 (latest) Test (optional) Successful in 54s Details
✅ CI: Optional E2E Tests / E2E nextjs-16 (deno) Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E cloudflare-pi-durable Test (optional) Successful in 5m Details
✅ CI: Optional E2E Tests / E2E nextjs-16 (cloudflare, latest) Test (optional) Successful in 6m Details
✅ CI: Optional E2E Tests / E2E nextjs-16 (vinext, bun) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E debug-id-sourcemaps Test (optional) Successful in 41s Details
✅ CI: Optional E2E Tests / E2E node-fastify-6 Test (optional) Successful in 5m Details
✅ CI: Optional E2E Tests / E2E nuxt-5 (tunnel-dev) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E nextjs-15 (latest) Test (optional) Successful in 8m Details
✅ CI: Optional E2E Tests / E2E gen-ai-libraries (cloudflare) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E tanstackstart-react (latest) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E node-express-mcp-v2 Test (optional) Successful in 5m Details
✅ CI: Optional E2E Tests / E2E nuxt-5-sourcemaps (client source maps kept) Test (optional) Successful in 6m Details
✅ CI: Optional E2E Tests / E2E solidstart-2 Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E vue-3 (no Options API) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E nextjs-16-tunnel (cloudflare) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E nextjs-orpc Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E node-pi-durable Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E node-openai-decisions Test (optional) Successful in 46s Details
✅ CI: Optional E2E Tests / E2E react-router-7-framework-instrumentation Test (optional) Successful in 11m Details
✅ CI: Optional E2E Tests / E2E node-mastra (latest) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E tanstackstart-react-cloudflare Test (optional) Successful in 51s Details
✅ CI: Optional E2E Tests / E2E node-fastify-6 (tracer provider) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E node-openai-decisions (latest) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E supabase-nextjs Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E nuxt-5 Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E nuxt-5-sourcemaps Test (optional) Successful in 37s Details
✅ CI: Optional E2E Tests / E2E node-mastra Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E node-express-send-to-sentry Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E node-express-mcp-v1 Test (optional) Successful in 43s Details
✅ CI: Optional E2E Tests / E2E react-send-to-sentry Test (optional) Successful in 4m Details
✅ CI: Optional E2E Tests / E2E node-flue Test (optional) Successful in 11m Details
✅ CI: Optional E2E Tests / E2E tanstackstart-react-sourcemaps Test (optional) Successful in 36s Details

This branch has not been deployed

No deployments
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.

Debug-only code survives esbuild DCE (early-return guard)

1 participant