@sentry/wizard 3.27.0 → 3.29.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/dist/package.json +1 -1
  3. package/dist/src/nextjs/nextjs-wizard.js +56 -8
  4. package/dist/src/nextjs/nextjs-wizard.js.map +1 -1
  5. package/dist/src/nextjs/templates.js +2 -2
  6. package/dist/src/nextjs/templates.js.map +1 -1
  7. package/dist/src/react-native/react-native-wizard.js +4 -1
  8. package/dist/src/react-native/react-native-wizard.js.map +1 -1
  9. package/dist/src/remix/remix-wizard.d.ts +1 -1
  10. package/dist/src/remix/remix-wizard.js +27 -11
  11. package/dist/src/remix/remix-wizard.js.map +1 -1
  12. package/dist/src/remix/sdk-setup.d.ts +24 -3
  13. package/dist/src/remix/sdk-setup.js +95 -61
  14. package/dist/src/remix/sdk-setup.js.map +1 -1
  15. package/dist/src/sveltekit/sdk-setup.js +64 -43
  16. package/dist/src/sveltekit/sdk-setup.js.map +1 -1
  17. package/dist/src/sveltekit/sveltekit-wizard.d.ts +1 -1
  18. package/dist/src/sveltekit/sveltekit-wizard.js +3 -1
  19. package/dist/src/sveltekit/sveltekit-wizard.js.map +1 -1
  20. package/dist/src/sveltekit/templates.d.ts +8 -2
  21. package/dist/src/sveltekit/templates.js +11 -5
  22. package/dist/src/sveltekit/templates.js.map +1 -1
  23. package/dist/src/utils/clack-utils.d.ts +3 -0
  24. package/dist/src/utils/clack-utils.js +59 -1
  25. package/dist/src/utils/clack-utils.js.map +1 -1
  26. package/dist/test/remix/client-entry.test.d.ts +1 -0
  27. package/dist/test/remix/client-entry.test.js +41 -0
  28. package/dist/test/remix/client-entry.test.js.map +1 -0
  29. package/dist/test/remix/server-instrumentation.test.d.ts +1 -0
  30. package/dist/test/remix/server-instrumentation.test.js +22 -0
  31. package/dist/test/remix/server-instrumentation.test.js.map +1 -0
  32. package/dist/test/sveltekit/templates.test.d.ts +1 -0
  33. package/dist/test/sveltekit/templates.test.js +43 -0
  34. package/dist/test/sveltekit/templates.test.js.map +1 -0
  35. package/package.json +1 -1
  36. package/src/nextjs/nextjs-wizard.ts +48 -3
  37. package/src/nextjs/templates.ts +12 -3
  38. package/src/react-native/react-native-wizard.ts +4 -0
  39. package/src/remix/remix-wizard.ts +32 -6
  40. package/src/remix/sdk-setup.ts +145 -48
  41. package/src/sveltekit/sdk-setup.ts +100 -22
  42. package/src/sveltekit/sveltekit-wizard.ts +4 -1
  43. package/src/sveltekit/templates.ts +36 -10
  44. package/src/utils/clack-utils.ts +47 -1
  45. package/test/remix/client-entry.test.ts +122 -0
  46. package/test/remix/server-instrumentation.test.ts +38 -0
  47. package/test/sveltekit/templates.test.ts +152 -0
@@ -15,7 +15,11 @@ import { builders, generateCode, loadFile, parseModule } from 'magicast';
15
15
  // @ts-ignore - magicast is ESM and TS complains about that. It works though
16
16
  import { addVitePlugin } from 'magicast/helpers';
17
17
  import { getClientHooksTemplate, getServerHooksTemplate } from './templates';
18
- import { abortIfCancelled, isUsingTypeScript } from '../utils/clack-utils';
18
+ import {
19
+ abortIfCancelled,
20
+ featureSelectionPrompt,
21
+ isUsingTypeScript,
22
+ } from '../utils/clack-utils';
19
23
  import { debug } from '../utils/debug';
20
24
  import { findFile, hasSentryContent } from '../utils/ast-utils';
21
25
 
@@ -50,6 +54,23 @@ export async function createOrMergeSvelteKitFiles(
50
54
  projectInfo: ProjectInfo,
51
55
  svelteConfig: PartialSvelteConfig,
52
56
  ): Promise<void> {
57
+ const selectedFeatures = await featureSelectionPrompt([
58
+ {
59
+ id: 'performance',
60
+ prompt: `Do you want to enable ${chalk.bold(
61
+ 'Tracing',
62
+ )} to track the performance of your application?`,
63
+ enabledHint: 'recommended',
64
+ },
65
+ {
66
+ id: 'replay',
67
+ prompt: `Do you want to enable ${chalk.bold(
68
+ 'Sentry Session Replay',
69
+ )} to get a video-like reproduction of errors during a user session?`,
70
+ enabledHint: 'recommended, but increases bundle size',
71
+ },
72
+ ] as const);
73
+
53
74
  const { clientHooksPath, serverHooksPath } = getHooksConfigDirs(svelteConfig);
54
75
 
55
76
  // full file paths with correct file ending (or undefined if not found)
@@ -68,9 +89,19 @@ export async function createOrMergeSvelteKitFiles(
68
89
  );
69
90
  if (!originalClientHooksFile) {
70
91
  clack.log.info('No client hooks file found, creating a new one.');
71
- await createNewHooksFile(`${clientHooksPath}.${fileEnding}`, 'client', dsn);
92
+ await createNewHooksFile(
93
+ `${clientHooksPath}.${fileEnding}`,
94
+ 'client',
95
+ dsn,
96
+ selectedFeatures,
97
+ );
72
98
  } else {
73
- await mergeHooksFile(originalClientHooksFile, 'client', dsn);
99
+ await mergeHooksFile(
100
+ originalClientHooksFile,
101
+ 'client',
102
+ dsn,
103
+ selectedFeatures,
104
+ );
74
105
  }
75
106
 
76
107
  Sentry.setTag(
@@ -79,9 +110,19 @@ export async function createOrMergeSvelteKitFiles(
79
110
  );
80
111
  if (!originalServerHooksFile) {
81
112
  clack.log.info('No server hooks file found, creating a new one.');
82
- await createNewHooksFile(`${serverHooksPath}.${fileEnding}`, 'server', dsn);
113
+ await createNewHooksFile(
114
+ `${serverHooksPath}.${fileEnding}`,
115
+ 'server',
116
+ dsn,
117
+ selectedFeatures,
118
+ );
83
119
  } else {
84
- await mergeHooksFile(originalServerHooksFile, 'server', dsn);
120
+ await mergeHooksFile(
121
+ originalServerHooksFile,
122
+ 'server',
123
+ dsn,
124
+ selectedFeatures,
125
+ );
85
126
  }
86
127
 
87
128
  if (viteConfig) {
@@ -123,11 +164,15 @@ async function createNewHooksFile(
123
164
  hooksFileDest: string,
124
165
  hooktype: 'client' | 'server',
125
166
  dsn: string,
167
+ selectedFeatures: {
168
+ performance: boolean;
169
+ replay: boolean;
170
+ },
126
171
  ): Promise<void> {
127
172
  const filledTemplate =
128
173
  hooktype === 'client'
129
- ? getClientHooksTemplate(dsn)
130
- : getServerHooksTemplate(dsn);
174
+ ? getClientHooksTemplate(dsn, selectedFeatures)
175
+ : getServerHooksTemplate(dsn, selectedFeatures);
131
176
 
132
177
  await fs.promises.mkdir(path.dirname(hooksFileDest), { recursive: true });
133
178
  await fs.promises.writeFile(hooksFileDest, filledTemplate);
@@ -151,6 +196,10 @@ async function mergeHooksFile(
151
196
  hooksFile: string,
152
197
  hookType: 'client' | 'server',
153
198
  dsn: string,
199
+ selectedFeatures: {
200
+ performance: boolean;
201
+ replay: boolean;
202
+ },
154
203
  ): Promise<void> {
155
204
  const originalHooksMod = await loadFile(hooksFile);
156
205
 
@@ -184,9 +233,9 @@ Skipping adding Sentry functionality to.`,
184
233
  await modifyAndRecordFail(
185
234
  () => {
186
235
  if (hookType === 'client') {
187
- insertClientInitCall(dsn, originalHooksMod);
236
+ insertClientInitCall(dsn, originalHooksMod, selectedFeatures);
188
237
  } else {
189
- insertServerInitCall(dsn, originalHooksMod);
238
+ insertServerInitCall(dsn, originalHooksMod, selectedFeatures);
190
239
  }
191
240
  },
192
241
  'init-call-injection',
@@ -224,20 +273,38 @@ function insertClientInitCall(
224
273
  dsn: string,
225
274
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
226
275
  originalHooksMod: ProxifiedModule<any>,
276
+ selectedFeatures: {
277
+ performance: boolean;
278
+ replay: boolean;
279
+ },
227
280
  ): void {
228
281
  const initCallComment = `
229
- // If you don't want to use Session Replay, remove the \`Replay\` integration,
282
+ // If you don't want to use Session Replay, remove the \`Replay\` integration,
230
283
  // \`replaysSessionSampleRate\` and \`replaysOnErrorSampleRate\` options.`;
231
284
 
285
+ const initArgs: {
286
+ dsn: string;
287
+ tracesSampleRate?: number;
288
+ replaysSessionSampleRate?: number;
289
+ replaysOnErrorSampleRate?: number;
290
+ integrations?: string[];
291
+ } = {
292
+ dsn,
293
+ };
294
+
295
+ if (selectedFeatures.performance) {
296
+ initArgs.tracesSampleRate = 1.0;
297
+ }
298
+
299
+ if (selectedFeatures.replay) {
300
+ initArgs.replaysSessionSampleRate = 0.1;
301
+ initArgs.replaysOnErrorSampleRate = 1.0;
302
+ initArgs.integrations = [builders.functionCall('Sentry.replayIntegration')];
303
+ }
304
+
232
305
  // This assignment of any values is fine because we're just creating a function call in magicast
233
306
  // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
234
- const initCall = builders.functionCall('Sentry.init', {
235
- dsn,
236
- tracesSampleRate: 1.0,
237
- replaysSessionSampleRate: 0.1,
238
- replaysOnErrorSampleRate: 1.0,
239
- integrations: [builders.functionCall('Sentry.replayIntegration')],
240
- });
307
+ const initCall = builders.functionCall('Sentry.init', initArgs);
241
308
 
242
309
  // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
243
310
  const initCallWithComment = builders.raw(
@@ -262,13 +329,24 @@ function insertServerInitCall(
262
329
  dsn: string,
263
330
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
264
331
  originalHooksMod: ProxifiedModule<any>,
332
+ selectedFeatures: {
333
+ performance: boolean;
334
+ },
265
335
  ): void {
336
+ const initArgs: {
337
+ dsn: string;
338
+ tracesSampleRate?: number;
339
+ } = {
340
+ dsn,
341
+ };
342
+
343
+ if (selectedFeatures.performance) {
344
+ initArgs.tracesSampleRate = 1.0;
345
+ }
346
+
266
347
  // This assignment of any values is fine because we're just creating a function call in magicast
267
348
  // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
268
- const initCall = builders.functionCall('Sentry.init', {
269
- dsn,
270
- tracesSampleRate: 1.0,
271
- });
349
+ const initCall = builders.functionCall('Sentry.init', initArgs);
272
350
 
273
351
  const originalHooksModAST = originalHooksMod.$ast as Program;
274
352
 
@@ -546,7 +624,7 @@ export default defineConfig({
546
624
  sourceMapsUploadOptions: {
547
625
  org: '${org}',
548
626
  project: '${project}',${selfHosted ? `\n url: '${url}',` : ''}
549
- }
627
+ }
550
628
  }),`)}
551
629
  sveltekit(),
552
630
  ]
@@ -15,9 +15,10 @@ import {
15
15
  getPackageDotJson,
16
16
  installPackage,
17
17
  printWelcome,
18
+ runPrettierIfInstalled,
18
19
  } from '../utils/clack-utils';
19
20
  import { getPackageVersion, hasPackageInstalled } from '../utils/package-json';
20
- import { WizardOptions } from '../utils/types';
21
+ import type { WizardOptions } from '../utils/types';
21
22
  import { createExamplePage } from './sdk-example';
22
23
  import { createOrMergeSvelteKitFiles, loadSvelteConfig } from './sdk-setup';
23
24
  import { traceStep, withTelemetry } from '../telemetry';
@@ -163,6 +164,8 @@ export async function runSvelteKitWizardWithTelemetry(
163
164
  }
164
165
  }
165
166
 
167
+ await runPrettierIfInstalled();
168
+
166
169
  clack.outro(buildOutroMessage(shouldCreateExamplePage));
167
170
  }
168
171
 
@@ -1,21 +1,36 @@
1
- export function getClientHooksTemplate(dsn: string) {
1
+ export function getClientHooksTemplate(
2
+ dsn: string,
3
+ selectedFeatures: {
4
+ performance: boolean;
5
+ replay: boolean;
6
+ },
7
+ ) {
2
8
  return `import { handleErrorWithSentry, replayIntegration } from "@sentry/sveltekit";
3
9
  import * as Sentry from '@sentry/sveltekit';
4
10
 
5
11
  Sentry.init({
6
12
  dsn: '${dsn}',
13
+ ${
14
+ selectedFeatures.performance
15
+ ? `
7
16
  tracesSampleRate: 1.0,
8
-
9
- // This sets the sample rate to be 10%. You may want this to be 100% while
17
+ `
18
+ : ''
19
+ }
20
+ ${
21
+ selectedFeatures.replay
22
+ ? ` // This sets the sample rate to be 10%. You may want this to be 100% while
10
23
  // in development and sample at a lower rate in production
11
24
  replaysSessionSampleRate: 0.1,
12
25
 
13
26
  // If the entire session is not sampled, use the below sample rate to sample
14
27
  // sessions when an error occurs.
15
28
  replaysOnErrorSampleRate: 1.0,
16
-
29
+
17
30
  // If you don't want to use Session Replay, just remove the line below:
18
- integrations: [replayIntegration()],
31
+ integrations: [replayIntegration()],`
32
+ : ''
33
+ }
19
34
  });
20
35
 
21
36
  // If you have a custom error handler, pass it to \`handleErrorWithSentry\`
@@ -23,17 +38,28 @@ export const handleError = handleErrorWithSentry();
23
38
  `;
24
39
  }
25
40
 
26
- export function getServerHooksTemplate(dsn: string) {
41
+ export function getServerHooksTemplate(
42
+ dsn: string,
43
+ selectedFeatures: {
44
+ performance: boolean;
45
+ replay: boolean;
46
+ },
47
+ ) {
27
48
  return `import { sequence } from "@sveltejs/kit/hooks";
28
49
  import { handleErrorWithSentry, sentryHandle } from "@sentry/sveltekit";
29
50
  import * as Sentry from '@sentry/sveltekit';
30
51
 
31
52
  Sentry.init({
32
53
  dsn: '${dsn}',
54
+ ${
55
+ selectedFeatures.performance
56
+ ? `
33
57
  tracesSampleRate: 1.0,
34
-
58
+ `
59
+ : ''
60
+ }
35
61
  // uncomment the line below to enable Spotlight (https://spotlightjs.com)
36
- // spotlight: import.meta.env.DEV,
62
+ // spotlight: import.meta.env.DEV,
37
63
  });
38
64
 
39
65
  // If you have custom handlers, make sure to place them after \`sentryHandle()\` in the \`sequence\` function.
@@ -57,9 +83,9 @@ export function getSentryExampleSveltePage(options: {
57
83
  ? `${options.url}organizations/${options.orgSlug}/issues/?project=${options.projectId}`
58
84
  : `https://${options.orgSlug}.sentry.io/issues/?project=${options.projectId}`;
59
85
 
60
- return `<!--
86
+ return `<!--
61
87
  This is just a very simple page with a button to throw an example error.
62
- Feel free to delete this file and the entire sentry route.
88
+ Feel free to delete this file and the entire sentry route.
63
89
  -->
64
90
 
65
91
  <script>
@@ -670,6 +670,52 @@ async function addCliConfigFileToGitIgnore(filename: string): Promise<void> {
670
670
  }
671
671
  }
672
672
 
673
+ export async function runPrettierIfInstalled(): Promise<void> {
674
+ return traceStep('run-prettier', async () => {
675
+ const packageJson = await getPackageDotJson();
676
+ const prettierInstalled = hasPackageInstalled('prettier', packageJson);
677
+
678
+ if (prettierInstalled) {
679
+ // prompt the user if they want to run prettier
680
+ const shouldRunPrettier = await abortIfCancelled(
681
+ clack.confirm({
682
+ message:
683
+ 'Looks like you have Prettier in your project. Do you want to run it on your files?',
684
+ }),
685
+ );
686
+
687
+ if (!shouldRunPrettier) {
688
+ return;
689
+ }
690
+ } else {
691
+ return;
692
+ }
693
+
694
+ const prettierSpinner = clack.spinner();
695
+ prettierSpinner.start('Running Prettier on your files.');
696
+
697
+ try {
698
+ await new Promise<void>((resolve, reject) => {
699
+ childProcess.exec('npx prettier --write .', (err) => {
700
+ if (err) {
701
+ reject(err);
702
+ } else {
703
+ resolve();
704
+ }
705
+ });
706
+ });
707
+ } catch {
708
+ prettierSpinner.stop('Prettier failed to run.');
709
+ clack.log.error(
710
+ 'Prettier failed to run. There may be formatting issues in your updated files.',
711
+ );
712
+ return;
713
+ }
714
+
715
+ prettierSpinner.stop('Prettier has formatted your files.');
716
+ });
717
+ }
718
+
673
719
  /**
674
720
  * Checks if @param packageId is listed as a dependency in @param packageJson.
675
721
  * If not, it will ask users if they want to continue without the package.
@@ -734,7 +780,7 @@ export async function getPackageDotJson(): Promise<PackageDotJson> {
734
780
  return packageJson || {};
735
781
  }
736
782
 
737
- async function getPackageManager(): Promise<PackageManager> {
783
+ export async function getPackageManager(): Promise<PackageManager> {
738
784
  const detectedPackageManager = detectPackageManger();
739
785
 
740
786
  if (detectedPackageManager) {
@@ -0,0 +1,122 @@
1
+ // @ts-expect-error - magicast is ESM and TS complains about that. It works though
2
+ import { parseModule } from 'magicast';
3
+ import { updateEntryClientMod } from '../../src/remix/sdk-setup';
4
+
5
+ describe('initializeSentryOnEntryClient', () => {
6
+ it('should initialize Sentry on client entry with all features enabled', () => {
7
+ // Empty entry.client.tsx file for testing
8
+ const originalEntryClientMod = parseModule('');
9
+
10
+ const dsn = 'https://sentry.io/123';
11
+ const selectedFeatures = {
12
+ performance: true,
13
+ replay: true,
14
+ };
15
+
16
+ const result = updateEntryClientMod(
17
+ originalEntryClientMod,
18
+ dsn,
19
+ selectedFeatures,
20
+ );
21
+
22
+ expect(result.generate().code).toMatchInlineSnapshot(`
23
+ "import { useEffect,} from "react";
24
+
25
+ import {
26
+ useLocation,
27
+ useMatches,
28
+ } from "@remix-run/react";
29
+
30
+ import * as Sentry from "@sentry/remix";
31
+
32
+ Sentry.init({
33
+ dsn: "https://sentry.io/123",
34
+ tracesSampleRate: 1,
35
+
36
+ integrations: [Sentry.browserTracingIntegration({
37
+ useEffect,
38
+ useLocation,
39
+ useMatches
40
+ }), Sentry.replayIntegration({
41
+ maskAllText: true,
42
+ blockAllMedia: true
43
+ })],
44
+
45
+ replaysSessionSampleRate: 0.1,
46
+ replaysOnErrorSampleRate: 1
47
+ })"
48
+ `);
49
+ });
50
+
51
+ it('should initialize Sentry on client entry when performance disabled', () => {
52
+ // Empty entry.client.tsx file for testing
53
+ const originalEntryClientMod = parseModule('');
54
+
55
+ const dsn = 'https://sentry.io/123';
56
+ const selectedFeatures = {
57
+ performance: false,
58
+ replay: true,
59
+ };
60
+
61
+ const result = updateEntryClientMod(
62
+ originalEntryClientMod,
63
+ dsn,
64
+ selectedFeatures,
65
+ );
66
+
67
+ expect(result.generate().code).toMatchInlineSnapshot(`
68
+ "import * as Sentry from "@sentry/remix";
69
+
70
+ Sentry.init({
71
+ dsn: "https://sentry.io/123",
72
+
73
+ integrations: [Sentry.replayIntegration({
74
+ maskAllText: true,
75
+ blockAllMedia: true
76
+ })],
77
+
78
+ replaysSessionSampleRate: 0.1,
79
+ replaysOnErrorSampleRate: 1
80
+ })"
81
+ `);
82
+ });
83
+
84
+ it('should initialize Sentry on client entry when replay disabled', () => {
85
+ // Empty entry.client.tsx file for testing
86
+ const originalEntryClientMod = parseModule('');
87
+
88
+ const dsn = 'https://sentry.io/123';
89
+ const selectedFeatures = {
90
+ performance: true,
91
+ replay: false,
92
+ };
93
+
94
+ const result = updateEntryClientMod(
95
+ originalEntryClientMod,
96
+ dsn,
97
+ selectedFeatures,
98
+ );
99
+
100
+ expect(result.generate().code).toMatchInlineSnapshot(`
101
+ "import { useEffect,} from "react";
102
+
103
+ import {
104
+ useLocation,
105
+ useMatches,
106
+ } from "@remix-run/react";
107
+
108
+ import * as Sentry from "@sentry/remix";
109
+
110
+ Sentry.init({
111
+ dsn: "https://sentry.io/123",
112
+ tracesSampleRate: 1,
113
+
114
+ integrations: [Sentry.browserTracingIntegration({
115
+ useEffect,
116
+ useLocation,
117
+ useMatches
118
+ })]
119
+ })"
120
+ `);
121
+ });
122
+ });
@@ -0,0 +1,38 @@
1
+ import { generateServerInstrumentationFile } from '../../src/remix/sdk-setup';
2
+
3
+ describe('generateServerInstrumentationFile', () => {
4
+ it('should generate server instrumentation file', () => {
5
+ const result = generateServerInstrumentationFile('https://sentry.io/123', {
6
+ performance: true,
7
+ replay: true,
8
+ });
9
+
10
+ expect(result.instrumentationFileMod.generate().code)
11
+ .toMatchInlineSnapshot(`
12
+ "import * as Sentry from "@sentry/remix";
13
+
14
+ Sentry.init({
15
+ dsn: "https://sentry.io/123",
16
+ tracesSampleRate: 1,
17
+ autoInstrumentRemix: true
18
+ })"
19
+ `);
20
+ });
21
+
22
+ it('should generate server instrumentation file when performance is disabled', () => {
23
+ const result = generateServerInstrumentationFile('https://sentry.io/123', {
24
+ performance: false,
25
+ replay: true,
26
+ });
27
+
28
+ expect(result.instrumentationFileMod.generate().code)
29
+ .toMatchInlineSnapshot(`
30
+ "import * as Sentry from "@sentry/remix";
31
+
32
+ Sentry.init({
33
+ dsn: "https://sentry.io/123",
34
+ autoInstrumentRemix: true
35
+ })"
36
+ `);
37
+ });
38
+ });
@@ -0,0 +1,152 @@
1
+ import {
2
+ getClientHooksTemplate,
3
+ getServerHooksTemplate,
4
+ } from '../../src/sveltekit/templates';
5
+
6
+ describe('getClientHooksTemplate', () => {
7
+ it('should generate client hooks template with all features enabled', () => {
8
+ const result = getClientHooksTemplate('https://sentry.io/123', {
9
+ performance: true,
10
+ replay: true,
11
+ });
12
+
13
+ expect(result).toMatchInlineSnapshot(`
14
+ "import { handleErrorWithSentry, replayIntegration } from "@sentry/sveltekit";
15
+ import * as Sentry from '@sentry/sveltekit';
16
+
17
+ Sentry.init({
18
+ dsn: 'https://sentry.io/123',
19
+
20
+ tracesSampleRate: 1.0,
21
+
22
+ // This sets the sample rate to be 10%. You may want this to be 100% while
23
+ // in development and sample at a lower rate in production
24
+ replaysSessionSampleRate: 0.1,
25
+
26
+ // If the entire session is not sampled, use the below sample rate to sample
27
+ // sessions when an error occurs.
28
+ replaysOnErrorSampleRate: 1.0,
29
+
30
+ // If you don't want to use Session Replay, just remove the line below:
31
+ integrations: [replayIntegration()],
32
+ });
33
+
34
+ // If you have a custom error handler, pass it to \`handleErrorWithSentry\`
35
+ export const handleError = handleErrorWithSentry();
36
+ "
37
+ `);
38
+ });
39
+
40
+ it('should generate client hooks template when performance disabled', () => {
41
+ const result = getClientHooksTemplate('https://sentry.io/123', {
42
+ performance: false,
43
+ replay: true,
44
+ });
45
+
46
+ expect(result).toMatchInlineSnapshot(`
47
+ "import { handleErrorWithSentry, replayIntegration } from "@sentry/sveltekit";
48
+ import * as Sentry from '@sentry/sveltekit';
49
+
50
+ Sentry.init({
51
+ dsn: 'https://sentry.io/123',
52
+
53
+ // This sets the sample rate to be 10%. You may want this to be 100% while
54
+ // in development and sample at a lower rate in production
55
+ replaysSessionSampleRate: 0.1,
56
+
57
+ // If the entire session is not sampled, use the below sample rate to sample
58
+ // sessions when an error occurs.
59
+ replaysOnErrorSampleRate: 1.0,
60
+
61
+ // If you don't want to use Session Replay, just remove the line below:
62
+ integrations: [replayIntegration()],
63
+ });
64
+
65
+ // If you have a custom error handler, pass it to \`handleErrorWithSentry\`
66
+ export const handleError = handleErrorWithSentry();
67
+ "
68
+ `);
69
+ });
70
+
71
+ it('should generate client hooks template when replay disabled', () => {
72
+ const result = getClientHooksTemplate('https://sentry.io/123', {
73
+ performance: true,
74
+ replay: false,
75
+ });
76
+
77
+ expect(result).toMatchInlineSnapshot(`
78
+ "import { handleErrorWithSentry, replayIntegration } from "@sentry/sveltekit";
79
+ import * as Sentry from '@sentry/sveltekit';
80
+
81
+ Sentry.init({
82
+ dsn: 'https://sentry.io/123',
83
+
84
+ tracesSampleRate: 1.0,
85
+
86
+
87
+ });
88
+
89
+ // If you have a custom error handler, pass it to \`handleErrorWithSentry\`
90
+ export const handleError = handleErrorWithSentry();
91
+ "
92
+ `);
93
+ });
94
+ });
95
+
96
+ describe('getServerHooksTemplate', () => {
97
+ it('should generate server hooks template with all features enabled', () => {
98
+ const result = getServerHooksTemplate('https://sentry.io/123', {
99
+ performance: true,
100
+ replay: true,
101
+ });
102
+
103
+ expect(result).toMatchInlineSnapshot(`
104
+ "import { sequence } from "@sveltejs/kit/hooks";
105
+ import { handleErrorWithSentry, sentryHandle } from "@sentry/sveltekit";
106
+ import * as Sentry from '@sentry/sveltekit';
107
+
108
+ Sentry.init({
109
+ dsn: 'https://sentry.io/123',
110
+
111
+ tracesSampleRate: 1.0,
112
+
113
+ // uncomment the line below to enable Spotlight (https://spotlightjs.com)
114
+ // spotlight: import.meta.env.DEV,
115
+ });
116
+
117
+ // If you have custom handlers, make sure to place them after \`sentryHandle()\` in the \`sequence\` function.
118
+ export const handle = sequence(sentryHandle());
119
+
120
+ // If you have a custom error handler, pass it to \`handleErrorWithSentry\`
121
+ export const handleError = handleErrorWithSentry();
122
+ "
123
+ `);
124
+ });
125
+
126
+ it('should generate server hooks template when performance disabled', () => {
127
+ const result = getServerHooksTemplate('https://sentry.io/123', {
128
+ performance: false,
129
+ replay: true,
130
+ });
131
+
132
+ expect(result).toMatchInlineSnapshot(`
133
+ "import { sequence } from "@sveltejs/kit/hooks";
134
+ import { handleErrorWithSentry, sentryHandle } from "@sentry/sveltekit";
135
+ import * as Sentry from '@sentry/sveltekit';
136
+
137
+ Sentry.init({
138
+ dsn: 'https://sentry.io/123',
139
+
140
+ // uncomment the line below to enable Spotlight (https://spotlightjs.com)
141
+ // spotlight: import.meta.env.DEV,
142
+ });
143
+
144
+ // If you have custom handlers, make sure to place them after \`sentryHandle()\` in the \`sequence\` function.
145
+ export const handle = sequence(sentryHandle());
146
+
147
+ // If you have a custom error handler, pass it to \`handleErrorWithSentry\`
148
+ export const handleError = handleErrorWithSentry();
149
+ "
150
+ `);
151
+ });
152
+ });