Skip to content

Commit a1012c4

Browse files
authored
feat(cf/vercel-edge)!: Align request data collection with v11 defaults (#22850)
⚠️ Needs this PR to be merged first to correctly apply filtering (tests fail otherwise): #22853 Cloudflare no longer gates cookie collection on `sendDefaultPii`. The request data integration now relies exclusively on resolved `dataCollection` settings. Cookies are therefore collected and denylist-filtered by default, while `dataCollection.cookies: false` remains an explicit opt-out. This also removes the obsolete options shim from Vercel Edge’s default integration setup. These transitional paths are no longer needed in v11, where `sendDefaultPii` is being removed. part of (only cloudflare/vercel for now) #21260
1 parent b5380cf commit a1012c4

12 files changed

Lines changed: 83 additions & 17 deletions

File tree

dev-packages/cloudflare-integration-tests/suites/basic/test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ it('Basic error in fetch handler', async ({ signal }) => {
2121
],
2222
},
2323
request: {
24+
cookies: {},
2425
headers: expect.any(Object),
2526
method: 'GET',
2627
url: expect.any(String),

dev-packages/cloudflare-integration-tests/suites/double-instrumentation/test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ it('Only sends one error event when withSentry is called twice', async ({ signal
2121
],
2222
},
2323
request: {
24+
cookies: {},
2425
headers: expect.any(Object),
2526
method: 'GET',
2627
url: expect.any(String),

dev-packages/cloudflare-integration-tests/suites/hono-sdk/test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ it('Hono app captures parametrized errors (Hono SDK)', async ({ signal }) => {
2222
],
2323
},
2424
request: {
25+
cookies: {},
2526
headers: expect.any(Object),
2627
method: 'GET',
2728
url: expect.stringContaining('/error/param-123'),

dev-packages/cloudflare-integration-tests/suites/integrations/http-server/test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ it('Captures JSON request body', async ({ signal }) => {
1010
level: 'info',
1111
message: 'POST JSON request',
1212
request: {
13+
cookies: {},
1314
headers: expect.any(Object),
1415
method: 'POST',
1516
url: expect.stringContaining('/post-json'),
@@ -38,6 +39,7 @@ it('Captures form-urlencoded request body', async ({ signal }) => {
3839
level: 'info',
3940
message: 'POST form request',
4041
request: {
42+
cookies: {},
4143
headers: expect.any(Object),
4244
method: 'POST',
4345
url: expect.stringContaining('/post-form'),
@@ -66,6 +68,7 @@ it('Captures plain text request body', async ({ signal }) => {
6668
level: 'info',
6769
message: 'POST text request',
6870
request: {
71+
cookies: {},
6972
headers: expect.any(Object),
7073
method: 'POST',
7174
url: expect.stringContaining('/post-text'),
@@ -94,6 +97,7 @@ it('Does not capture body for POST without content', async ({ signal }) => {
9497
level: 'info',
9598
message: 'POST no body request',
9699
request: {
100+
cookies: {},
97101
headers: expect.any(Object),
98102
method: 'POST',
99103
url: expect.stringContaining('/post-no-body'),

dev-packages/cloudflare-integration-tests/suites/tracing/dsc-url-source/test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ it('omits the span name from the DSC for url-source spans when tracing is enable
2323
],
2424
},
2525
request: {
26+
cookies: {},
2627
headers: expect.any(Object),
2728
method: 'GET',
2829
url: expect.any(String),

dev-packages/cloudflare-integration-tests/suites/tracing/headers/test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ it('Tracing headers', async ({ signal }) => {
4646
},
4747
],
4848
request: {
49+
cookies: {},
4950
headers: expect.any(Object),
5051
method: 'GET',
5152
url: expect.any(String),

dev-packages/e2e-tests/test-applications/cloudflare-agent/tests/callable.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ test('@callable() methods work correctly with Sentry instrumentAgentWithSentry',
4848
transaction: 'GET /agents/my-agent/user-123',
4949
type: 'transaction',
5050
request: {
51+
cookies: {},
5152
headers: expect.any(Object),
5253
method: 'GET',
5354
url: expect.stringContaining('/agents/my-agent/user-123'),

packages/cloudflare/src/sdk.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,6 @@ function getRegisteredChannelIntegrations(): Integration[] {
4141

4242
/** Get the default integrations for the Cloudflare SDK. */
4343
export function getDefaultIntegrations(options: CloudflareOptions): Integration[] {
44-
// TODO(v11): Drop this transitional gating and let `requestDataIntegration` rely on the resolved
45-
// `dataCollection` defaults directly. Until then, preserve the historical Cloudflare behavior of not
46-
// attaching cookies unless the user explicitly opts in via `sendDefaultPii` or `dataCollection.cookies`.
47-
// eslint-disable-next-line typescript/no-deprecated
48-
const cookiesEnabled = options.sendDefaultPii || options.dataCollection?.cookies != null;
4944
return [
5045
// The Dedupe integration should not be used in workflows because we want to
5146
// capture all step failures, even if they are the same error.
@@ -59,7 +54,7 @@ export function getDefaultIntegrations(options: CloudflareOptions): Integration[
5954
fetchIntegration(),
6055
httpServerIntegration(),
6156
// oxlint-disable-next-line typescript/no-deprecated
62-
requestDataIntegration(cookiesEnabled ? undefined : { include: { cookies: false } }),
57+
requestDataIntegration(),
6358
consoleIntegration(),
6459
// The orchestrion diagnostics-channel subscribers (mysql, pg, …). The
6560
// `@sentry/cloudflare/vite` plugin injects the channels at build time and,

packages/cloudflare/test/request.test.ts

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,31 @@ describe('withSentry', () => {
268268
expect(sentryEvent.sdkProcessingMetadata?.normalizedRequest?.data).toBeUndefined();
269269
});
270270

271+
test('captures cookies with denylist filtering by default', async () => {
272+
let sentryEvent: Event = {};
273+
274+
await wrapRequestHandler(
275+
{
276+
options: {
277+
...MOCK_OPTIONS,
278+
dataCollection: { httpBodies: [] },
279+
beforeSend(event) {
280+
sentryEvent = event;
281+
return null;
282+
},
283+
},
284+
request: new Request('https://example.com', { headers: { cookie: 'foo=bar; session=secret' } }),
285+
context: createMockExecutionContext(),
286+
},
287+
() => {
288+
SentryCore.captureMessage('request body');
289+
return new Response('test');
290+
},
291+
);
292+
293+
expect(sentryEvent.request?.cookies).toEqual({ foo: 'bar', session: '[Filtered]' });
294+
});
295+
271296
test('explicit maxRequestBodySize overrides dataCollection.httpBodies', async () => {
272297
let sentryEvent: Event = {};
273298
const context = createMockExecutionContext();
@@ -299,15 +324,14 @@ describe('withSentry', () => {
299324
expect(sentryEvent.sdkProcessingMetadata?.normalizedRequest?.data).toEqual(JSON.stringify({ key: 'value' }));
300325
});
301326

302-
// TODO(v11): Cookies should be attached (subject to denylist filtering) by default. Until then we keep the
303-
// historical Cloudflare behavior of not attaching cookies unless the user explicitly opts in.
304-
test('does not capture cookies by default', async () => {
327+
test('does not capture cookies when dataCollection.cookies is disabled', async () => {
305328
let sentryEvent: Event = {};
306329

307330
await wrapRequestHandler(
308331
{
309332
options: {
310333
...MOCK_OPTIONS,
334+
dataCollection: { cookies: false },
311335
beforeSend(event) {
312336
sentryEvent = event;
313337
return null;

packages/nextjs/src/edge/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export function init(options: VercelEdgeOptions = {}): void {
6363
);
6464
}
6565

66-
const customDefaultIntegrations = getDefaultIntegrations(options);
66+
const customDefaultIntegrations = getDefaultIntegrations();
6767

6868
// This value is injected at build time, based on the output directory specified in the build config. Though a default
6969
// is set there, we set it here as well, just in case something has gone wrong with the injection.

0 commit comments

Comments
 (0)