Skip to content

fix(core): Explicitly flush log buffer in client.close()#19371

Open
chargome wants to merge 2 commits intodevelopfrom
cg/JS-1726-flush-log-buffer
Open

fix(core): Explicitly flush log buffer in client.close()#19371
chargome wants to merge 2 commits intodevelopfrom
cg/JS-1726-flush-log-buffer

Conversation

@chargome
Copy link
Member

Adds an explicit _INTERNAL_flushLogsBuffer(this) call at the start of the base Client.close() method, before flush(timeout) is called.

Previously, the log buffer flush during close() relied on an indirect event chain: close() → flush() → emit('flush') → setupWeightBasedFlushing handler → _INTERNAL_flushLogsBuffer. While this works, it's fragile and could break if someone refactors the event mechanism. The explicit call ensures logs are always flushed on close regardless of the event wiring.

The call is placed before flush() so the log envelope is queued to the transport before transport.flush(timeout) drains all pending sends. _INTERNAL_flushLogsBuffer safely handles empty buffers (returns early), so there's no overhead when logs are disabled or the buffer is empty.

All platform SDKs (NodeClient, LightNodeClient, DenoClient, BrowserClient, CloudflareClient) ultimately call super.close() which reaches this base implementation, so all runtimes benefit automatically.

closes #19347

@chargome chargome self-assigned this Feb 18, 2026
@linear
Copy link

linear bot commented Feb 18, 2026

@github-actions
Copy link
Contributor

github-actions bot commented Feb 18, 2026

Codecov Results 📊


Generated by Codecov Action

@github-actions
Copy link
Contributor

size-limit report 📦

Path Size % Change Change
@sentry/browser 25.57 kB +0.02% +4 B 🔺
@sentry/browser - with treeshaking flags 24.08 kB +0.03% +5 B 🔺
@sentry/browser (incl. Tracing) 42.37 kB +0.01% +3 B 🔺
@sentry/browser (incl. Tracing, Profiling) 47.04 kB +0.01% +4 B 🔺
@sentry/browser (incl. Tracing, Replay) 81.19 kB +0.01% +5 B 🔺
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 70.81 kB +0.01% +5 B 🔺
@sentry/browser (incl. Tracing, Replay with Canvas) 85.87 kB +0.01% +4 B 🔺
@sentry/browser (incl. Tracing, Replay, Feedback) 98.04 kB +0.01% +4 B 🔺
@sentry/browser (incl. Feedback) 42.3 kB +0.02% +6 B 🔺
@sentry/browser (incl. sendFeedback) 30.24 kB +0.02% +4 B 🔺
@sentry/browser (incl. FeedbackAsync) 35.23 kB +0.02% +5 B 🔺
@sentry/browser (incl. Metrics) 26.75 kB +0.03% +6 B 🔺
@sentry/browser (incl. Logs) 26.89 kB +0.03% +8 B 🔺
@sentry/browser (incl. Metrics & Logs) 27.56 kB +0.03% +6 B 🔺
@sentry/react 27.34 kB +0.02% +5 B 🔺
@sentry/react (incl. Tracing) 44.72 kB +0.01% +4 B 🔺
@sentry/vue 30.02 kB +0.02% +6 B 🔺
@sentry/vue (incl. Tracing) 44.22 kB +0.01% +3 B 🔺
@sentry/svelte 25.59 kB +0.03% +7 B 🔺
CDN Bundle 28.12 kB +0.02% +5 B 🔺
CDN Bundle (incl. Tracing) 43.2 kB +0.01% +2 B 🔺
CDN Bundle (incl. Logs, Metrics) 28.96 kB +0.03% +6 B 🔺
CDN Bundle (incl. Tracing, Logs, Metrics) 44.04 kB +0.01% +4 B 🔺
CDN Bundle (incl. Replay, Logs, Metrics) 68.03 kB +0.01% +4 B 🔺
CDN Bundle (incl. Tracing, Replay) 80.08 kB +0.01% +3 B 🔺
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 80.95 kB +0.01% +3 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback) 85.51 kB +0.01% +5 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 86.4 kB +0.01% +4 B 🔺
CDN Bundle - uncompressed 82.22 kB +0.02% +9 B 🔺
CDN Bundle (incl. Tracing) - uncompressed 127.94 kB +0.01% +9 B 🔺
CDN Bundle (incl. Logs, Metrics) - uncompressed 85.06 kB +0.02% +9 B 🔺
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 130.77 kB +0.01% +9 B 🔺
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 208.72 kB +0.01% +9 B 🔺
CDN Bundle (incl. Tracing, Replay) - uncompressed 244.82 kB +0.01% +9 B 🔺
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 247.64 kB +0.01% +9 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 257.62 kB +0.01% +9 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 260.43 kB +0.01% +9 B 🔺
@sentry/nextjs (client) 47.07 kB +0.02% +5 B 🔺
@sentry/sveltekit (client) 42.82 kB +0.02% +5 B 🔺
@sentry/node-core 52.15 kB +0.03% +12 B 🔺
@sentry/node 166.53 kB +0.01% +10 B 🔺
@sentry/node - without tracing 93.95 kB +0.02% +16 B 🔺
@sentry/aws-serverless 109.46 kB +0.02% +14 B 🔺

View base workflow run

@github-actions
Copy link
Contributor

node-overhead report 🧳

Note: This is a synthetic benchmark with a minimal express app and does not necessarily reflect the real-world performance impact in an application.

Scenario Requests/s % of Baseline Prev. Requests/s Change %
GET Baseline 8,984 - 9,044 -1%
GET With Sentry 1,598 18% 1,596 +0%
GET With Sentry (error only) 5,994 67% 6,140 -2%
POST Baseline 1,197 - 1,189 +1%
POST With Sentry 576 48% 592 -3%
POST With Sentry (error only) 1,039 87% 1,058 -2%
MYSQL Baseline 3,230 - 3,237 -0%
MYSQL With Sentry 444 14% 416 +7%
MYSQL With Sentry (error only) 2,615 81% 2,643 -1%

View base workflow run

@chargome chargome requested a review from Lms24 February 18, 2026 13:51
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.

Flush log buffer in base Client.close()

1 participant

Comments