sveltekit.tsx 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. import {Fragment} from 'react';
  2. import ExternalLink from 'sentry/components/links/externalLink';
  3. import List from 'sentry/components/list/';
  4. import ListItem from 'sentry/components/list/listItem';
  5. import {Layout, LayoutProps} from 'sentry/components/onboarding/gettingStartedDoc/layout';
  6. import {ModuleProps} from 'sentry/components/onboarding/gettingStartedDoc/sdkDocumentation';
  7. import {StepType} from 'sentry/components/onboarding/gettingStartedDoc/step';
  8. import {ProductSolution} from 'sentry/components/onboarding/productSelection';
  9. import {t, tct} from 'sentry/locale';
  10. // Configuration Start
  11. const replayIntegration = `
  12. new Sentry.Replay(),
  13. `;
  14. const replayOtherConfig = `
  15. // Session Replay
  16. replaysSessionSampleRate: 0.1, // This sets the sample rate at 10%. You may want to change it to 100% while in development and then sample at a lower rate in production.
  17. replaysOnErrorSampleRate: 1.0, // If you're not already sampling the entire session, change the sample rate to 100% when sampling sessions where errors occur.
  18. `;
  19. const performanceOtherConfig = `
  20. // Performance Monitoring
  21. tracesSampleRate: 1.0, // Capture 100% of the transactions, reduce in production!
  22. `;
  23. export const steps = ({
  24. sentryInitContent,
  25. }: {
  26. sentryInitContent?: string;
  27. } = {}): LayoutProps['steps'] => [
  28. {
  29. type: StepType.INSTALL,
  30. description: (
  31. <p>
  32. {tct('Configure your app automatically with the [wizardLink:Sentry wizard].', {
  33. wizardLink: (
  34. <ExternalLink href="https://docs.sentry.io/platforms/javascript/guides/sveltekit/#install" />
  35. ),
  36. })}
  37. </p>
  38. ),
  39. configurations: [
  40. {
  41. language: 'bash',
  42. code: `npx @sentry/wizard -i sveltekit`,
  43. },
  44. ],
  45. },
  46. {
  47. type: StepType.CONFIGURE,
  48. description: (
  49. <Fragment>
  50. {t(
  51. 'The Sentry wizard will automatically patch your application to configure the Sentry SDK:'
  52. )}
  53. <List symbol="bullet">
  54. <ListItem>
  55. {tct(
  56. 'Create or update [code:src/hooks.client.js] and [code:src/hooks.server.js] with the default [code:Sentry.init] call and SvelteKit hooks handlers.',
  57. {
  58. code: <code />,
  59. }
  60. )}
  61. </ListItem>
  62. <ListItem>
  63. {tct(
  64. 'Update [code:vite.config.js] to add source maps upload and auto-instrumentation via Vite plugins.',
  65. {
  66. code: <code />,
  67. }
  68. )}
  69. </ListItem>
  70. <ListItem>
  71. {tct(
  72. 'Create [code:.sentryclirc] and [code:sentry.properties] files with configuration for sentry-cli (which is used when automatically uploading source maps).',
  73. {
  74. code: <code />,
  75. }
  76. )}
  77. </ListItem>
  78. </List>
  79. <p>
  80. {tct('Alternatively, you can also [manualSetupLink:set up the SDK manually].', {
  81. manualSetupLink: (
  82. <ExternalLink href="https://docs.sentry.io/platforms/javascript/guides/sveltekit/manual-setup/" />
  83. ),
  84. })}
  85. </p>
  86. </Fragment>
  87. ),
  88. configurations: [
  89. {
  90. description: (
  91. <Fragment>
  92. <strong>{t('Configure the Sentry SDK:')}</strong>
  93. <p>
  94. {tct(
  95. 'To configure the Sentry SDK, edit the [code:Sentry.init] options in [code:hooks.(client|server).(js|ts)]:',
  96. {code: <code />}
  97. )}
  98. </p>
  99. </Fragment>
  100. ),
  101. language: 'javascript',
  102. code: `
  103. import * as Sentry from "@sentry/sveltekit";
  104. Sentry.init({
  105. ${sentryInitContent}
  106. });
  107. `,
  108. },
  109. ],
  110. },
  111. {
  112. type: StepType.VERIFY,
  113. description: t(
  114. "This snippet contains an intentional error and can be used as a test to make sure that everything's working as expected."
  115. ),
  116. configurations: [
  117. {
  118. language: 'javascript',
  119. code: `
  120. <!-- +page.svelte -->
  121. <button type="button" on:click={unknownFunction}>Break the world</button>
  122. `,
  123. },
  124. ],
  125. },
  126. ];
  127. export const nextSteps = [
  128. {
  129. id: 'source-maps',
  130. name: t('Source Maps'),
  131. description: t('Learn how to enable readable stack traces in your Sentry errors.'),
  132. link: 'https://docs.sentry.io/platforms/javascript/guides/sveltekit/sourcemaps/',
  133. },
  134. {
  135. id: 'performance-monitoring',
  136. name: t('Performance Monitoring'),
  137. description: t(
  138. 'Track down transactions to connect the dots between 10-second page loads and poor-performing API calls or slow database queries.'
  139. ),
  140. link: 'https://docs.sentry.io/platforms/javascript/guides/sveltekit/performance/',
  141. },
  142. {
  143. id: 'session-replay',
  144. name: t('Session Replay'),
  145. description: t(
  146. 'Get to the root cause of an error or latency issue faster by seeing all the technical details related to that issue in one visual replay on your web application.'
  147. ),
  148. link: 'https://docs.sentry.io/platforms/javascript/guides/sveltekit/session-replay/',
  149. },
  150. ];
  151. // Configuration End
  152. export function GettingStartedWithSvelteKit({
  153. dsn,
  154. activeProductSelection = [],
  155. ...props
  156. }: ModuleProps) {
  157. const integrations: string[] = [];
  158. const otherConfigs: string[] = [];
  159. let nextStepDocs = [...nextSteps];
  160. if (activeProductSelection.includes(ProductSolution.PERFORMANCE_MONITORING)) {
  161. otherConfigs.push(performanceOtherConfig.trim());
  162. nextStepDocs = nextStepDocs.filter(
  163. step => step.id !== ProductSolution.PERFORMANCE_MONITORING
  164. );
  165. }
  166. if (activeProductSelection.includes(ProductSolution.SESSION_REPLAY)) {
  167. integrations.push(replayIntegration.trim());
  168. otherConfigs.push(replayOtherConfig.trim());
  169. nextStepDocs = nextStepDocs.filter(
  170. step => step.id !== ProductSolution.SESSION_REPLAY
  171. );
  172. }
  173. let sentryInitContent: string[] = [`dsn: "${dsn}",`];
  174. if (integrations.length > 0) {
  175. sentryInitContent = sentryInitContent.concat('integrations: [', integrations, '],');
  176. }
  177. if (otherConfigs.length > 0) {
  178. sentryInitContent = sentryInitContent.concat(otherConfigs);
  179. }
  180. return (
  181. <Layout
  182. steps={steps({sentryInitContent: sentryInitContent.join('\n')})}
  183. nextSteps={nextStepDocs}
  184. {...props}
  185. />
  186. );
  187. }
  188. export default GettingStartedWithSvelteKit;