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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { afterAll, describe } from 'vitest';
import { cleanupChildProcesses, createEsmAndCjsTests } from '../../../utils/runner';
import { cleanupChildProcesses, createEsmAndCjsTests } from '../../../../utils/runner';

describe('express with http import', () => {
afterAll(() => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Payload for requests
export function generatePayload(sizeInBytes: number): { data: string } {
const baseSize = JSON.stringify({ data: '' }).length;
const contentLength = sizeInBytes - baseSize;

return { data: 'x'.repeat(contentLength) };
}

// Generate the "expected" body string
export function generatePayloadString(dataLength: number, truncate?: boolean): string {
const prefix = '{"data":"';
const suffix = truncate ? '...' : '"}';

const baseStructuralLength = prefix.length + suffix.length;
const dataContent = 'x'.repeat(dataLength - baseStructuralLength);

return `${prefix}${dataContent}${suffix}`;
}

// Functions for non-ASCII payloads (e.g. emojis)
export function generateEmojiPayload(sizeInBytes: number): { data: string } {
const baseSize = JSON.stringify({ data: '' }).length;
const contentLength = sizeInBytes - baseSize;

return { data: '👍'.repeat(contentLength) };
}
export function generateEmojiPayloadString(dataLength: number, truncate?: boolean): string {
const prefix = '{"data":"';
const suffix = truncate ? '...' : '"}';

const baseStructuralLength = suffix.length;
const dataContent = '👍'.repeat(dataLength - baseStructuralLength);

return `${prefix}${dataContent}${suffix}`;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import * as Sentry from '@sentry/node';
import { loggingTransport } from '@sentry-internal/node-integration-tests';

Sentry.init({
dsn: 'https://[email protected]/1337',
release: '1.0',
tracesSampleRate: 1.0,
transport: loggingTransport,
integrations: [Sentry.httpIntegration({ maxRequestBodySize: 'always' })],
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import * as Sentry from '@sentry/node';
import { loggingTransport } from '@sentry-internal/node-integration-tests';

Sentry.init({
dsn: 'https://[email protected]/1337',
release: '1.0',
tracesSampleRate: 1.0,
transport: loggingTransport,
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import * as Sentry from '@sentry/node';
import { loggingTransport } from '@sentry-internal/node-integration-tests';

Sentry.init({
dsn: 'https://[email protected]/1337',
release: '1.0',
tracesSampleRate: 1.0,
transport: loggingTransport,
integrations: [Sentry.httpIntegration({ maxRequestBodySize: 'medium' })],
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import * as Sentry from '@sentry/node';
import { loggingTransport } from '@sentry-internal/node-integration-tests';

Sentry.init({
dsn: 'https://[email protected]/1337',
release: '1.0',
tracesSampleRate: 1.0,
transport: loggingTransport,
integrations: [
Sentry.httpIntegration({
maxRequestBodySize: 'none',
ignoreIncomingRequestBody: url => url.includes('/ignore-request-body'),
}),
],
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import * as Sentry from '@sentry/node';
import { loggingTransport } from '@sentry-internal/node-integration-tests';

Sentry.init({
dsn: 'https://[email protected]/1337',
release: '1.0',
tracesSampleRate: 1.0,
transport: loggingTransport,
integrations: [Sentry.httpIntegration({ maxRequestBodySize: 'small' })],
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import * as Sentry from '@sentry/node';
import { startExpressServerAndSendPortToRunner } from '@sentry-internal/node-integration-tests';
import bodyParser from 'body-parser';
import express from 'express';

const app = express();

// Increase limit for JSON parsing
app.use(bodyParser.json({ limit: '3mb' }));
app.use(express.json({ limit: '3mb' }));

app.post('/test-body-size', (req, res) => {
const receivedSize = JSON.stringify(req.body).length;
res.json({
success: true,
receivedSize,
message: 'Payload processed successfully',
});
});

app.post('/ignore-request-body', (req, res) => {
const receivedSize = JSON.stringify(req.body).length;
res.json({
success: true,
receivedSize,
message: 'Payload processed successfully',
});
});

Sentry.setupExpressErrorHandler(app);

startExpressServerAndSendPortToRunner(app);
Loading