Skip to content

ref(core): Set up log and metric flushing on first capture - #26146

Merged
andreiborza merged 2 commits into
developfrom
ref/lazy-log-metric-flushing
Nov 6, 2026
Merged

andreiborza merged 2 commits into
developfrom
ref/lazy-log-metric-flushing

Conversation

@sentry-junior

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

Copy link
Copy Markdown
Contributor

Why: The Client constructor always called setupWeightBasedFlushing for logs and metrics, so every bundle carried the log and metric flush, envelope and size-estimation code, even apps that never capture either. Flushing is now set up in _INTERNAL_captureSerializedLog / _INTERNAL_captureSerializedMetric when a client's buffer is first created. That is the single entry point every log or metric passes through before it can be flushed: _INTERNAL_captureLog/captureMetric, and direct callers of the serialized variants. Setup still runs before the first afterCaptureLog/afterCaptureMetric emit.

Logs and metrics behave as before: the same 800 KB weight threshold, the idle timer, _flushInterval, and draining on flush()/close(). The only difference is that a client with nothing buffered no longer registers these hooks. Flushing an empty buffer was already a no-op.

Savings with esbuild 0.27.7 (minify, ESM, browser, __SENTRY_DEBUG__: false) on a tracing-only setup (BrowserClient + browserTracingIntegration): 2,068 B raw / 445 B br-11 (131,185 → 129,117 B raw). Locally, size-limit gzip for @sentry/browser goes from 30,403 to 29,885 B, and for @sentry/browser (incl. Tracing) from 52,727 to 52,173 B.

How to review: The helper and estimators moved unchanged into utils/weightBasedFlushing.ts. The "close flushes the logs buffer" test now captures a log first. It used to spy on _INTERNAL_flushLogsBuffer with an empty buffer, which no longer reflects the contract.

Closes #26145

via @BYK.

--

View Session in Sentry

The client constructor always set up weight-based flushing, which pulled
the log and metric buffer and envelope code into every bundle. Flushing
is now set up when a client's log or metric buffer is first created.

Closes #26145

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

github-actions Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

size-limit report 📦

Compared: 0f4d54c (PR test merge using develop at 8c2bc97)

Against: 8c2bc97 (develop) · base run #65215

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

Path Size % Change Change
@sentry/browser 29.88 kB -1.71% -518 B 🔽
@sentry/browser - with treeshaking flags 28.04 kB -1.77% -505 B 🔽
@sentry/browser - with treeshaking flags tracing without tracing 27.93 kB -1.76% -498 B 🔽
@sentry/browser (incl. Tracing) 52.17 kB -1.06% -556 B 🔽
@sentry/browser (incl. Tracing + Span Streaming) 52.17 kB -1.06% -558 B 🔽
@sentry/browser (incl. Tracing, Profiling) 55.16 kB -0.98% -544 B 🔽
@sentry/browser (incl. Tracing, Replay) 92.47 kB -0.61% -563 B 🔽
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 81.16 kB -0.58% -470 B 🔽
@sentry/browser (incl. Tracing, Replay with Canvas) 97.2 kB -0.6% -580 B 🔽
@sentry/browser (incl. Tracing, Replay, Feedback) 110.21 kB -0.51% -560 B 🔽
@sentry/browser (incl. Feedback) 47.49 kB -1.04% -495 B 🔽
@sentry/browser (incl. sendFeedback) 34.98 kB -1.48% -525 B 🔽
@sentry/browser (incl. FeedbackAsync) 40.09 kB -1.26% -511 B 🔽
@sentry/browser (incl. Metrics) 31.44 kB +0.02% +6 B 🔺
@sentry/browser (incl. Logs) 31.73 kB +0.02% +4 B 🔺
@sentry/browser (incl. Metrics & Logs) 32.42 kB -0.08% -25 B 🔽
@sentry/react 31.74 kB -1.69% -545 B 🔽
@sentry/react (incl. Tracing) 54.57 kB -0.96% -525 B 🔽
@sentry/vue 38.17 kB -1.29% -497 B 🔽
@sentry/vue (incl. Tracing) 55.19 kB -1% -555 B 🔽
@sentry/svelte 29.9 kB -1.72% -523 B 🔽
@sentry/remix (Remix 3 client bundle) 57.79 kB -0.06% -30 B 🔽
CDN Bundle 31.68 kB -1.62% -519 B 🔽
CDN Bundle (incl. Tracing) 52.77 kB -0.92% -488 B 🔽
CDN Bundle (incl. Logs, Metrics) 34.49 kB +0.06% +19 B 🔺
CDN Bundle (incl. Tracing, Logs, Metrics) 55.26 kB +0.11% +60 B 🔺
CDN Bundle (incl. Replay, Logs, Metrics) 75.86 kB -0.04% -23 B 🔽
CDN Bundle (incl. Tracing, Replay) 90.94 kB -0.59% -532 B 🔽
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 93.49 kB +0.1% +85 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback) 97.09 kB -0.5% -486 B 🔽
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 99.68 kB +0.11% +104 B 🔺
CDN Bundle - uncompressed 92.61 kB -2.18% -2.06 kB 🔽
CDN Bundle (incl. Tracing) - uncompressed 155.63 kB -1.3% -2.04 kB 🔽
CDN Bundle (incl. Logs, Metrics) - uncompressed 101.14 kB -0.01% -3 B 🔽
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 163.4 kB -0.01% -1 B 🔽
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 232.71 kB -0.01% -1 B 🔽
CDN Bundle (incl. Tracing, Replay) - uncompressed 277.32 kB -0.74% -2.04 kB 🔽
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 285.08 kB -0.01% -1 B 🔽
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 291.02 kB -0.7% -2.04 kB 🔽
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 298.77 kB -0.01% -1 B 🔽
@sentry/nextjs (client) 57.55 kB -0.87% -500 B 🔽
@sentry/sveltekit (client) 52.7 kB -1.02% -542 B 🔽
@sentry/core/server 43.8 kB -1.02% -447 B 🔽
@sentry/core/browser 13.93 kB - -
@sentry/node 156.4 kB -0.36% -556 B 🔽
@sentry/node/import (ESM hook with diagnostics-channel injection) 82.27 kB -0.01% -2 B 🔽
@sentry/node - without tracing 96.56 kB -0.49% -470 B 🔽
@sentry/node - without channel injection 136.72 kB -0.42% -567 B 🔽
@sentry/aws-serverless 104.89 kB -0.48% -496 B 🔽
@sentry/cloudflare (withSentry) - minified 199.77 kB -0.46% -911 B 🔽
@sentry/cloudflare (withSentry) 496.55 kB -0.51% -2.51 kB 🔽
@sentry/nextjs/cloudflare (withSentry) - minified 221.77 kB -0.41% -911 B 🔽

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. 7 not successful, 49 successful. See the run.

Check Status
❌ CI: Optional E2E Tests / E2E cloudflare-pi-durable (latest) Test (optional) Failing after 41s 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 12m Details
❌ CI: Optional E2E Tests / E2E node-eve (latest) Test (optional) Failing after 56s 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 50s Details
❌ CI: Optional E2E Tests / E2E cloudflare-flue-send-to-sentry Test (optional) Failing after 1m Details
Successful checks
Check Status
✅ CI: Optional E2E Tests / E2E astro-7 Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E cloudflare-mastra Test (optional) Successful in 59s Details
✅ CI: Optional E2E Tests / E2E cloudflare-pi-durable Test (optional) Successful in 45s Details
✅ CI: Optional E2E Tests / E2E cloudflare-think (ai v6) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E debug-id-sourcemaps Test (optional) Successful in 54s Details
✅ CI: Optional E2E Tests / E2E cloudflare-agent Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E cloudflare-workers-send-to-sentry Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E deno (latest) 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 nextjs-16 (deno) Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E nextjs-15 (latest) Test (optional) Successful in 3m Details
✅ CI: Optional E2E Tests / E2E gen-ai-libraries (cloudflare) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E nextjs-14 (latest) 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 nestjs-12 (latest) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E gen-ai-libraries (latest) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E nextjs-16 (cloudflare, latest) Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E nextjs-16-tunnel (cloudflare) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E nextjs-16 (vinext, bun) Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E nextjs-16 (vinext) Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E nextjs-orpc Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E node-express-send-to-sentry Test (optional) Successful in 3m Details
✅ CI: Optional E2E Tests / E2E node-express-send-to-sentry-static Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E node-express-mcp-v2 Test (optional) Successful in 38s Details
✅ CI: Optional E2E Tests / E2E node-express-mcp-v1 Test (optional) Successful in 43s Details
✅ CI: Optional E2E Tests / E2E node-fastify-6 (tracer provider) Test (optional) Successful in 9m Details
✅ CI: Optional E2E Tests / E2E node-flue Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E node-mastra Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E node-fastify-6 Test (optional) Successful in 9m Details
✅ CI: Optional E2E Tests / E2E node-openai-decisions Test (optional) Successful in 39s Details
✅ CI: Optional E2E Tests / E2E node-openai-decisions (latest) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E node-mastra (latest) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E nuxt-5 Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E node-pi-durable Test (optional) Successful in 58s Details
✅ CI: Optional E2E Tests / E2E nuxt-5 (tunnel-dev) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E node-pi-durable (latest) Test (optional) Successful in 51s Details
✅ CI: Optional E2E Tests / E2E nuxt-5-sourcemaps Test (optional) Successful in 45s Details
✅ CI: Optional E2E Tests / E2E nuxt-5-sourcemaps (client source maps kept) Test (optional) Successful in 9m Details
✅ CI: Optional E2E Tests / E2E nuxt-5-sourcemaps (static / nuxt generate) Test (optional) Successful in 39s Details
✅ CI: Optional E2E Tests / E2E solidstart-2 Test (optional) Successful in 9m Details
✅ CI: Optional E2E Tests / E2E react-router-7-framework-instrumentation Test (optional) Successful in 3m Details
✅ CI: Optional E2E Tests / E2E tanstackstart-react (latest) Test (optional) Successful in 12m Details
✅ CI: Optional E2E Tests / E2E react-send-to-sentry Test (optional) Successful in 11m Details
✅ CI: Optional E2E Tests / E2E vue-3 (no Options API) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E supabase-nextjs Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E tanstackstart-react-sourcemaps Test (optional) Successful in 39s Details
✅ CI: Optional E2E Tests / E2E tanstackstart-react-cloudflare Test (optional) Successful in 52s Details
✅ CI: Optional E2E Tests / E2E astro-7-static Test (optional) Successful in 12m Details
✅ CI: Optional E2E Tests / E2E cloudflare-think Test (optional) Successful in 59s Details

Comment thread packages/core/test/lib/client.test.ts Resolved
Comment thread packages/core/test/lib/client.test.ts Resolved
@andreiborza
andreiborza merged commit 6ffdf10 into develop Nov 6, 2026
506 of 528 checks passed
@andreiborza
andreiborza deleted the ref/lazy-log-metric-flushing branch November 6, 2026 11:13
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.

Client always bundles log/metric flush code

2 participants