fix(cloudflare, vercel-edge): Disable timer-based flush for serverless runtimes#20889
Open
sergical wants to merge 1 commit into
Open
fix(cloudflare, vercel-edge): Disable timer-based flush for serverless runtimes#20889sergical wants to merge 1 commit into
sergical wants to merge 1 commit into
Conversation
…s runtimes The weight-based flushing mechanism for logs and metrics schedules a `setTimeout(fn, 5000)` after each capture. In Cloudflare Workers built with `@cloudflare/vite-plugin` (native ESM + `no_bundle: true`), workerd rejects this timer as running outside request context. Add a `_flushInterval` internal option to `ClientOptions`. When set to 0, the idle flush timer is skipped entirely. Size-based flushing (800KB) and explicit `flush()` calls (via `withSentry` → `flushAndDispose`) still work. Set `_flushInterval: 0` in `CloudflareClient` and `VercelEdgeClient`. Fixes #20888 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Contributor
size-limit report 📦
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
_flushIntervalinternal option toClientOptions— controls the idle flush timer interval for logs/metrics weight-based flushing0, skipssetTimeoutentirely; size-based flush (800KB) and explicitflush()still work_flushInterval: 0inCloudflareClientandVercelEdgeClientContext
The core client's
setupWeightBasedFlushingschedules asetTimeout(fn, 5000)after each metric/log capture. In Cloudflare Workers built with@cloudflare/vite-plugin(native ESM +no_bundle: true), workerd rejects this timer as running outside request context — even though the code executes within awithSentryhandler.This does not affect Wrangler's single-bundle output. The difference is how workerd tracks request context across ESM module boundaries with
no_bundle: true.Zero performance impact for serverless — each request creates its own client, so the batching window never spans multiple requests.
withSentry→flushAndDisposealready callsflush()at end of every request.Fixes #20888
Reported stack trace: #20888 (comment)
Test plan
_flushInterval: 0prevents timer creation (nosafeUnrefcall)_flushInterval: 0still flushes viaflushevent_flushInterval: 0still flushes on 800KB size threshold@sentry/core,@sentry/cloudflare,@sentry/vercel-edge🤖 Generated with Claude Code