sveltekit.tsx 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  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 crashReportCallout from 'sentry/components/onboarding/gettingStartedDoc/feedback/crashReportCallout';
  6. import widgetCallout from 'sentry/components/onboarding/gettingStartedDoc/feedback/widgetCallout';
  7. import TracePropagationMessage from 'sentry/components/onboarding/gettingStartedDoc/replay/tracePropagationMessage';
  8. import {StepType} from 'sentry/components/onboarding/gettingStartedDoc/step';
  9. import type {
  10. Docs,
  11. DocsParams,
  12. OnboardingConfig,
  13. } from 'sentry/components/onboarding/gettingStartedDoc/types';
  14. import {
  15. getCrashReportJavaScriptInstallStep,
  16. getCrashReportModalConfigDescription,
  17. getCrashReportModalIntroduction,
  18. getFeedbackConfigureDescription,
  19. getFeedbackSDKSetupSnippet,
  20. } from 'sentry/components/onboarding/gettingStartedDoc/utils/feedbackOnboarding';
  21. import {getJSMetricsOnboarding} from 'sentry/components/onboarding/gettingStartedDoc/utils/metricsOnboarding';
  22. import {
  23. getReplayConfigureDescription,
  24. getReplaySDKSetupSnippet,
  25. getReplayVerifyStep,
  26. } from 'sentry/components/onboarding/gettingStartedDoc/utils/replayOnboarding';
  27. import {t, tct} from 'sentry/locale';
  28. type Params = DocsParams;
  29. const getConfigStep = ({isSelfHosted, organization, projectSlug}: Params) => {
  30. const urlParam = isSelfHosted ? '' : '--saas';
  31. return [
  32. {
  33. type: StepType.INSTALL,
  34. description: tct(
  35. 'Configure your app automatically by running the [wizardLink:Sentry wizard] in the root of your project.',
  36. {
  37. wizardLink: (
  38. <ExternalLink href="https://docs.sentry.io/platforms/javascript/guides/sveltekit/#install" />
  39. ),
  40. }
  41. ),
  42. configurations: [
  43. {
  44. language: 'bash',
  45. code: `npx @sentry/wizard@latest -i sveltekit ${urlParam} --org ${organization.slug} --project ${projectSlug}`,
  46. },
  47. ],
  48. },
  49. ];
  50. };
  51. const getInstallConfig = (params: Params) => [
  52. {
  53. type: StepType.INSTALL,
  54. configurations: getConfigStep(params),
  55. },
  56. ];
  57. const onboarding: OnboardingConfig = {
  58. install: (params: Params) => [
  59. {
  60. title: t('Automatic Configuration (Recommended)'),
  61. configurations: getConfigStep(params),
  62. },
  63. ],
  64. configure: () => [
  65. {
  66. title: t('Manual Configuration'),
  67. collapsible: true,
  68. description: tct(
  69. 'Alternatively, you can also [manualSetupLink:set up the SDK manually], by following these steps:',
  70. {
  71. manualSetupLink: (
  72. <ExternalLink href="https://docs.sentry.io/platforms/javascript/guides/sveltekit/manual-setup/" />
  73. ),
  74. }
  75. ),
  76. configurations: [
  77. {
  78. description: (
  79. <List symbol="bullet">
  80. <ListItem>
  81. {tct(
  82. '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.',
  83. {
  84. code: <code />,
  85. }
  86. )}
  87. </ListItem>
  88. <ListItem>
  89. {tct(
  90. 'Update [code:vite.config.js] to add source maps upload and auto-instrumentation via Vite plugins.',
  91. {
  92. code: <code />,
  93. }
  94. )}
  95. </ListItem>
  96. <ListItem>
  97. {tct(
  98. 'Create [code:.sentryclirc] and [code:sentry.properties] files with configuration for sentry-cli (which is used when automatically uploading source maps).',
  99. {
  100. code: <code />,
  101. }
  102. )}
  103. </ListItem>
  104. </List>
  105. ),
  106. },
  107. ],
  108. },
  109. ],
  110. verify: () => [
  111. {
  112. type: StepType.VERIFY,
  113. description: (
  114. <Fragment>
  115. <p>
  116. {tct(
  117. 'Start your development server and visit [code:/sentry-example-page] if you have set it up. Click the button to trigger a test error.',
  118. {
  119. code: <code />,
  120. }
  121. )}
  122. </p>
  123. <p>
  124. {t(
  125. 'Or, trigger a sample error by calling a function that does not exist somewhere in your application.'
  126. )}
  127. </p>
  128. </Fragment>
  129. ),
  130. configurations: [
  131. {
  132. code: [
  133. {
  134. label: 'Javascript',
  135. value: 'javascript',
  136. language: 'javascript',
  137. code: `myUndefinedFunction();`,
  138. },
  139. ],
  140. },
  141. ],
  142. additionalInfo: t(
  143. 'If you see an issue in your Sentry dashboard, you have successfully set up Sentry.'
  144. ),
  145. },
  146. ],
  147. };
  148. const replayOnboarding: OnboardingConfig = {
  149. install: (params: Params) => getInstallConfig(params),
  150. configure: (params: Params) => [
  151. {
  152. type: StepType.CONFIGURE,
  153. description: getReplayConfigureDescription({
  154. link: 'https://docs.sentry.io/platforms/javascript/guides/sveltekit/session-replay/',
  155. }),
  156. configurations: [
  157. {
  158. code: [
  159. {
  160. label: 'JavaScript',
  161. value: 'javascript',
  162. language: 'javascript',
  163. code: getReplaySDKSetupSnippet({
  164. importStatement: `import * as Sentry from "@sentry/sveltekit";`,
  165. dsn: params.dsn.public,
  166. mask: params.replayOptions?.mask,
  167. block: params.replayOptions?.block,
  168. }),
  169. },
  170. ],
  171. additionalInfo: <TracePropagationMessage />,
  172. },
  173. ],
  174. },
  175. ],
  176. verify: getReplayVerifyStep(),
  177. nextSteps: () => [],
  178. };
  179. const feedbackOnboarding: OnboardingConfig = {
  180. install: (params: Params) => [
  181. {
  182. type: StepType.INSTALL,
  183. description: tct(
  184. 'For the User Feedback integration to work, you must have the Sentry browser SDK package, or an equivalent framework SDK (e.g. [code:@sentry/sveltekit]) installed, minimum version 7.85.0.',
  185. {
  186. code: <code />,
  187. }
  188. ),
  189. configurations: getInstallConfig(params),
  190. },
  191. ],
  192. configure: (params: Params) => [
  193. {
  194. type: StepType.CONFIGURE,
  195. description: getFeedbackConfigureDescription({
  196. linkConfig:
  197. 'https://docs.sentry.io/platforms/javascript/guides/sveltekit/user-feedback/configuration/',
  198. linkButton:
  199. 'https://docs.sentry.io/platforms/javascript/guides/sveltekit/user-feedback/configuration/#bring-your-own-button',
  200. }),
  201. configurations: [
  202. {
  203. code: [
  204. {
  205. label: 'JavaScript',
  206. value: 'javascript',
  207. language: 'javascript',
  208. code: getFeedbackSDKSetupSnippet({
  209. importStatement: `import * as Sentry from "@sentry/sveltekit";`,
  210. dsn: params.dsn.public,
  211. feedbackOptions: params.feedbackOptions,
  212. }),
  213. },
  214. ],
  215. },
  216. ],
  217. additionalInfo: crashReportCallout({
  218. link: 'https://docs.sentry.io/platforms/javascript/guides/sveltekit/user-feedback/#crash-report-modal',
  219. }),
  220. },
  221. ],
  222. verify: () => [],
  223. nextSteps: () => [],
  224. };
  225. const crashReportOnboarding: OnboardingConfig = {
  226. introduction: () => getCrashReportModalIntroduction(),
  227. install: (params: Params) => getCrashReportJavaScriptInstallStep(params),
  228. configure: () => [
  229. {
  230. type: StepType.CONFIGURE,
  231. description: getCrashReportModalConfigDescription({
  232. link: 'https://docs.sentry.io/platforms/javascript/guides/sveltekit/user-feedback/configuration/#crash-report-modal',
  233. }),
  234. additionalInfo: widgetCallout({
  235. link: 'https://docs.sentry.io/platforms/javascript/guides/sveltekit/user-feedback/#user-feedback-widget',
  236. }),
  237. },
  238. ],
  239. verify: () => [],
  240. nextSteps: () => [],
  241. };
  242. const docs: Docs = {
  243. onboarding,
  244. feedbackOnboardingNpm: feedbackOnboarding,
  245. replayOnboarding,
  246. customMetricsOnboarding: getJSMetricsOnboarding({getInstallConfig}),
  247. crashReportOnboarding,
  248. };
  249. export default docs;