Skip to content

fix(cloudflare): Skip SDK initialization for OPTIONS/HEAD requests#21090

Open
JPeer264 wants to merge 2 commits into
developfrom
jp/cloudflare-options-request-overhead
Open

fix(cloudflare): Skip SDK initialization for OPTIONS/HEAD requests#21090
JPeer264 wants to merge 2 commits into
developfrom
jp/cloudflare-options-request-overhead

Conversation

@JPeer264
Copy link
Copy Markdown
Member

@JPeer264 JPeer264 commented May 21, 2026

closes #21022
closes JS-2553

OPTIONS and HEAD requests now bypass SDK initialization entirely, eliminating ~450ms overhead per request. The early bail-out happens before any SDK work (OTel setup, integrations, init) runs.

This matches the Bun SDK's approach and addresses the performance issue where withSentry mutates handler.fetch in place, causing even "bypassed" requests to incur full init cost.

This will get rid of captureExceptions for these requests. Then again OPTIONS are just CORS preflight requests and should perform quick for the next request. Same for HEAD.

I played around to actually test against response times in an integration test, but they were not really reliable, even locally, so I decided to keep unit tests only. I also let the old behavior in as the wrapRequesetHandler is exposed and used in other SDKs (see #21090 (comment))

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@JPeer264 JPeer264 self-assigned this May 21, 2026
@JPeer264 JPeer264 requested a review from a team as a code owner May 21, 2026 08:11
@JPeer264 JPeer264 requested review from andreiborza and mydea and removed request for a team May 21, 2026 08:11
@linear-code
Copy link
Copy Markdown

linear-code Bot commented May 21, 2026

JS-2553

@JPeer264 JPeer264 requested a review from isaacs May 21, 2026 08:14
Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 6424081. Configure here.

Comment thread packages/cloudflare/src/request.ts
Comment thread packages/cloudflare/src/request.ts
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 21, 2026

size-limit report 📦

⚠️ Warning: Base artifact is not the latest one, because the latest workflow run is not done yet. This may lead to incorrect results. Try to re-run all tests to get up to date results.

Path Size % Change Change
@sentry/browser 27.31 kB - -
@sentry/browser - with treeshaking flags 25.73 kB - -
@sentry/browser (incl. Tracing) 45.31 kB - -
@sentry/browser (incl. Tracing + Span Streaming) 47.53 kB - -
@sentry/browser (incl. Tracing, Profiling) 50.29 kB - -
@sentry/browser (incl. Tracing, Replay) 84.91 kB - -
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 74.42 kB - -
@sentry/browser (incl. Tracing, Replay with Canvas) 89.63 kB - -
@sentry/browser (incl. Tracing, Replay, Feedback) 102.23 kB - -
@sentry/browser (incl. Feedback) 44.5 kB - -
@sentry/browser (incl. sendFeedback) 32.12 kB - -
@sentry/browser (incl. FeedbackAsync) 37.24 kB - -
@sentry/browser (incl. Metrics) 28.39 kB - -
@sentry/browser (incl. Logs) 28.62 kB - -
@sentry/browser (incl. Metrics & Logs) 29.32 kB - -
@sentry/react 29.04 kB - -
@sentry/react (incl. Tracing) 47.54 kB - -
@sentry/vue 32.23 kB - -
@sentry/vue (incl. Tracing) 47.16 kB - -
@sentry/svelte 27.34 kB - -
CDN Bundle 29.71 kB - -
CDN Bundle (incl. Tracing) 47.82 kB - -
CDN Bundle (incl. Logs, Metrics) 31.2 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) 49.07 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) 70.52 kB - -
CDN Bundle (incl. Tracing, Replay) 85.32 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 86.48 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) 91.18 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 92.33 kB - -
CDN Bundle - uncompressed 87.78 kB - -
CDN Bundle (incl. Tracing) - uncompressed 144.25 kB - -
CDN Bundle (incl. Logs, Metrics) - uncompressed 92.27 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 148.01 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 217 kB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 263.03 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 266.77 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 276.73 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 280.46 kB - -
@sentry/nextjs (client) 50.02 kB - -
@sentry/sveltekit (client) 45.79 kB - -
@sentry/core/server 76.29 kB - -
@sentry/core/browser 63.06 kB - -
@sentry/node-core 62.56 kB -0.01% -1 B 🔽
@sentry/node 164.31 kB - -
@sentry/node - without tracing 75 kB - -
@sentry/aws-serverless 87.22 kB - -
@sentry/cloudflare (withSentry) - minified 173.08 kB +0.08% +128 B 🔺
@sentry/cloudflare (withSentry) 432.39 kB +0.07% +261 B 🔺

View base workflow run

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.

perf(cloudflare): withSentry adds ~450ms per-request overhead to CORS preflight (OPTIONS) requests because handler.fetch is mutated in place

1 participant