sveltekit.tsx 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  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@latest -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 [hookClientCode:src/hooks.client.js] and [hookServerCode:src/hooks.server.js] with the default [sentryInitCode:Sentry.init] call and SvelteKit hooks handlers.',
  57. {
  58. hookClientCode: <code />,
  59. hookServerCode: <code />,
  60. sentryInitCode: <code />,
  61. }
  62. )}
  63. </ListItem>
  64. <ListItem>
  65. {tct(
  66. 'Update [code:vite.config.js] to add source maps upload and auto-instrumentation via Vite plugins.',
  67. {
  68. code: <code />,
  69. }
  70. )}
  71. </ListItem>
  72. <ListItem>
  73. {tct(
  74. 'Create [sentryClircCode:.sentryclirc] and [sentryPropertiesCode:sentry.properties] files with configuration for sentry-cli (which is used when automatically uploading source maps).',
  75. {
  76. sentryClircCode: <code />,
  77. sentryPropertiesCode: <code />,
  78. }
  79. )}
  80. </ListItem>
  81. </List>
  82. <p>
  83. {tct('Alternatively, you can also [manualSetupLink:set up the SDK manually].', {
  84. manualSetupLink: (
  85. <ExternalLink href="https://docs.sentry.io/platforms/javascript/guides/sveltekit/manual-setup/" />
  86. ),
  87. })}
  88. </p>
  89. </Fragment>
  90. ),
  91. configurations: [
  92. {
  93. description: (
  94. <Fragment>
  95. <strong>{t('Configure the Sentry SDK:')}</strong>
  96. <p>
  97. {tct(
  98. 'To configure the Sentry SDK, edit the [sentryInitCode:Sentry.init] options in [hooksCode:hooks.(client|server).(js|ts)]:',
  99. {hooksCode: <code />, sentryInitCode: <code />}
  100. )}
  101. </p>
  102. </Fragment>
  103. ),
  104. language: 'javascript',
  105. code: `
  106. import * as Sentry from "@sentry/sveltekit";
  107. Sentry.init({
  108. ${sentryInitContent}
  109. });
  110. `,
  111. },
  112. ],
  113. },
  114. {
  115. type: StepType.VERIFY,
  116. description: t(
  117. "This snippet contains an intentional error and can be used as a test to make sure that everything's working as expected."
  118. ),
  119. configurations: [
  120. {
  121. language: 'javascript',
  122. code: `
  123. <!-- +page.svelte -->
  124. <button type="button" on:click={unknownFunction}>Break the world</button>
  125. `,
  126. },
  127. ],
  128. },
  129. ];
  130. export const nextSteps = [
  131. {
  132. id: 'source-maps',
  133. name: t('Source Maps'),
  134. description: t('Learn how to enable readable stack traces in your Sentry errors.'),
  135. link: 'https://docs.sentry.io/platforms/javascript/guides/sveltekit/sourcemaps/',
  136. },
  137. {
  138. id: 'performance-monitoring',
  139. name: t('Performance Monitoring'),
  140. description: t(
  141. 'Track down transactions to connect the dots between 10-second page loads and poor-performing API calls or slow database queries.'
  142. ),
  143. link: 'https://docs.sentry.io/platforms/javascript/guides/sveltekit/performance/',
  144. },
  145. {
  146. id: 'session-replay',
  147. name: t('Session Replay'),
  148. description: t(
  149. '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.'
  150. ),
  151. link: 'https://docs.sentry.io/platforms/javascript/guides/sveltekit/session-replay/',
  152. },
  153. ];
  154. // Configuration End
  155. export function GettingStartedWithSvelteKit({
  156. dsn,
  157. activeProductSelection = [],
  158. ...props
  159. }: ModuleProps) {
  160. const integrations: string[] = [];
  161. const otherConfigs: string[] = [];
  162. let nextStepDocs = [...nextSteps];
  163. if (activeProductSelection.includes(ProductSolution.PERFORMANCE_MONITORING)) {
  164. otherConfigs.push(performanceOtherConfig.trim());
  165. nextStepDocs = nextStepDocs.filter(
  166. step => step.id !== ProductSolution.PERFORMANCE_MONITORING
  167. );
  168. }
  169. if (activeProductSelection.includes(ProductSolution.SESSION_REPLAY)) {
  170. integrations.push(replayIntegration.trim());
  171. otherConfigs.push(replayOtherConfig.trim());
  172. nextStepDocs = nextStepDocs.filter(
  173. step => step.id !== ProductSolution.SESSION_REPLAY
  174. );
  175. }
  176. let sentryInitContent: string[] = [`dsn: "${dsn}",`];
  177. if (integrations.length > 0) {
  178. sentryInitContent = sentryInitContent.concat('integrations: [', integrations, '],');
  179. }
  180. if (otherConfigs.length > 0) {
  181. sentryInitContent = sentryInitContent.concat(otherConfigs);
  182. }
  183. return (
  184. <Layout
  185. steps={steps({sentryInitContent: sentryInitContent.join('\n')})}
  186. nextSteps={nextStepDocs}
  187. {...props}
  188. />
  189. );
  190. }
  191. export default GettingStartedWithSvelteKit;