Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save isaacs/9897e925123d1ce714b4f20d2a589077 to your computer and use it in GitHub Desktop.

Select an option

Save isaacs/9897e925123d1ce714b4f20d2a589077 to your computer and use it in GitHub Desktop.
From 80beae84ce774d48d94ccafd4bdd78e823080f11 Mon Sep 17 00:00:00 2001
From: isaacs <[email protected]>
Date: Wed, 29 Jul 2026 09:18:20 -0700
Subject: [PATCH] fixup! feat(core)!: Gate incoming HTTP body capture on
`dataCollection.httpBodies`
---
.../instrument-datacollection.mjs | 11 +++++++
.../maxIncomingRequestBodySize/test.ts | 32 +++++++++++++++++--
packages/cloudflare/test/request.test.ts | 32 ++++++++++++++++++-
3 files changed, 72 insertions(+), 3 deletions(-)
create mode 100644 dev-packages/node-integration-tests/suites/express/with-http/maxIncomingRequestBodySize/instrument-datacollection.mjs
diff --git a/dev-packages/node-integration-tests/suites/express/with-http/maxIncomingRequestBodySize/instrument-datacollection.mjs b/dev-packages/node-integration-tests/suites/express/with-http/maxIncomingRequestBodySize/instrument-datacollection.mjs
new file mode 100644
index 0000000000..5d995e640e
--- /dev/null
+++ b/dev-packages/node-integration-tests/suites/express/with-http/maxIncomingRequestBodySize/instrument-datacollection.mjs
@@ -0,0 +1,11 @@
+import * as Sentry from '@sentry/node';
+import { loggingTransport } from '@sentry-internal/node-integration-tests';
+
+Sentry.init({
+ traceLifecycle: 'static',
+ dsn: 'https://[email protected]/1337',
+ release: '1.0',
+ tracesSampleRate: 1.0,
+ transport: loggingTransport,
+ dataCollection: { httpBodies: ['incomingRequest'] },
+});
diff --git a/dev-packages/node-integration-tests/suites/express/with-http/maxIncomingRequestBodySize/test.ts b/dev-packages/node-integration-tests/suites/express/with-http/maxIncomingRequestBodySize/test.ts
index 84f0a5ee21..a52f0225fe 100644
--- a/dev-packages/node-integration-tests/suites/express/with-http/maxIncomingRequestBodySize/test.ts
+++ b/dev-packages/node-integration-tests/suites/express/with-http/maxIncomingRequestBodySize/test.ts
@@ -18,7 +18,35 @@ describe('express with httpIntegration and not defined maxIncomingRequestBodySiz
});
createEsmAndCjsTests(__dirname, 'scenario.mjs', 'instrument-default.mjs', (createRunner, test) => {
- test('captures medium request bodies with default setting (medium)', async () => {
+ test('does not capture request bodies by default (dataCollection.httpBodies gates it)', async () => {
+ const runner = createRunner()
+ .expect({
+ transaction: {
+ transaction: 'POST /test-body-size',
+ request: expect.not.objectContaining({
+ data: expect.any(String),
+ }),
+ },
+ })
+ .start();
+
+ await runner.makeRequest('post', '/test-body-size', {
+ headers: { 'Content-Type': 'application/json' },
+ data: JSON.stringify(generatePayload(MAX_MEDIUM)),
+ });
+
+ await runner.completed();
+ });
+ });
+});
+
+describe("express with httpIntegration and dataCollection.httpBodies: ['incomingRequest']", () => {
+ afterAll(() => {
+ cleanupChildProcesses();
+ });
+
+ createEsmAndCjsTests(__dirname, 'scenario.mjs', 'instrument-datacollection.mjs', (createRunner, test) => {
+ test('captures medium request bodies when incomingRequest is enabled', async () => {
const runner = createRunner()
.expect({
transaction: {
@@ -38,7 +66,7 @@ describe('express with httpIntegration and not defined maxIncomingRequestBodySiz
await runner.completed();
});
- test('truncates large request bodies with default setting (medium)', async () => {
+ test('truncates large request bodies at medium size when incomingRequest is enabled', async () => {
const runner = createRunner()
.expect({
transaction: {
diff --git a/packages/cloudflare/test/request.test.ts b/packages/cloudflare/test/request.test.ts
index 375efa4b6d..9726727e75 100644
--- a/packages/cloudflare/test/request.test.ts
+++ b/packages/cloudflare/test/request.test.ts
@@ -207,7 +207,7 @@ describe('withSentry', () => {
expect(sentryEvent.contexts?.culture).toEqual({ timezone: 'UTC' });
});
- test('captures request body by default (all body types included by default)', async () => {
+ test('does not capture request body by default (dataCollection.httpBodies gates it)', async () => {
let sentryEvent: Event = {};
const context = createMockExecutionContext();
@@ -233,6 +233,36 @@ describe('withSentry', () => {
},
);
+ expect(sentryEvent.sdkProcessingMetadata?.normalizedRequest?.data).toBeUndefined();
+ });
+
+ test('captures request body when dataCollection.httpBodies includes incomingRequest', async () => {
+ let sentryEvent: Event = {};
+ const context = createMockExecutionContext();
+
+ await wrapRequestHandler(
+ {
+ options: {
+ ...MOCK_OPTIONS,
+ dataCollection: { httpBodies: ['incomingRequest'] },
+ beforeSend(event) {
+ sentryEvent = event;
+ return null;
+ },
+ },
+ request: new Request('https://example.com', {
+ method: 'POST',
+ headers: { 'content-type': 'application/json' },
+ body: JSON.stringify({ username: 'test', data: 'value' }),
+ }),
+ context,
+ },
+ () => {
+ SentryCore.captureMessage('request body');
+ return new Response('test');
+ },
+ );
+
expect(sentryEvent.sdkProcessingMetadata?.normalizedRequest?.data).toEqual(
JSON.stringify({ username: 'test', data: 'value' }),
);
--
2.50.1 (Apple Git-155)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment