Skip to content

fix(browser): Flush telemetry when page is hidden#21862

Merged
Lms24 merged 1 commit into
developfrom
lms/fix-browser-flush-on-visibilitychange
Jul 1, 2026
Merged

fix(browser): Flush telemetry when page is hidden#21862
Lms24 merged 1 commit into
developfrom
lms/fix-browser-flush-on-visibilitychange

Conversation

@Lms24

@Lms24 Lms24 commented Jun 30, 2026

Copy link
Copy Markdown
Member

So far, we only flushed logs, metrics and client reports when the page is hidden (visibilitychange: hidden). This PR generalizes the flushing behaviour to call client.flush(), which in turn flushes all our telemetry. Specifically spans (and any requests pending in the transport) which previously were unaffected. Logs and metrics will continue to be flushed because they already listen to client.on('flush'), similarly to the span buffer. I think think this should be a fair change and reduces some bundle size on top :)

Came up while investigating partially sent traces when span streaming is enabled (e.g. child spans already sent but no pageload span).

ref #21805

@github-actions

Copy link
Copy Markdown
Contributor

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.59 kB -0.11% -28 B 🔽
@sentry/browser - with treeshaking flags 26.03 kB -0.1% -26 B 🔽
@sentry/browser (incl. Tracing) 46.05 kB -0.06% -26 B 🔽
@sentry/browser (incl. Tracing + Span Streaming) 47.79 kB -0.06% -28 B 🔽
@sentry/browser (incl. Tracing, Profiling) 50.81 kB -0.05% -24 B 🔽
@sentry/browser (incl. Tracing, Replay) 85.28 kB -0.03% -25 B 🔽
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 74.89 kB -0.04% -27 B 🔽
@sentry/browser (incl. Tracing, Replay with Canvas) 89.97 kB -0.03% -22 B 🔽
@sentry/browser (incl. Tracing, Replay, Feedback) 102.64 kB -0.03% -26 B 🔽
@sentry/browser (incl. Feedback) 44.77 kB -0.07% -30 B 🔽
@sentry/browser (incl. sendFeedback) 32.39 kB -0.09% -29 B 🔽
@sentry/browser (incl. FeedbackAsync) 37.52 kB -0.08% -28 B 🔽
@sentry/browser (incl. Metrics) 28.67 kB -0.05% -14 B 🔽
@sentry/browser (incl. Logs) 28.91 kB -0.09% -24 B 🔽
@sentry/browser (incl. Metrics & Logs) 29.6 kB -0.07% -18 B 🔽
@sentry/react 29.38 kB -0.11% -30 B 🔽
@sentry/react (incl. Tracing) 48.35 kB -0.07% -30 B 🔽
@sentry/vue 32.82 kB -0.09% -27 B 🔽
@sentry/vue (incl. Tracing) 47.91 kB -0.06% -25 B 🔽
@sentry/svelte 27.61 kB -0.11% -29 B 🔽
CDN Bundle 30 kB -0.09% -25 B 🔽
CDN Bundle (incl. Tracing) 47.98 kB -0.08% -36 B 🔽
CDN Bundle (incl. Logs, Metrics) 31.57 kB -0.06% -18 B 🔽
CDN Bundle (incl. Tracing, Logs, Metrics) 49.32 kB -0.07% -32 B 🔽
CDN Bundle (incl. Replay, Logs, Metrics) 70.77 kB -0.03% -17 B 🔽
CDN Bundle (incl. Tracing, Replay) 85.48 kB -0.04% -29 B 🔽
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 86.76 kB -0.04% -30 B 🔽
CDN Bundle (incl. Tracing, Replay, Feedback) 91.29 kB -0.03% -24 B 🔽
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 92.54 kB -0.03% -23 B 🔽
CDN Bundle - uncompressed 89.35 kB -0.08% -70 B 🔽
CDN Bundle (incl. Tracing) - uncompressed 145.28 kB -0.05% -70 B 🔽
CDN Bundle (incl. Logs, Metrics) - uncompressed 94.05 kB -0.08% -70 B 🔽
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 149.25 kB -0.05% -70 B 🔽
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 218.59 kB -0.04% -70 B 🔽
CDN Bundle (incl. Tracing, Replay) - uncompressed 264.29 kB -0.03% -70 B 🔽
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 268.25 kB -0.03% -70 B 🔽
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 277.99 kB -0.03% -70 B 🔽
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 281.94 kB -0.03% -70 B 🔽
@sentry/nextjs (client) 50.73 kB -0.06% -29 B 🔽
@sentry/sveltekit (client) 46.44 kB -0.05% -22 B 🔽
@sentry/core/server 77.75 kB - -
@sentry/core/browser 64.06 kB - -
@sentry/node-core 61.47 kB +0.01% +1 B 🔺
@sentry/node 122.82 kB -0.01% -1 B 🔽
@sentry/node/import (ESM hook with diagnostics-channel injection) 69.95 kB - -
@sentry/node/light 50.45 kB -0.01% -1 B 🔽
@sentry/node - without tracing 73.2 kB -0.01% -1 B 🔽
@sentry/aws-serverless 84.09 kB -0.01% -1 B 🔽
@sentry/cloudflare (withSentry) - minified 180.62 kB - -
@sentry/cloudflare (withSentry) 446.93 kB - -

View base workflow run

@Lms24 Lms24 self-assigned this Jun 30, 2026
@Lms24 Lms24 marked this pull request as ready for review July 1, 2026 07:27
@Lms24 Lms24 requested a review from a team as a code owner July 1, 2026 07:27
@Lms24 Lms24 requested review from chargome, logaretm and mydea and removed request for a team July 1, 2026 07:27

@chargome chargome left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nice!

@Lms24 Lms24 merged commit 7af75a9 into develop Jul 1, 2026
205 checks passed
@Lms24 Lms24 deleted the lms/fix-browser-flush-on-visibilitychange branch July 1, 2026 09:50
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.

2 participants