Skip to content

fix(node): Make body capturing more robust #16105

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Apr 23, 2025
Merged

Conversation

lforst
Copy link
Member

@lforst lforst commented Apr 22, 2025

I have a hunch that not all frameworks call req.on('end') but may only do req.on('close') or whatever else and this is why we are not reliably capturing bodies.

It should be safe to attach a req.on('end') handler, as that doesn't change any semantics AFAIK.

Fixes #16090

@lforst lforst requested a review from mydea April 22, 2025 10:19
Copy link
Contributor

github-actions bot commented Apr 22, 2025

size-limit report 📦

Path Size % Change Change
@sentry/browser 23.28 KB - -
@sentry/browser - with treeshaking flags 23.12 KB - -
@sentry/browser (incl. Tracing) 36.99 KB - -
@sentry/browser (incl. Tracing, Replay) 74.17 KB - -
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 67.55 KB - -
@sentry/browser (incl. Tracing, Replay with Canvas) 78.83 KB - -
@sentry/browser (incl. Tracing, Replay, Feedback) 90.65 KB - -
@sentry/browser (incl. Feedback) 39.68 KB - -
@sentry/browser (incl. sendFeedback) 27.9 KB - -
@sentry/browser (incl. FeedbackAsync) 32.67 KB - -
@sentry/react 25.09 KB - -
@sentry/react (incl. Tracing) 38.91 KB - -
@sentry/vue 27.51 KB - -
@sentry/vue (incl. Tracing) 38.71 KB - -
@sentry/svelte 23.32 KB - -
CDN Bundle 24.51 KB - -
CDN Bundle (incl. Tracing) 36.98 KB - -
CDN Bundle (incl. Tracing, Replay) 72.03 KB - -
CDN Bundle (incl. Tracing, Replay, Feedback) 77.18 KB - -
CDN Bundle - uncompressed 71.47 KB - -
CDN Bundle (incl. Tracing) - uncompressed 109.34 KB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 220.63 KB - -
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 233.16 KB - -
@sentry/nextjs (client) 40.53 KB - -
@sentry/sveltekit (client) 37.44 KB - -
@sentry/node 143.37 KB -0.01% -2 B 🔽
@sentry/node - without tracing 96.51 KB -0.01% -8 B 🔽
@sentry/aws-serverless 120.83 KB -0.01% -9 B 🔽

View base workflow run


if (bodyByteLength < MAX_BODY_BYTE_LENGTH) {
chunks.push(bufferifiedChunk);
bodyByteLength += bufferifiedChunk.length;
Copy link
Member

Choose a reason for hiding this comment

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

should we use length or byteLength here? 🤔

}
} catch {
// noop
Copy link
Member

Choose a reason for hiding this comment

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

Let's add a debug logger message here?

@lforst lforst requested a review from mydea April 22, 2025 13:49
Copy link
Member

@mydea mydea left a comment

Choose a reason for hiding this comment

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

there is still one small comment open to add a debug log on error case, but already approving this, this is great!

@lforst
Copy link
Member Author

lforst commented Apr 23, 2025

Ah thanks, forgot to push that change!

@lforst lforst enabled auto-merge (squash) April 23, 2025 09:06
@lforst lforst merged commit 88ba26b into develop Apr 23, 2025
157 checks passed
@lforst lforst deleted the lforst-body-capturing branch April 23, 2025 09:20
onurtemizkan pushed a commit that referenced this pull request Apr 24, 2025
I have a hunch that not all frameworks call `req.on('end')` but may only
do `req.on('close')` or whatever else and this is why we are not
reliably capturing bodies.

It should be safe to attach a `req.on('end')` handler, as that doesn't
change any semantics AFAIK.

Fixes #16090

---------

Co-authored-by: Francesco Gringl-Novy <[email protected]>
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.

[fastify 4] Request body is not captured with fastify integration
2 participants