sveltekit.tsx 8.4 KB

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