Skip to content

Commit e751eeb

Browse files
authored
feat: Migrate sendDefaultPii in nitro, nuxt, sveltekit, astro to dataCollection (#21217)
Closes #20936
1 parent c6deebc commit e751eeb

6 files changed

Lines changed: 33 additions & 8 deletions

File tree

‎packages/astro/src/server/middleware.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ async function instrumentRequestStartHttpServerSpan(
221221
url: stripUrlQueryAndFragment(ctx.url.href),
222222
...httpHeadersToSpanAttributes(
223223
winterCGHeadersToDict(request.headers),
224-
getClient()?.getOptions().sendDefaultPii ?? false,
224+
getClient()?.getDataCollectionOptions() ?? false,
225225
),
226226
};
227227

‎packages/astro/test/server/middleware.test.ts‎

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,22 @@ describe('sentryMiddleware', () => {
5454
} as any;
5555
});
5656
vi.spyOn(SentryNode, 'getActiveSpan').mockImplementation(getSpanMock);
57-
vi.spyOn(SentryNode, 'getClient').mockImplementation(() => ({ getOptions: () => ({}) }) as Client);
57+
vi.spyOn(SentryNode, 'getClient').mockImplementation(
58+
() =>
59+
({
60+
getOptions: () => ({}),
61+
getDataCollectionOptions: () => ({
62+
userInfo: false,
63+
cookies: true,
64+
httpHeaders: { request: true, response: true },
65+
httpBodies: [],
66+
queryParams: true,
67+
genAI: { inputs: false, outputs: false },
68+
stackFrameVariables: true,
69+
frameContextLines: 5,
70+
}),
71+
}) as unknown as Client,
72+
);
5873
vi.spyOn(SentryNode, 'getTraceMetaTags').mockImplementation(
5974
() => `
6075
<meta name="sentry-trace" content="123">

‎packages/nitro/src/runtime/hooks/captureTracingEvents.ts‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,10 +160,9 @@ function setupSrvxTracingChannels(): void {
160160
method: data.request.method,
161161
});
162162

163-
const sendDefaultPii = getClient()?.getOptions().sendDefaultPii ?? false;
164163
const headerAttributes = httpHeadersToSpanAttributes(
165164
Object.fromEntries(data.request.headers.entries()),
166-
sendDefaultPii,
165+
getClient()?.getDataCollectionOptions() ?? false,
167166
);
168167

169168
return startSpanManual(

‎packages/nuxt/src/runtime/hooks/wrapMiddlewareHandler.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ function getSpanAttributes(
201201
headers = Object.fromEntries(eventH3v2?.req.headers.entries());
202202
}
203203

204-
const headerAttributes = httpHeadersToSpanAttributes(headers, getClient()?.getOptions().sendDefaultPii ?? false);
204+
const headerAttributes = httpHeadersToSpanAttributes(headers, getClient()?.getDataCollectionOptions() ?? false);
205205

206206
// Merge header attributes with existing attributes
207207
Object.assign(attributes, headerAttributes);

‎packages/nuxt/test/runtime/hooks/wrapMiddlewareHandler.test.ts‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,18 @@ describe('wrapMiddlewareHandlerWithSentry', () => {
4040

4141
// Setup minimal required mocks
4242
(SentryCore.startSpan as any).mockImplementation((_config: any, callback: any) => callback(mockSpan));
43-
(SentryCore.getClient as any).mockReturnValue({ getOptions: () => ({ sendDefaultPii: false }) });
43+
(SentryCore.getClient as any).mockReturnValue({
44+
getDataCollectionOptions: () => ({
45+
userInfo: false,
46+
cookies: true,
47+
httpHeaders: { request: true, response: true },
48+
httpBodies: [],
49+
queryParams: true,
50+
genAI: { inputs: false, outputs: false },
51+
stackFrameVariables: true,
52+
frameContextLines: 5,
53+
}),
54+
});
4455
(SentryCore.httpHeadersToSpanAttributes as any).mockReturnValue({ 'http.request.header.user_agent': 'test-agent' });
4556
(SentryCore.flushIfServerless as any).mockResolvedValue(undefined);
4657
});

‎packages/sveltekit/src/server-common/handle.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ async function instrumentHandle(
180180
'sveltekit.tracing.original_name': originalName,
181181
...httpHeadersToSpanAttributes(
182182
winterCGHeadersToDict(event.request.headers),
183-
getClient()?.getOptions().sendDefaultPii ?? false,
183+
getClient()?.getDataCollectionOptions() ?? false,
184184
),
185185
});
186186
}
@@ -209,7 +209,7 @@ async function instrumentHandle(
209209
'http.method': event.request.method,
210210
...httpHeadersToSpanAttributes(
211211
winterCGHeadersToDict(event.request.headers),
212-
getClient()?.getOptions().sendDefaultPii ?? false,
212+
getClient()?.getDataCollectionOptions() ?? false,
213213
),
214214
},
215215
name: routeName,

0 commit comments

Comments
 (0)