From f6ac311e31f8f4eee1f8228b61587604cf650b65 Mon Sep 17 00:00:00 2001 From: Onur Temizkan Date: Tue, 5 Aug 2025 12:43:18 +0100 Subject: [PATCH 1/7] feat(sveltekit): Set sendDefaultPii: true by default --- CHANGELOG.md | 1 + e2e-tests/tests/sveltekit-hooks.test.ts | 15 ++++++++++-- src/sveltekit/sdk-setup/setup.ts | 6 +++++ src/sveltekit/templates.ts | 9 +++++++ test/sveltekit/templates.test.ts | 31 +++++++++++++++++++++++++ 5 files changed, 60 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a3631305c..52d9958c1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## Unreleased - feat(nextjs): Set `sendDefaultPii: true` by default ([#1052](https://github.com/getsentry/sentry-wizard/pull/1052)) +- feat(sveltekit): Set `sendDefaultPii: true` by default ([#1054](https://github.com/getsentry/sentry-wizard/pull/1054)) ## 6.5.0 diff --git a/e2e-tests/tests/sveltekit-hooks.test.ts b/e2e-tests/tests/sveltekit-hooks.test.ts index 8a01bdb7d..c9a298c9c 100644 --- a/e2e-tests/tests/sveltekit-hooks.test.ts +++ b/e2e-tests/tests/sveltekit-hooks.test.ts @@ -241,6 +241,10 @@ describe('Sveltekit', () => { // If you don't want to use Session Replay, just remove the line below: integrations: [replayIntegration()], + + // Enable sending user PII (Personally Identifiable Information) + // https://docs.sentry.io/platforms/javascript/guides/sveltekit/configuration/options/#sendDefaultPii + sendDefaultPii: true, });`, 'export const handleError = handleErrorWithSentry(', ]); @@ -257,6 +261,11 @@ describe('Sveltekit', () => { // Enable logs to be sent to Sentry enableLogs: true, + + // Enable sending user PII (Personally Identifiable Information) + // https://docs.sentry.io/platforms/javascript/guides/sveltekit/configuration/options/#sendDefaultPii + sendDefaultPii: true, + // uncomment the line below to enable Spotlight (https://spotlightjs.com) // spotlight: import.meta.env.DEV, });`, @@ -308,7 +317,8 @@ describe('Sveltekit', () => { replaysSessionSampleRate: 0.1, replaysOnErrorSampleRate: 1, integrations: [Sentry.replayIntegration()], - enableLogs: true + enableLogs: true, + sendDefaultPii: true })`, 'export const handleError = Sentry.handleErrorWithSentry(', ]); @@ -320,7 +330,8 @@ describe('Sveltekit', () => { `Sentry.init({ dsn: "${TEST_ARGS.PROJECT_DSN}", tracesSampleRate: 1, - enableLogs: true + enableLogs: true, + sendDefaultPii: true })`, 'export const handleError = Sentry.handleErrorWithSentry();', ]); diff --git a/src/sveltekit/sdk-setup/setup.ts b/src/sveltekit/sdk-setup/setup.ts index ae3fac83d..b78eabd25 100644 --- a/src/sveltekit/sdk-setup/setup.ts +++ b/src/sveltekit/sdk-setup/setup.ts @@ -439,6 +439,7 @@ function insertClientInitCall( replaysOnErrorSampleRate?: number; integrations?: string[]; enableLogs?: boolean; + sendDefaultPii?: boolean; } = { dsn, }; @@ -457,6 +458,8 @@ function insertClientInitCall( initArgs.enableLogs = true; } + initArgs.sendDefaultPii = true; + // This assignment of any values is fine because we're just creating a function call in magicast // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment const initCall = builders.functionCall('Sentry.init', initArgs); @@ -493,6 +496,7 @@ function insertServerInitCall( dsn: string; tracesSampleRate?: number; enableLogs?: boolean; + sendDefaultPii?: boolean; } = { dsn, }; @@ -505,6 +509,8 @@ function insertServerInitCall( initArgs.enableLogs = true; } + initArgs.sendDefaultPii = true; + // This assignment of any values is fine because we're just creating a function call in magicast // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment const initCall = builders.functionCall('Sentry.init', initArgs); diff --git a/src/sveltekit/templates.ts b/src/sveltekit/templates.ts index 2f0c51c93..4ec1785d2 100644 --- a/src/sveltekit/templates.ts +++ b/src/sveltekit/templates.ts @@ -39,6 +39,10 @@ ${ integrations: [replayIntegration()],` : '' } + + // Enable sending user PII (Personally Identifiable Information) + // https://docs.sentry.io/platforms/javascript/guides/sveltekit/configuration/options/#sendDefaultPii + sendDefaultPii: true, }); // If you have a custom error handler, pass it to \`handleErrorWithSentry\` @@ -74,6 +78,11 @@ ${ ` : '' } + + // Enable sending user PII (Personally Identifiable Information) + // https://docs.sentry.io/platforms/javascript/guides/sveltekit/configuration/options/#sendDefaultPii + sendDefaultPii: true, + // uncomment the line below to enable Spotlight (https://spotlightjs.com) // spotlight: import.meta.env.DEV, });` diff --git a/test/sveltekit/templates.test.ts b/test/sveltekit/templates.test.ts index 3d4b3bed2..ff7140156 100644 --- a/test/sveltekit/templates.test.ts +++ b/test/sveltekit/templates.test.ts @@ -39,6 +39,10 @@ describe('getClientHooksTemplate', () => { // If you don't want to use Session Replay, just remove the line below: integrations: [replayIntegration()], + + // Enable sending user PII (Personally Identifiable Information) + // https://docs.sentry.io/platforms/javascript/guides/sveltekit/configuration/options/#sendDefaultPii + sendDefaultPii: true, }); // If you have a custom error handler, pass it to \`handleErrorWithSentry\` @@ -72,6 +76,10 @@ describe('getClientHooksTemplate', () => { // If you don't want to use Session Replay, just remove the line below: integrations: [replayIntegration()], + + // Enable sending user PII (Personally Identifiable Information) + // https://docs.sentry.io/platforms/javascript/guides/sveltekit/configuration/options/#sendDefaultPii + sendDefaultPii: true, }); // If you have a custom error handler, pass it to \`handleErrorWithSentry\` @@ -98,6 +106,10 @@ describe('getClientHooksTemplate', () => { + + // Enable sending user PII (Personally Identifiable Information) + // https://docs.sentry.io/platforms/javascript/guides/sveltekit/configuration/options/#sendDefaultPii + sendDefaultPii: true, }); // If you have a custom error handler, pass it to \`handleErrorWithSentry\` @@ -124,6 +136,10 @@ describe('getClientHooksTemplate', () => { enableLogs: true, + + // Enable sending user PII (Personally Identifiable Information) + // https://docs.sentry.io/platforms/javascript/guides/sveltekit/configuration/options/#sendDefaultPii + sendDefaultPii: true, }); // If you have a custom error handler, pass it to \`handleErrorWithSentry\` @@ -158,6 +174,11 @@ describe('getServerHooksTemplate', () => { // Enable logs to be sent to Sentry enableLogs: true, + + // Enable sending user PII (Personally Identifiable Information) + // https://docs.sentry.io/platforms/javascript/guides/sveltekit/configuration/options/#sendDefaultPii + sendDefaultPii: true, + // uncomment the line below to enable Spotlight (https://spotlightjs.com) // spotlight: import.meta.env.DEV, }); @@ -191,6 +212,11 @@ describe('getServerHooksTemplate', () => { dsn: 'https://sentry.io/123', + + // Enable sending user PII (Personally Identifiable Information) + // https://docs.sentry.io/platforms/javascript/guides/sveltekit/configuration/options/#sendDefaultPii + sendDefaultPii: true, + // uncomment the line below to enable Spotlight (https://spotlightjs.com) // spotlight: import.meta.env.DEV, }); @@ -226,6 +252,11 @@ describe('getServerHooksTemplate', () => { // Enable logs to be sent to Sentry enableLogs: true, + + // Enable sending user PII (Personally Identifiable Information) + // https://docs.sentry.io/platforms/javascript/guides/sveltekit/configuration/options/#sendDefaultPii + sendDefaultPii: true, + // uncomment the line below to enable Spotlight (https://spotlightjs.com) // spotlight: import.meta.env.DEV, }); From 9e3a2f61986756547dc1831e64b99ee1fca41c29 Mon Sep 17 00:00:00 2001 From: Onur Temizkan Date: Tue, 5 Aug 2025 12:45:08 +0100 Subject: [PATCH 2/7] Fix PR number --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 52d9958c1..58f697fa7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1118,3 +1118,5 @@ npx @sentry/wizard -s -i reactNative ## v0.1.0 - Inital release +- feat(nextjs): Set `sendDefaultPii: true` by default ([#1052](https://github.com/getsentry/sentry-wizard/pull/1052)) +- feat(sveltekit): Set `sendDefaultPii: true` by default ([#1055](https://github.com/getsentry/sentry-wizard/pull/1055)) From 29684377b3581a111aa29b09dd8132dd56315718 Mon Sep 17 00:00:00 2001 From: Onur Temizkan Date: Thu, 7 Aug 2025 12:13:38 +0100 Subject: [PATCH 3/7] Add tests for `insertClientInitCall` --- src/sveltekit/sdk-setup/setup.ts | 2 +- test/sveltekit/templates.test.ts | 177 +++++++++++++++++++++++++++++++ 2 files changed, 178 insertions(+), 1 deletion(-) diff --git a/src/sveltekit/sdk-setup/setup.ts b/src/sveltekit/sdk-setup/setup.ts index b78eabd25..cf148fe2d 100644 --- a/src/sveltekit/sdk-setup/setup.ts +++ b/src/sveltekit/sdk-setup/setup.ts @@ -418,7 +418,7 @@ Skipping adding Sentry functionality to it.`, Sentry.setTag(`modified-instrumentation-server`, 'success'); } -function insertClientInitCall( +export function insertClientInitCall( dsn: string, // eslint-disable-next-line @typescript-eslint/no-explicit-any originalHooksMod: ProxifiedModule, diff --git a/test/sveltekit/templates.test.ts b/test/sveltekit/templates.test.ts index ff7140156..f7ebc50fa 100644 --- a/test/sveltekit/templates.test.ts +++ b/test/sveltekit/templates.test.ts @@ -4,6 +4,9 @@ import { getInstrumentationServerTemplate, getServerHooksTemplate, } from '../../src/sveltekit/templates'; +import { insertClientInitCall } from '../../src/sveltekit/sdk-setup'; +// @ts-expect-error - magicast is ESM and TS complains about that. It works though +import { parseModule } from 'magicast'; vi.mock('../../src/utils/clack/mcp-config', () => ({ offerProjectScopedMcpConfig: vi.fn().mockResolvedValue(undefined), @@ -377,3 +380,177 @@ describe('getInstrumentationServerTemplate', () => { });"`); }); }); + +describe('insertClientInitCall', () => { + it('should insert client init call with all features enabled', () => { + const originalHooksMod = parseModule(` + import { handleErrorWithSentry } from "@sentry/sveltekit"; + import * as Sentry from "@sentry/sveltekit"; + + export const handleError = handleErrorWithSentry(); + `); + + insertClientInitCall('https://sentry.io/123', originalHooksMod, { + performance: true, + replay: true, + logs: true, + }); + + const result = originalHooksMod.generate().code; + + expect(result).toContain('import * as Sentry from "@sentry/sveltekit";'); + expect(result).toContain('dsn: "https://sentry.io/123"'); + expect(result).toContain('tracesSampleRate: 1'); + expect(result).toContain('replaysSessionSampleRate: 0.1'); + expect(result).toContain('replaysOnErrorSampleRate: 1'); + expect(result).toContain('enableLogs: true'); + expect(result).toContain('sendDefaultPii: true'); + expect(result).toContain('integrations: [Sentry.replayIntegration()]'); + expect(result).toContain('Sentry.init({'); + }); + + it('should insert client init call with performance disabled', () => { + const originalHooksMod = parseModule(` + import { handleErrorWithSentry } from "@sentry/sveltekit"; + import * as Sentry from "@sentry/sveltekit"; + + export const handleError = handleErrorWithSentry(); + `); + + insertClientInitCall('https://sentry.io/456', originalHooksMod, { + performance: false, + replay: true, + logs: false, + }); + + const result = originalHooksMod.generate().code; + + expect(result).toContain('dsn: "https://sentry.io/456"'); + expect(result).not.toContain('tracesSampleRate'); + expect(result).toContain('replaysSessionSampleRate: 0.1'); + expect(result).toContain('replaysOnErrorSampleRate: 1'); + expect(result).not.toContain('enableLogs: true'); + expect(result).toContain('sendDefaultPii: true'); + expect(result).toContain('integrations: [Sentry.replayIntegration()]'); + }); + + it('should insert client init call with replay disabled', () => { + const originalHooksMod = parseModule(` + import { handleErrorWithSentry } from "@sentry/sveltekit"; + import * as Sentry from "@sentry/sveltekit"; + + export const handleError = handleErrorWithSentry(); + `); + + insertClientInitCall('https://sentry.io/789', originalHooksMod, { + performance: true, + replay: false, + logs: true, + }); + + const result = originalHooksMod.generate().code; + + expect(result).toContain('dsn: "https://sentry.io/789"'); + expect(result).toContain('tracesSampleRate: 1'); + expect(result).not.toContain('replaysSessionSampleRate: 0.1'); + expect(result).not.toContain('replaysOnErrorSampleRate: 1'); + expect(result).not.toContain('integrations: [Sentry.replayIntegration()]'); + expect(result).toContain('enableLogs: true'); + expect(result).toContain('sendDefaultPii: true'); + // Note: The comment mentions replaysSessionSampleRate even when replay is disabled + // This is current behavior of the function + expect(result).toContain('replaysSessionSampleRate'); + }); + + it('should insert client init call with only logs enabled', () => { + const originalHooksMod = parseModule(` + import { handleErrorWithSentry } from "@sentry/sveltekit"; + import * as Sentry from "@sentry/sveltekit"; + + export const handleError = handleErrorWithSentry(); + `); + + insertClientInitCall('https://sentry.io/xyz', originalHooksMod, { + performance: false, + replay: false, + logs: true, + }); + + const result = originalHooksMod.generate().code; + + expect(result).toContain('dsn: "https://sentry.io/xyz"'); + expect(result).not.toContain('tracesSampleRate: 1'); + expect(result).not.toContain('replaysSessionSampleRate: 0.1'); + expect(result).not.toContain('replaysOnErrorSampleRate: 1'); + expect(result).not.toContain('integrations: [Sentry.replayIntegration()]'); + expect(result).toContain('enableLogs: true'); + expect(result).toContain('sendDefaultPii: true'); + // Note: The comment mentions replaysSessionSampleRate even when replay is disabled + expect(result).toContain('replaysSessionSampleRate'); + }); + + it('should insert client init call with all features disabled', () => { + const originalHooksMod = parseModule(` + import { handleErrorWithSentry } from "@sentry/sveltekit"; + import * as Sentry from "@sentry/sveltekit"; + + export const handleError = handleErrorWithSentry(); + `); + + insertClientInitCall('https://sentry.io/minimal', originalHooksMod, { + performance: false, + replay: false, + logs: false, + }); + + const result = originalHooksMod.generate().code; + + expect(result).toContain('dsn: "https://sentry.io/minimal"'); + expect(result).not.toContain('tracesSampleRate: 1'); + expect(result).not.toContain('replaysSessionSampleRate: 0.1'); + expect(result).not.toContain('replaysOnErrorSampleRate: 1'); + expect(result).not.toContain('integrations: [Sentry.replayIntegration()]'); + expect(result).not.toContain('enableLogs: true'); + expect(result).toContain('sendDefaultPii: true'); + // Note: The comment mentions replaysSessionSampleRate even when replay is disabled + expect(result).toContain('replaysSessionSampleRate'); + }); + + it('should insert init call after imports', () => { + const originalHooksMod = parseModule(` + import { handleErrorWithSentry } from "@sentry/sveltekit"; + import { somethingElse } from "some-package"; + import * as Sentry from "@sentry/sveltekit"; + + export const handleError = handleErrorWithSentry(); + export const someOtherExport = somethingElse(); + `); + + insertClientInitCall('https://sentry.io/order-test', originalHooksMod, { + performance: true, + replay: false, + logs: false, + }); + + const result = originalHooksMod.generate().code; + const lines = result + .split('\n') + .map((line) => line.trim()) + .filter((line) => line); + + // Find the index of the last import and the Sentry.init call + const lastImportIndex = Math.max( + lines.findIndex((line) => + line.includes('import { handleErrorWithSentry }'), + ), + lines.findIndex((line) => line.includes('import { somethingElse }')), + lines.findIndex((line) => line.includes('import * as Sentry')), + ); + const sentryInitIndex = lines.findIndex((line) => + line.includes('Sentry.init({'), + ); + + expect(sentryInitIndex).toBeGreaterThan(lastImportIndex); + expect(result).toContain('Sentry.init({'); + }); +}); From 46d4b0f6bc2f2838262c32e173f6880995e6690e Mon Sep 17 00:00:00 2001 From: Onur Temizkan Date: Mon, 6 Oct 2025 13:57:27 +0100 Subject: [PATCH 4/7] Use `toMatchInlineSnapshot` for assertions --- test/sveltekit/templates.test.ts | 156 ++++++++++++++++++------------- 1 file changed, 93 insertions(+), 63 deletions(-) diff --git a/test/sveltekit/templates.test.ts b/test/sveltekit/templates.test.ts index f7ebc50fa..ddbeeda88 100644 --- a/test/sveltekit/templates.test.ts +++ b/test/sveltekit/templates.test.ts @@ -4,7 +4,7 @@ import { getInstrumentationServerTemplate, getServerHooksTemplate, } from '../../src/sveltekit/templates'; -import { insertClientInitCall } from '../../src/sveltekit/sdk-setup'; +import { insertClientInitCall } from '../../src/sveltekit/sdk-setup/setup'; // @ts-expect-error - magicast is ESM and TS complains about that. It works though import { parseModule } from 'magicast'; @@ -398,15 +398,24 @@ describe('insertClientInitCall', () => { const result = originalHooksMod.generate().code; - expect(result).toContain('import * as Sentry from "@sentry/sveltekit";'); - expect(result).toContain('dsn: "https://sentry.io/123"'); - expect(result).toContain('tracesSampleRate: 1'); - expect(result).toContain('replaysSessionSampleRate: 0.1'); - expect(result).toContain('replaysOnErrorSampleRate: 1'); - expect(result).toContain('enableLogs: true'); - expect(result).toContain('sendDefaultPii: true'); - expect(result).toContain('integrations: [Sentry.replayIntegration()]'); - expect(result).toContain('Sentry.init({'); + expect(result).toMatchInlineSnapshot(` + "import { handleErrorWithSentry } from "@sentry/sveltekit"; + import * as Sentry from "@sentry/sveltekit"; + + // If you don't want to use Session Replay, remove the \`Replay\` integration, + // \`replaysSessionSampleRate\` and \`replaysOnErrorSampleRate\` options. + Sentry.init({ + dsn: "https://sentry.io/123", + tracesSampleRate: 1, + replaysSessionSampleRate: 0.1, + replaysOnErrorSampleRate: 1, + integrations: [Sentry.replayIntegration()], + enableLogs: true, + sendDefaultPii: true + }) + + export const handleError = handleErrorWithSentry();" + `); }); it('should insert client init call with performance disabled', () => { @@ -425,13 +434,22 @@ describe('insertClientInitCall', () => { const result = originalHooksMod.generate().code; - expect(result).toContain('dsn: "https://sentry.io/456"'); - expect(result).not.toContain('tracesSampleRate'); - expect(result).toContain('replaysSessionSampleRate: 0.1'); - expect(result).toContain('replaysOnErrorSampleRate: 1'); - expect(result).not.toContain('enableLogs: true'); - expect(result).toContain('sendDefaultPii: true'); - expect(result).toContain('integrations: [Sentry.replayIntegration()]'); + expect(result).toMatchInlineSnapshot(` + "import { handleErrorWithSentry } from "@sentry/sveltekit"; + import * as Sentry from "@sentry/sveltekit"; + + // If you don't want to use Session Replay, remove the \`Replay\` integration, + // \`replaysSessionSampleRate\` and \`replaysOnErrorSampleRate\` options. + Sentry.init({ + dsn: "https://sentry.io/456", + replaysSessionSampleRate: 0.1, + replaysOnErrorSampleRate: 1, + integrations: [Sentry.replayIntegration()], + sendDefaultPii: true + }) + + export const handleError = handleErrorWithSentry();" + `); }); it('should insert client init call with replay disabled', () => { @@ -450,16 +468,21 @@ describe('insertClientInitCall', () => { const result = originalHooksMod.generate().code; - expect(result).toContain('dsn: "https://sentry.io/789"'); - expect(result).toContain('tracesSampleRate: 1'); - expect(result).not.toContain('replaysSessionSampleRate: 0.1'); - expect(result).not.toContain('replaysOnErrorSampleRate: 1'); - expect(result).not.toContain('integrations: [Sentry.replayIntegration()]'); - expect(result).toContain('enableLogs: true'); - expect(result).toContain('sendDefaultPii: true'); - // Note: The comment mentions replaysSessionSampleRate even when replay is disabled - // This is current behavior of the function - expect(result).toContain('replaysSessionSampleRate'); + expect(result).toMatchInlineSnapshot(` + "import { handleErrorWithSentry } from "@sentry/sveltekit"; + import * as Sentry from "@sentry/sveltekit"; + + // If you don't want to use Session Replay, remove the \`Replay\` integration, + // \`replaysSessionSampleRate\` and \`replaysOnErrorSampleRate\` options. + Sentry.init({ + dsn: "https://sentry.io/789", + tracesSampleRate: 1, + enableLogs: true, + sendDefaultPii: true + }) + + export const handleError = handleErrorWithSentry();" + `); }); it('should insert client init call with only logs enabled', () => { @@ -478,15 +501,20 @@ describe('insertClientInitCall', () => { const result = originalHooksMod.generate().code; - expect(result).toContain('dsn: "https://sentry.io/xyz"'); - expect(result).not.toContain('tracesSampleRate: 1'); - expect(result).not.toContain('replaysSessionSampleRate: 0.1'); - expect(result).not.toContain('replaysOnErrorSampleRate: 1'); - expect(result).not.toContain('integrations: [Sentry.replayIntegration()]'); - expect(result).toContain('enableLogs: true'); - expect(result).toContain('sendDefaultPii: true'); - // Note: The comment mentions replaysSessionSampleRate even when replay is disabled - expect(result).toContain('replaysSessionSampleRate'); + expect(result).toMatchInlineSnapshot(` + "import { handleErrorWithSentry } from "@sentry/sveltekit"; + import * as Sentry from "@sentry/sveltekit"; + + // If you don't want to use Session Replay, remove the \`Replay\` integration, + // \`replaysSessionSampleRate\` and \`replaysOnErrorSampleRate\` options. + Sentry.init({ + dsn: "https://sentry.io/xyz", + enableLogs: true, + sendDefaultPii: true + }) + + export const handleError = handleErrorWithSentry();" + `); }); it('should insert client init call with all features disabled', () => { @@ -505,15 +533,19 @@ describe('insertClientInitCall', () => { const result = originalHooksMod.generate().code; - expect(result).toContain('dsn: "https://sentry.io/minimal"'); - expect(result).not.toContain('tracesSampleRate: 1'); - expect(result).not.toContain('replaysSessionSampleRate: 0.1'); - expect(result).not.toContain('replaysOnErrorSampleRate: 1'); - expect(result).not.toContain('integrations: [Sentry.replayIntegration()]'); - expect(result).not.toContain('enableLogs: true'); - expect(result).toContain('sendDefaultPii: true'); - // Note: The comment mentions replaysSessionSampleRate even when replay is disabled - expect(result).toContain('replaysSessionSampleRate'); + expect(result).toMatchInlineSnapshot(` + "import { handleErrorWithSentry } from "@sentry/sveltekit"; + import * as Sentry from "@sentry/sveltekit"; + + // If you don't want to use Session Replay, remove the \`Replay\` integration, + // \`replaysSessionSampleRate\` and \`replaysOnErrorSampleRate\` options. + Sentry.init({ + dsn: "https://sentry.io/minimal", + sendDefaultPii: true + }) + + export const handleError = handleErrorWithSentry();" + `); }); it('should insert init call after imports', () => { @@ -533,24 +565,22 @@ describe('insertClientInitCall', () => { }); const result = originalHooksMod.generate().code; - const lines = result - .split('\n') - .map((line) => line.trim()) - .filter((line) => line); - - // Find the index of the last import and the Sentry.init call - const lastImportIndex = Math.max( - lines.findIndex((line) => - line.includes('import { handleErrorWithSentry }'), - ), - lines.findIndex((line) => line.includes('import { somethingElse }')), - lines.findIndex((line) => line.includes('import * as Sentry')), - ); - const sentryInitIndex = lines.findIndex((line) => - line.includes('Sentry.init({'), - ); - expect(sentryInitIndex).toBeGreaterThan(lastImportIndex); - expect(result).toContain('Sentry.init({'); + expect(result).toMatchInlineSnapshot(` + "import { handleErrorWithSentry } from "@sentry/sveltekit"; + import { somethingElse } from "some-package"; + import * as Sentry from "@sentry/sveltekit"; + + // If you don't want to use Session Replay, remove the \`Replay\` integration, + // \`replaysSessionSampleRate\` and \`replaysOnErrorSampleRate\` options. + Sentry.init({ + dsn: "https://sentry.io/order-test", + tracesSampleRate: 1, + sendDefaultPii: true + }) + + export const handleError = handleErrorWithSentry(); + export const someOtherExport = somethingElse();" + `); }); }); From e7361d80c2c17e38405bad4306d54700d0789ddc Mon Sep 17 00:00:00 2001 From: Onur Temizkan Date: Mon, 6 Oct 2025 14:24:38 +0100 Subject: [PATCH 5/7] Fix PR number again --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 58f697fa7..e95fa869a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,7 @@ ## Unreleased - feat(nextjs): Set `sendDefaultPii: true` by default ([#1052](https://github.com/getsentry/sentry-wizard/pull/1052)) -- feat(sveltekit): Set `sendDefaultPii: true` by default ([#1054](https://github.com/getsentry/sentry-wizard/pull/1054)) +- feat(sveltekit): Set `sendDefaultPii: true` by default ([#1055](https://github.com/getsentry/sentry-wizard/pull/1055)) ## 6.5.0 From ca7a0bcd5907ca12dd9b37e82d4c5b2598e2d5d9 Mon Sep 17 00:00:00 2001 From: Onur Temizkan Date: Mon, 6 Oct 2025 14:31:55 +0100 Subject: [PATCH 6/7] Fix E2E test --- e2e-tests/tests/sveltekit-tracing.test.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/e2e-tests/tests/sveltekit-tracing.test.ts b/e2e-tests/tests/sveltekit-tracing.test.ts index f5469bc54..15b8103cd 100644 --- a/e2e-tests/tests/sveltekit-tracing.test.ts +++ b/e2e-tests/tests/sveltekit-tracing.test.ts @@ -142,6 +142,10 @@ describe('Sveltekit with instrumentation and tracing', () => { // If you don't want to use Session Replay, just remove the line below: integrations: [replayIntegration()], + + // Enable sending user PII (Personally Identifiable Information) + // https://docs.sentry.io/platforms/javascript/guides/sveltekit/configuration/options/#sendDefaultPii + sendDefaultPii: true, }); // If you have a custom error handler, pass it to \`handleErrorWithSentry\` From baa0dd4bfce83065cf8aada12dd29a080dd5f3ed Mon Sep 17 00:00:00 2001 From: Lukas Stracke Date: Thu, 9 Oct 2025 10:53:05 +0200 Subject: [PATCH 7/7] Update CHANGELOG.md --- CHANGELOG.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e95fa869a..0941a5a2e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1118,5 +1118,3 @@ npx @sentry/wizard -s -i reactNative ## v0.1.0 - Inital release -- feat(nextjs): Set `sendDefaultPii: true` by default ([#1052](https://github.com/getsentry/sentry-wizard/pull/1052)) -- feat(sveltekit): Set `sendDefaultPii: true` by default ([#1055](https://github.com/getsentry/sentry-wizard/pull/1055))