nuxt.tsx 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  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 {MaybeBrowserProfilingBetaWarning} from 'sentry/components/onboarding/gettingStartedDoc/utils/profilingOnboarding';
  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, tctCode} from 'sentry/locale';
  30. type Params = DocsParams;
  31. const getConfigStep = ({isSelfHosted, organization, projectSlug}: Params) => {
  32. const urlParam = isSelfHosted ? '--saas' : '--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/nuxt/#install" />
  41. ),
  42. }
  43. ),
  44. configurations: [
  45. {
  46. language: 'bash',
  47. code: `npx @sentry/wizard@latest -i nuxt ${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 getVerifyNuxtSnippet = () => `
  60. <script setup>
  61. const triggerError = () => {
  62. throw new Error("Nuxt Button Error");
  63. };
  64. </script>
  65. <template>
  66. <button id="errorBtn" @click="triggerError">Trigger Error</button>
  67. </template>`;
  68. const onboarding: OnboardingConfig = {
  69. install: (params: Params) => [
  70. {
  71. title: t('Automatic Configuration (Recommended)'),
  72. configurations: getConfigStep(params),
  73. },
  74. ],
  75. configure: () => [
  76. {
  77. title: t('Manual Configuration'),
  78. collapsible: true,
  79. description: tct(
  80. 'Alternatively, you can also [manualSetupLink:set up the SDK manually], by following these steps:',
  81. {
  82. manualSetupLink: (
  83. <ExternalLink href="https://docs.sentry.io/platforms/javascript/guides/nuxt/manual-setup/" />
  84. ),
  85. }
  86. ),
  87. configurations: [
  88. {
  89. description: (
  90. <List symbol="bullet">
  91. <ListItem>
  92. {tctCode('Add [code:@sentry/nuxt/module] to your [code:nuxt.config.ts].')}
  93. </ListItem>
  94. <ListItem>
  95. {tctCode(
  96. 'Create or update [code:sentry.client.config.ts] and [code:sentry.server.config.ts] with the default [code:Sentry.init] call.'
  97. )}
  98. </ListItem>
  99. <ListItem>
  100. {tctCode(
  101. 'Configure source maps upload options in your [code:nuxt.config.ts].'
  102. )}
  103. </ListItem>
  104. </List>
  105. ),
  106. },
  107. ],
  108. },
  109. ],
  110. verify: () => [
  111. {
  112. type: StepType.VERIFY,
  113. description: (
  114. <Fragment>
  115. <p>
  116. {tctCode(
  117. '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.'
  118. )}
  119. </p>
  120. <p>{t('Or, throw an error in a simple vue component.')}</p>
  121. </Fragment>
  122. ),
  123. configurations: [
  124. {
  125. code: [
  126. {
  127. label: 'Vue',
  128. value: 'vue',
  129. language: 'html',
  130. code: getVerifyNuxtSnippet(),
  131. },
  132. ],
  133. },
  134. ],
  135. additionalInfo: t(
  136. 'If you see an issue in your Sentry dashboard, you have successfully set up Sentry.'
  137. ),
  138. },
  139. ],
  140. nextSteps: () => [
  141. {
  142. id: 'nuxt-features',
  143. name: t('Nuxt Features'),
  144. description: t('Learn about our first class integration with the Nuxt framework.'),
  145. link: 'https://docs.sentry.io/platforms/javascript/guides/nuxt/features/',
  146. },
  147. ],
  148. };
  149. const replayOnboarding: OnboardingConfig = {
  150. install: (params: Params) => getInstallConfig(params),
  151. configure: (params: Params) => [
  152. {
  153. type: StepType.INSTALL,
  154. description: getReplayConfigureDescription({
  155. link: 'https://docs.sentry.io/platforms/javascript/guides/nuxt/session-replay/',
  156. }),
  157. configurations: [
  158. {
  159. code: [
  160. {
  161. label: 'JavaScript',
  162. value: 'javascript',
  163. language: 'javascript',
  164. code: getReplaySDKSetupSnippet({
  165. importStatement: `import * as Sentry from "@sentry/nuxt";`,
  166. dsn: params.dsn.public,
  167. mask: params.replayOptions?.mask,
  168. block: params.replayOptions?.block,
  169. }),
  170. },
  171. ],
  172. },
  173. ],
  174. additionalInfo: <TracePropagationMessage />,
  175. },
  176. ],
  177. verify: getReplayVerifyStep(),
  178. nextSteps: () => [],
  179. };
  180. const feedbackOnboarding: OnboardingConfig = {
  181. install: (params: Params) => [
  182. {
  183. type: StepType.INSTALL,
  184. description: tct(
  185. '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.',
  186. {
  187. code: <code />,
  188. }
  189. ),
  190. configurations: getInstallConfig(params),
  191. },
  192. ],
  193. configure: (params: Params) => [
  194. {
  195. type: StepType.CONFIGURE,
  196. description: getFeedbackConfigureDescription({
  197. linkConfig:
  198. 'https://docs.sentry.io/platforms/javascript/guides/nuxt/user-feedback/configuration/',
  199. linkButton:
  200. 'https://docs.sentry.io/platforms/javascript/guides/nuxt/user-feedback/configuration/#bring-your-own-button',
  201. }),
  202. configurations: [
  203. {
  204. code: [
  205. {
  206. label: 'JavaScript',
  207. value: 'javascript',
  208. language: 'javascript',
  209. code: getFeedbackSDKSetupSnippet({
  210. importStatement: `import * as Sentry from "@sentry/nuxt";`,
  211. dsn: params.dsn.public,
  212. feedbackOptions: params.feedbackOptions,
  213. }),
  214. },
  215. ],
  216. },
  217. ],
  218. additionalInfo: crashReportCallout({
  219. link: 'https://docs.sentry.io/platforms/javascript/guides/nuxt/user-feedback/#crash-report-modal',
  220. }),
  221. },
  222. ],
  223. verify: () => [],
  224. nextSteps: () => [],
  225. };
  226. const crashReportOnboarding: OnboardingConfig = {
  227. introduction: () => getCrashReportModalIntroduction(),
  228. install: (params: Params) => getCrashReportJavaScriptInstallStep(params),
  229. configure: () => [
  230. {
  231. type: StepType.CONFIGURE,
  232. description: getCrashReportModalConfigDescription({
  233. link: 'https://docs.sentry.io/platforms/javascript/guides/nuxt/user-feedback/configuration/#crash-report-modal',
  234. }),
  235. additionalInfo: widgetCallout({
  236. link: 'https://docs.sentry.io/platforms/javascript/guides/nuxt/user-feedback/#user-feedback-widget',
  237. }),
  238. },
  239. ],
  240. verify: () => [],
  241. nextSteps: () => [],
  242. };
  243. const profilingOnboarding: OnboardingConfig = {
  244. ...onboarding,
  245. introduction: params => <MaybeBrowserProfilingBetaWarning {...params} />,
  246. };
  247. const docs: Docs = {
  248. onboarding,
  249. feedbackOnboardingNpm: feedbackOnboarding,
  250. replayOnboarding,
  251. customMetricsOnboarding: getJSMetricsOnboarding({getInstallConfig}),
  252. crashReportOnboarding,
  253. profilingOnboarding,
  254. featureFlagOnboarding: featureFlagOnboarding,
  255. };
  256. export default docs;