Repository navigation
feat(browser): Make XHR request instrumentation tree-shakeable - #26134
sentry-junior[bot] wants to merge 1 commit into
Conversation
Bundlers can define `__SENTRY_EXCLUDE_XHR_TRACING__: true` to drop XHR request instrumentation and its span code. Defaults are unchanged. Co-Authored-By: BYK <126780+BYK@users.noreply.github.com>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 6c59cab. Configure here.
size-limit report 📦Compared: 5bea4d4 (PR test merge using develop at c054e7a) Against: c054e7a (develop) · base run #65086 ✅ Baseline matches: this diff contains only this PR's changes.
|
Optional E2E testsSome optional checks were not successful. They do not block the merge. 1 not successful, 24 successful. See the run.
Successful checks
|
|
Thanks for this. Same reasoning as #26143, I'd rather not go the build flag route here. I think a flag is a fair implementation given that XHR is stuck as a default in the integration. But we can keep it on by default and still make it shakeable, we already did some work for with The idea we are thinking about is fetch-only apps that care about size can skip Closing this PR, but feel free to talk to us more about this there if there are strong opinions about this. |

Why:
browserTracingIntegration()always bundles XHR request instrumentation becausetraceXHRis only checked at runtime. Apps that only usefetchcan't drop it. This adds a__SENTRY_EXCLUDE_XHR_TRACING__build-time flag, following the__SENTRY_EXCLUDE_REPLAY_WORKER__/__RRWEB_EXCLUDE_*__pattern: bundlers define it astrueand the XHR handler,xhrCallbackand its helpers get tree-shaken. If the flag isn't defined, nothing changes:traceXHRstill defaults totrueand no public options change.I picked a build flag over a separate opt-in integration because the feature has to stay on by default, and that's how the SDK already exposes opt-out tree-shaking. This is one of a set of PRs that use the same
__SENTRY_EXCLUDE_*__mechanism for other default-onbrowserTracingIntegrationfeatures.Measured with a tracing-only setup (
BrowserClient+browserTracingIntegration(), esbuild 0.27, minified ESM,__SENTRY_DEBUG__: false):__SENTRY_EXCLUDE_XHR_TRACING__: trueSaving with the flag: 2,976 B raw / 860 B br. Without the flag, the guard adds 78 B raw / 31 B br. Locally, size-limit
@sentry/browser (incl. Tracing)went from 52,727 B to 52,770 B gzip.Unsure about: Whether you also want a
bundleSizeOptimizations.excludeXhrTracingoption in the bundler plugins and Next.jsgetTreeshakeDefines, plus a docs entry on the tree-shaking page. I kept this PR to the SDK guard, like #22835 did.Closes #26133
via @BYK.
--
View Session in Sentry