8000 feat(node): Add `maxIncomingRequestBodySize` (#16225) · getsentry/sentry-javascript@12c90d1 · GitHub
[go: up one dir, main page]

Skip to content

Commit 12c90d1

Browse files
authored
feat(node): Add maxIncomingRequestBodySize (#16225)
Adds `maxIncomingRequestBodySize` to the Node `httpIntegration`. The setting controls the maximum size of HTTP request bodies attached to events. There is the option `maxRequestBodySize` ([docs](https://develop.sentry.dev/sdk/expected-features/#attaching-request-body-in-server-sdks)) in other SDKs, but to be more specific, this is named with `incoming`. 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
1 parent f128046 commit 12c90d1

File tree

13 files changed

+495
-9
lines changed
  • packages/node/src/integrations/http
  • 13 files changed

    +495
    -9
    lines changed

    dev-packages/node-integration-tests/suites/express/with-http/test.ts renamed to dev-packages/node-integration-tests/suites/express/with-http/base/test.ts

    Lines changed: 1 addition & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -1,5 +1,5 @@
    11
    import { afterAll, describe } from 'vitest';
    2-
    import { cleanupChildProcesses, createEsmAndCjsTests } from '../../../utils/runner';
    2+
    import { cleanupChildProcesses, createEsmAndCjsTests } from '../../../../utils/runner';
    33

    44
    describe('express with http import', () => {
    55
    afterAll(() => {
    Original file line numberDiff line numberDiff line change
    @@ -0,0 +1,35 @@
    1+
    // Payload for requests
    2+
    export function generatePayload(sizeInBytes: number): { data: string } {
    3+
    const baseSize = JSON.stringify({ data: '' }).length;
    4+
    const contentLength = sizeInBytes - baseSize;
    5+
    6+
    return { data: 'x'.repeat(contentLength) };
    7+
    }
    8+
    9+
    // Generate the "expected" body string
    10+
    export function generatePayloadString(dataLength: number, truncate?: boolean): string {
    11+
    const prefix = '{"data":"';
    12+
    const suffix = truncate ? '...' : '"}';
    13+
    14+
    const baseStructuralLength = prefix.length + suffix.length;
    15+
    const dataContent = 'x'.repeat(dataLength - baseStructuralLength);
    16+
    17+
    return `${prefix}${dataContent}${suffix}`;
    18+
    }
    19+
    20+
    // Functions for non-ASCII payloads (e.g. emojis)
    21+
    export function generateEmojiPayload(sizeInBytes: number): { data: string } {
    22+
    const baseSize = JSON.stringify({ data: '' }).length;
    23+
    const contentLength = sizeInBytes - baseSize;
    24+
    25+
    return { data: '👍'.repeat(contentLength) };
    26+
    }
    27+
    export function generateEmojiPayloadString(dataLength: number, truncate?: boolean): string {
    28+
    const prefix = '{"data":"';
    29+
    const suffix = truncate ? '...' : '"}';
    30+
    31+
    const baseStructuralLength = suffix.length;
    32+
    const dataContent = '👍'.repeat(dataLength - baseStructuralLength);
    33+
    34+
    return `${prefix}${dataContent}${suffix}`;
    35+
    }
    Original file line numberDiff line numberDiff line change
    @@ -0,0 +1,10 @@
    1+
    import * as Sentry from '@sentry/node';
    2+
    import { loggingTransport } from '@sentry-internal/node-integration-tests';
    3+
    4+
    Sentry.init({
    5+
    dsn: 'https://public@dsn.ingest.sentry.io/1337',
    6+
    release: '1.0',
    7+
    tracesSampleRate: 1.0,
    8+
    transport: loggingTransport,
    9+
    integrations: [Sentry.httpIntegration({ maxIncomingRequestBodySize: 'always' })],
    10+
    });
    Original file line numberDiff line numberDiff line change
    @@ -0,0 +1,9 @@
    1+
    import * as Sentry from '@sentry/node';
    2+
    import { loggingTransport } from '@sentry-internal/node-integration-tests';
    3+
    4+
    Sentry.init({
    5+
    dsn: 'https://public@dsn.ingest.sentry.io/1337',
    6+
    release: '1.0',
    7+
    tracesSampleRate: 1.0,
    8+
    transport: loggingTransport,
    9+
    });
    Original file line numberDiff line numberDiff line change
    @@ -0,0 +1,10 @@
    1+
    import * as Sentry from '@sentry/node';
    2+
    import { loggingTransport } from '@sentry-internal/node-integration-tests';
    3+
    4+
    Sentry.init({
    5+
    dsn: 'https://public@dsn.ingest.sentry.io/1337',
    6+
    release: '1.0',
    7+
    tracesSampleRate: 1.0,
    8+
    transport: loggingTransport,
    9+
    integrations: [Sentry.httpIntegration({ maxIncomingRequestBodySize: 'medium' })],
    10+
    });
    Original file line numberDiff line numberDiff line change
    @@ -0,0 +1,15 @@
    1+
    import * as Sentry from '@sentry/node';
    2+
    import { loggingTransport } from '@sentry-internal/node-integration-tests';
    3+
    4+
    Sentry.init({
    5+
    dsn: 'https://public@dsn.ingest.sentry.io/1337',
    6+
    release: '1.0',
    7+
    tracesSampleRate: 1.0,
    8+
    transport: loggingTransport,
    9+
    integrations: [
    10+
    Sentry.httpIntegration({
    11+
    maxIncomingRequestBodySize: 'none',
    12+
    ignoreIncomingRequestBody: url => url.includes('/ignore-request-body'),
    13+
    }),
    14+
    ],
    15+
    });
    Original file line numberDiff line numberDiff line change
    @@ -0,0 +1,10 @@
    1+
    import * as Sentry from '@sentry/node';
    2+
    import { loggingTransport } from '@sentry-internal/node-integration-tests';
    3+
    4+
    Sentry.init({
    5+
    dsn: 'https://public@dsn.ingest.sentry.io/1337',
    6+
    release: '1.0',
    7+
    tracesSampleRate: 1.0,
    8+
    transport: loggingTransport,
    9+
    integrations: [Sentry.httpIntegration({ maxIncomingRequestBodySize: 'small' })],
    10+
    });
    Lines changed: 32 additions & 0 deletions
    Original file line numberDiff line numberDiff line change
    @@ -0,0 +1,32 @@
    1+
    import * as Sentry from '@sentry/node';
    2+
    import { startExpressServerAndSendPortToRunner } from '@sentry-internal/node-integration-tests';
    3+
    import bodyParser from 'body-parser';
    4+
    import express from 'express';
    5+
    6+
    const app = express();
    7+
    8+
    // Increase limit for JSON parsing
    9+
    app.use(bodyParser.json({ limit: '3mb' }));
    10+
    app.use(express.json({ limit: '3mb' }));
    11+
    12+
    app.post('/test-body-size', (req, res) => {
    13+
    const receivedSize = JSON.stringify(req.body).length;
    14+
    res.json({
    15+
    success: true,
    16+
    receivedSize,
    17+
    message: 'Payload processed successfully',
    18+
    });
    19+
    });
    20+
    21+
    app.post('/ignore-request-body', (req, res) => {
    22+
    const receivedSize = JSON.stringify(req.body).length;
    23+
    res.json({
    24+
    success: true,
    25+
    receivedSize,
    26+
    message: 'Payload processed successfully',
    27+
    });
    28+
    });
    29+
    30+
    Sentry.setupExpressErrorHandler(app);
    31+
    32+
    startExpressServerAndSendPortToRunner(app);

    0 commit comments

    Comments
     (0)
    0