Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@andreiborza
Copy link
Member

@andreiborza andreiborza commented Nov 14, 2025

Looks like we swallowed the log that triggers a flush when MAX_LOG_BUFFER_SIZE is surpassed.

Test demonstrating issue: e3a8e2f
Fix: ba24997

v10 equivalent: #18207

Comment on lines 245 to 254
// Add one more to trigger flush
_INTERNAL_captureLog({ level: 'info', message: 'trigger flush' }, client, undefined);

expect(_INTERNAL_getLogBuffer(client)).toEqual([]);
// After flushing the 100 logs, the new log starts a fresh buffer with 1 item
const buffer = _INTERNAL_getLogBuffer(client);
expect(buffer).toHaveLength(1);
expect(buffer?.[0]?.body).toBe('trigger flush');
});

it('does not flush logs buffer when it is empty', () => {
Copy link

Choose a reason for hiding this comment

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

Bug: New logs are silently discarded when the log buffer reaches its maximum size and triggers a flush.
Severity: CRITICAL | Confidence: 1.00

🔍 Detailed Analysis

When the log buffer reaches MAX_LOG_BUFFER_SIZE and a new log is added, the system incorrectly flushes the old buffer before the new log is fully processed. Specifically, _INTERNAL_flushLogsBuffer is called with the logBuffer (100 items) before the serializedLog is properly accounted for. Subsequently, _getBufferMap().set(client, []) clears the buffer, overwriting the newly updated buffer that contained the 101st log. This results in the most recent log being silently discarded.

💡 Suggested Fix

Modify the logic to either check the new buffer size before flushing or ensure the new log is preserved after the buffer is cleared by the flush operation.

🤖 Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.

Location: packages/core/test/lib/logs/exports.test.ts#L245-L254

Potential issue: When the log buffer reaches `MAX_LOG_BUFFER_SIZE` and a new log is
added, the system incorrectly flushes the old buffer before the new log is fully
processed. Specifically, `_INTERNAL_flushLogsBuffer` is called with the `logBuffer` (100
items) before the `serializedLog` is properly accounted for. Subsequently,
`_getBufferMap().set(client, [])` clears the buffer, overwriting the newly updated
buffer that contained the 101st log. This results in the most recent log being silently
discarded.

Did we get this right? 👍 / 👎 to inform future reviews.

Reference_id: 2693436

Copy link
Member Author

Choose a reason for hiding this comment

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

Indeed, that's what this PR fixes with ba24997.

@github-actions
Copy link
Contributor

github-actions bot commented Nov 14, 2025

size-limit report 📦

Path Size % Change Change
@sentry/browser 23.79 kB added added
@sentry/browser - with treeshaking flags 22.36 kB added added
@sentry/browser (incl. Tracing) 39.66 kB added added
@sentry/browser (incl. Tracing, Replay) 77.93 kB added added
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 67.71 kB added added
@sentry/browser (incl. Tracing, Replay with Canvas) 82.63 kB added added
@sentry/browser (incl. Tracing, Replay, Feedback) 94.76 kB added added
@sentry/browser (incl. Feedback) 40.48 kB added added
@sentry/browser (incl. sendFeedback) 28.48 kB added added
@sentry/browser (incl. FeedbackAsync) 33.37 kB added added
@sentry/react 25.55 kB added added
@sentry/react (incl. Tracing) 41.62 kB added added
@sentry/vue 28.24 kB added added
@sentry/vue (incl. Tracing) 41.45 kB added added
@sentry/svelte 23.81 kB added added
CDN Bundle 25.18 kB added added
CDN Bundle (incl. Tracing) 39.42 kB added added
CDN Bundle (incl. Tracing, Replay) 75.55 kB added added
CDN Bundle (incl. Tracing, Replay, Feedback) 81.02 kB added added
CDN Bundle - uncompressed 73.45 kB added added
CDN Bundle (incl. Tracing) - uncompressed 116.86 kB added added
CDN Bundle (incl. Tracing, Replay) - uncompressed 231.75 kB added added
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 244.56 kB added added
@sentry/nextjs (client) 43.66 kB added added
@sentry/sveltekit (client) 40.08 kB added added
@sentry/node 169.37 kB added added
@sentry/node - without tracing 100.51 kB added added
@sentry/aws-serverless 128.67 kB added added

View base workflow run

Copy link
Member

@JPeer264 JPeer264 left a comment

Choose a reason for hiding this comment

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

LGTM. Nice catch

andreiborza added a commit that referenced this pull request Nov 17, 2025
…18207)

Looks like we swallowed the log that triggers a flush when
`MAX_LOG_BUFFER_SIZE` is surpassed.

Test demonstrating issue:
[5697b7d](5697b7d)
Fix:
[f7a4d8b](f7a4d8b)

Related metrics pr: #18212
v9 backport: #18213
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.

3 participants