Skip to content

feat(node): Add maxRequestBodySize #16225

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

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open

Conversation

s1gr1d
Copy link
Member

@s1gr1d s1gr1d commented May 7, 2025

Adds maxRequestBodySize to the Node httpIntegration.
The setting controls the maximum size of HTTP request bodies attached to events.

Available options:

  • 'none': No request bodies will be attached
  • 'small': Request bodies up to 1,000 bytes will be attached
  • 'medium': Request bodies up to 10,000 bytes will be attached (default)
  • 'always': Request bodies will always be attached (up to 1 MB)

closes #16179

@s1gr1d s1gr1d requested review from chargome and Lms24 May 7, 2025 17:16
@s1gr1d s1gr1d force-pushed the sig/maxRequestBodySize branch from 560976f to 7a21af7 Compare May 7, 2025 17:17
@s1gr1d s1gr1d requested a review from mydea May 7, 2025 17:18
Copy link
Contributor

github-actions bot commented May 7, 2025

size-limit report 📦

Path Size % Change Change
@sentry/browser 23.35 KB - -
@sentry/browser - with treeshaking flags 23.19 KB - -
@sentry/browser (incl. Tracing) 37.25 KB - -
@sentry/browser (incl. Tracing, Replay) 74.47 KB - -
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 68.34 KB - -
@sentry/browser (incl. Tracing, Replay with Canvas) 79.12 KB - -
@sentry/browser (incl. Tracing, Replay, Feedback) 90.93 KB - -
@sentry/browser (incl. Feedback) 39.75 KB - -
@sentry/browser (incl. sendFeedback) 27.98 KB - -
@sentry/browser (incl. FeedbackAsync) 32.74 KB - -
@sentry/react 25.16 KB - -
@sentry/react (incl. Tracing) 39.24 KB - -
@sentry/vue 27.63 KB - -
@sentry/vue (incl. Tracing) 39.01 KB - -
@sentry/svelte 23.38 KB - -
CDN Bundle 24.55 KB - -
CDN Bundle (incl. Tracing) 37.29 KB - -
CDN Bundle (incl. Tracing, Replay) 72.33 KB - -
CDN Bundle (incl. Tracing, Replay, Feedback) 77.64 KB - -
CDN Bundle - uncompressed 71.62 KB - -
CDN Bundle (incl. Tracing) - uncompressed 110.34 KB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 221.63 KB - -
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 234.15 KB - -
@sentry/nextjs (client) 40.84 KB - -
@sentry/sveltekit (client) 37.73 KB - -
@sentry/node 151.44 KB +0.05% +77 B 🔺
@sentry/node - without tracing 95.85 KB +0.08% +78 B 🔺
@sentry/aws-serverless 120.25 KB +0.08% +89 B 🔺

View base workflow run

*
* @default 'medium'
*/
maxRequestBodySize?: 'none' | 'small' | 'medium' | 'always';
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 rename this to maxIncomingRequestBodySize? It is not clear right now that this only applies to incoming requests, not outgoing ones 😅

Copy link
Member Author

Choose a reason for hiding this comment

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

I got the name from the general Sentry docs: https://develop.sentry.dev/sdk/expected-features/#attaching-request-body-in-server-sdks

To be uniform with other SDKs, it would be beneficial to keep the name, but I agree that it would be clearer with incoming. At least, the information is available in the JSDoc 😅

Copy link
Member

Choose a reason for hiding this comment

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

we don't need to have the same name, if we think something else is better :) maybe you could also check with other sdk folks, if this also applies to outgoing requests in other implementations or just to incoming?

function patchRequestToCaptureBody(
req: http.IncomingMessage,
isolationScope: Scope,
maxRequestBodySize: 'none' | 'small' | 'medium' | 'always',
Copy link
Member

Choose a reason for hiding this comment

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

l: We could actually type this to omit none as allowed value, and then avoid the further check in here, as we actually guard agains this already before calling this?

try {
// eslint-disable-next-line @typescript-eslint/unbound-method
req.on = new Proxy(req.on, {
apply: (target, thisArg, args: Parameters<typeof req.on>) => {
const [event, listener, ...restArgs] = args;

if (event === 'data') {
DEBUG_BUILD && logger.log(INSTRUMENTATION_NAME, 'Handling request.on("data")');
if (DEBUG_BUILD) {
logger.log(INSTRUMENTATION_NAME, 'Handling request.on("data")');
Copy link
Member

Choose a reason for hiding this comment

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

l: Let's combine these into a single log line, e.g. Handling request.on("data") with maximum request body size ...

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.

[Node] Add maxRequestBodySize to SentryHttpIntegration
2 participants