nuxt.tsx 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  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 {MaybeBrowserProfilingBetaWarning} from 'sentry/components/onboarding/gettingStartedDoc/utils/profilingOnboarding';
  24. import {
  25. getReplayConfigureDescription,
  26. getReplaySDKSetupSnippet,
  27. getReplayVerifyStep,
  28. } from 'sentry/components/onboarding/gettingStartedDoc/utils/replayOnboarding';
  29. import {featureFlagOnboarding} from 'sentry/gettingStartedDocs/javascript/javascript';
  30. import {t, tct, tctCode} from 'sentry/locale';
  31. type Params = DocsParams;
  32. const getConfigStep = ({isSelfHosted, organization, projectSlug}: Params) => {
  33. const urlParam = isSelfHosted ? '--saas' : '--saas';
  34. return [
  35. {
  36. type: StepType.INSTALL,
  37. description: tct(
  38. 'Configure your app automatically by running the [wizardLink:Sentry wizard] in the root of your project.',
  39. {
  40. wizardLink: (
  41. <ExternalLink href="https://docs.sentry.io/platforms/javascript/guides/nuxt/#install" />
  42. ),
  43. }
  44. ),
  45. configurations: [
  46. {
  47. language: 'bash',
  48. code: `npx @sentry/wizard@latest -i nuxt ${urlParam} --org ${organization.slug} --project ${projectSlug}`,
  49. },
  50. ],
  51. },
  52. ];
  53. };
  54. const getInstallConfig = (params: Params) => [
  55. {
  56. type: StepType.INSTALL,
  57. configurations: getConfigStep(params),
  58. },
  59. ];
  60. const getVerifyNuxtSnippet = () => `
  61. <script setup>
  62. const triggerError = () => {
  63. throw new Error("Nuxt Button Error");
  64. };
  65. </script>
  66. <template>
  67. <button id="errorBtn" @click="triggerError">Trigger Error</button>
  68. </template>`;
  69. const onboarding: OnboardingConfig = {
  70. install: (params: Params) => [
  71. {
  72. title: t('Automatic Configuration (Recommended)'),
  73. configurations: getConfigStep(params),
  74. },
  75. ],
  76. configure: params => [
  77. {
  78. title: t('Manual Configuration'),
  79. collapsible: true,
  80. description: tct(
  81. 'Alternatively, you can also [manualSetupLink:set up the SDK manually], by following these steps:',
  82. {
  83. manualSetupLink: (
  84. <ExternalLink href="https://docs.sentry.io/platforms/javascript/guides/nuxt/manual-setup/" />
  85. ),
  86. }
  87. ),
  88. configurations: [
  89. {
  90. description: (
  91. <List symbol="bullet">
  92. <ListItem>
  93. {tctCode('Add [code:@sentry/nuxt/module] to your [code:nuxt.config.ts].')}
  94. </ListItem>
  95. <ListItem>
  96. {tctCode(
  97. 'Create or update [code:sentry.client.config.ts] and [code:sentry.server.config.ts] with the default [code:Sentry.init] call.'
  98. )}
  99. </ListItem>
  100. <ListItem>
  101. {tctCode(
  102. 'Configure source maps upload options in your [code:nuxt.config.ts].'
  103. )}
  104. </ListItem>
  105. </List>
  106. ),
  107. },
  108. {
  109. description: <CopyDsnField params={params} />,
  110. },
  111. ],
  112. },
  113. ],
  114. verify: () => [
  115. {
  116. type: StepType.VERIFY,
  117. description: (
  118. <Fragment>
  119. <p>
  120. {tctCode(
  121. 'Build and run your application and visit [code:/sentry-example-page] if you have set it up. Click the button to trigger a test error.'
  122. )}
  123. </p>
  124. <p>{t('Or, throw an error in a simple vue component.')}</p>
  125. </Fragment>
  126. ),
  127. configurations: [
  128. {
  129. code: [
  130. {
  131. label: 'Vue',
  132. value: 'vue',
  133. language: 'html',
  134. code: getVerifyNuxtSnippet(),
  135. },
  136. ],
  137. },
  138. ],
  139. additionalInfo: t(
  140. 'If you see an issue in your Sentry dashboard, you have successfully set up Sentry.'
  141. ),
  142. },
  143. ],
  144. nextSteps: () => [
  145. {
  146. id: 'nuxt-features',
  147. name: t('Nuxt Features'),
  148. description: t('Learn about our first class integration with the Nuxt framework.'),
  149. link: 'https://docs.sentry.io/platforms/javascript/guides/nuxt/features/',
  150. },
  151. ],
  152. };
  153. const replayOnboarding: OnboardingConfig = {
  154. install: (params: Params) => getInstallConfig(params),
  155. configure: (params: Params) => [
  156. {
  157. type: StepType.INSTALL,
  158. description: getReplayConfigureDescription({
  159. link: 'https://docs.sentry.io/platforms/javascript/guides/nuxt/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/nuxt";`,
  170. dsn: params.dsn.public,
  171. mask: params.replayOptions?.mask,
  172. block: params.replayOptions?.block,
  173. }),
  174. },
  175. ],
  176. },
  177. ],
  178. additionalInfo: <TracePropagationMessage />,
  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/nuxt]) 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/nuxt/user-feedback/configuration/',
  203. linkButton:
  204. 'https://docs.sentry.io/platforms/javascript/guides/nuxt/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/nuxt";`,
  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/nuxt/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/nuxt/user-feedback/configuration/#crash-report-modal',
  238. }),
  239. additionalInfo: widgetCallout({
  240. link: 'https://docs.sentry.io/platforms/javascript/guides/nuxt/user-feedback/#user-feedback-widget',
  241. }),
  242. },
  243. ],
  244. verify: () => [],
  245. nextSteps: () => [],
  246. };
  247. const profilingOnboarding: OnboardingConfig = {
  248. ...onboarding,
  249. introduction: params => <MaybeBrowserProfilingBetaWarning {...params} />,
  250. };
  251. const docs: Docs = {
  252. onboarding,
  253. feedbackOnboardingNpm: feedbackOnboarding,
  254. replayOnboarding,
  255. customMetricsOnboarding: getJSMetricsOnboarding({getInstallConfig}),
  256. crashReportOnboarding,
  257. profilingOnboarding,
  258. featureFlagOnboarding,
  259. };
  260. export default docs;