nextjs.tsx 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. import {Fragment} from 'react';
  2. import styled from '@emotion/styled';
  3. import ExternalLink from 'sentry/components/links/externalLink';
  4. import List from 'sentry/components/list/';
  5. import ListItem from 'sentry/components/list/listItem';
  6. import crashReportCallout from 'sentry/components/onboarding/gettingStartedDoc/feedback/crashReportCallout';
  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. getFeedbackConfigureDescription,
  16. getFeedbackSDKSetupSnippet,
  17. } from 'sentry/components/onboarding/gettingStartedDoc/utils/feedbackOnboarding';
  18. import {getJSMetricsOnboarding} from 'sentry/components/onboarding/gettingStartedDoc/utils/metricsOnboarding';
  19. import {
  20. getReplayConfigureDescription,
  21. getReplaySDKSetupSnippet,
  22. } from 'sentry/components/onboarding/gettingStartedDoc/utils/replayOnboarding';
  23. import TextCopyInput from 'sentry/components/textCopyInput';
  24. import {t, tct} from 'sentry/locale';
  25. import {space} from 'sentry/styles/space';
  26. import {trackAnalytics} from 'sentry/utils/analytics';
  27. type Params = DocsParams;
  28. const getInstallConfig = () => [
  29. {
  30. description: tct(
  31. 'Configure your app automatically with the [wizardLink:Sentry wizard].',
  32. {
  33. wizardLink: (
  34. <ExternalLink href="https://docs.sentry.io/platforms/javascript/guides/nextjs/#install" />
  35. ),
  36. }
  37. ),
  38. language: 'bash',
  39. code: `npx @sentry/wizard@latest -i nextjs`,
  40. },
  41. ];
  42. const getManualInstallConfig = () => [
  43. {
  44. language: 'bash',
  45. code: [
  46. {
  47. label: 'npm',
  48. value: 'npm',
  49. language: 'bash',
  50. code: 'npm install --save @sentry/nextjs',
  51. },
  52. {
  53. label: 'yarn',
  54. value: 'yarn',
  55. language: 'bash',
  56. code: 'yarn add @sentry/nextjs',
  57. },
  58. ],
  59. },
  60. ];
  61. const onboarding: OnboardingConfig = {
  62. install: (params: Params) => [
  63. {
  64. type: StepType.INSTALL,
  65. configurations: getInstallConfig(),
  66. additionalInfo: (
  67. <Fragment>
  68. {t(
  69. 'The Sentry wizard will automatically patch your application to configure the Sentry SDK:'
  70. )}
  71. <List symbol="bullet">
  72. <ListItem>
  73. {tct(
  74. 'Create [clientCode:sentry.client.config.js] and [serverCode:sentry.server.config.js] with the default [sentryInitCode:Sentry.init].',
  75. {
  76. clientCode: <code />,
  77. serverCode: <code />,
  78. sentryInitCode: <code />,
  79. }
  80. )}
  81. </ListItem>
  82. <ListItem>
  83. {tct(
  84. 'Create or update your Next.js config [nextConfig:next.config.js] with the default Sentry configuration.',
  85. {
  86. nextConfig: <code />,
  87. }
  88. )}
  89. </ListItem>
  90. <ListItem>
  91. {tct(
  92. 'Create [sentryClircCode:.sentryclirc] and [sentryPropertiesCode:sentry.properties] files with configuration for sentry-cli (which is used when automatically uploading source maps).',
  93. {
  94. sentryClircCode: <code />,
  95. sentryPropertiesCode: <code />,
  96. }
  97. )}
  98. </ListItem>
  99. <ListItem>
  100. {tct('Add an example page to your app to verify your Sentry setup.', {
  101. sentryClircCode: <code />,
  102. })}
  103. </ListItem>
  104. </List>
  105. <br />
  106. <ManualSetupTitle>{t('Manual Setup')}</ManualSetupTitle>
  107. <p>
  108. {tct(
  109. 'Alternatively, you can also [manualSetupLink:set up the SDK manually].',
  110. {
  111. manualSetupLink: (
  112. <ExternalLink href="https://docs.sentry.io/platforms/javascript/guides/nextjs/manual-setup/" />
  113. ),
  114. }
  115. )}
  116. </p>
  117. <br />
  118. <DSNText>
  119. <p>
  120. {tct(
  121. "If you already have the configuration for Sentry in your application, and just need this project's ([projectSlug]) DSN, you can find it below:",
  122. {
  123. projectSlug: <code>{params.projectSlug}</code>,
  124. }
  125. )}
  126. </p>
  127. </DSNText>
  128. {params.organization && (
  129. <TextCopyInput
  130. onCopy={() =>
  131. trackAnalytics('onboarding.nextjs-dsn-copied', {
  132. organization: params.organization,
  133. })
  134. }
  135. >
  136. {params.dsn}
  137. </TextCopyInput>
  138. )}
  139. </Fragment>
  140. ),
  141. },
  142. ],
  143. configure: () => [],
  144. verify: () => [],
  145. };
  146. const replayOnboarding: OnboardingConfig = {
  147. install: () => [{type: StepType.INSTALL, configurations: getInstallConfig()}],
  148. configure: (params: Params) => [
  149. {
  150. type: StepType.CONFIGURE,
  151. description: getReplayConfigureDescription({
  152. link: 'https://docs.sentry.io/platforms/javascript/guides/nextjs/session-replay/',
  153. }),
  154. configurations: [
  155. {
  156. code: [
  157. {
  158. label: 'JavaScript',
  159. value: 'javascript',
  160. language: 'javascript',
  161. code: getReplaySDKSetupSnippet({
  162. importStatement: `import * as Sentry from "@sentry/nextjs";`,
  163. dsn: params.dsn,
  164. mask: params.replayOptions?.mask,
  165. block: params.replayOptions?.block,
  166. }),
  167. },
  168. ],
  169. },
  170. ],
  171. additionalInfo: (
  172. <Fragment>
  173. <TracePropagationMessage />
  174. {tct(
  175. 'Alert: The Replay integration must be added to your [sentryClient:sentry.client.config.js] file. Adding it into [sentryServer:sentry.server.config.js] or [sentryEdge:sentry.edge.config.js] may break your build.',
  176. {sentryClient: <code />, sentryServer: <code />, sentryEdge: <code />}
  177. )}
  178. </Fragment>
  179. ),
  180. },
  181. ],
  182. verify: () => [],
  183. nextSteps: () => [],
  184. };
  185. const feedbackOnboarding: OnboardingConfig = {
  186. install: () => [
  187. {
  188. type: StepType.INSTALL,
  189. description: tct(
  190. 'For the User Feedback integration to work, you must have the Sentry browser SDK package, or an equivalent framework SDK (e.g. [code:@sentry/nextjs]) installed, minimum version 7.85.0.',
  191. {
  192. code: <code />,
  193. }
  194. ),
  195. configurations: getInstallConfig(),
  196. },
  197. ],
  198. configure: (params: Params) => [
  199. {
  200. type: StepType.CONFIGURE,
  201. description: getFeedbackConfigureDescription({
  202. linkConfig:
  203. 'https://docs.sentry.io/platforms/javascript/guides/nextjs/user-feedback/configuration/',
  204. linkButton:
  205. 'https://docs.sentry.io/platforms/javascript/guides/nextjs/user-feedback/configuration/#bring-your-own-button',
  206. }),
  207. configurations: [
  208. {
  209. code: [
  210. {
  211. label: 'JavaScript',
  212. value: 'javascript',
  213. language: 'javascript',
  214. code: getFeedbackSDKSetupSnippet({
  215. importStatement: `import * as Sentry from "@sentry/nextjs";`,
  216. dsn: params.dsn,
  217. feedbackOptions: params.feedbackOptions,
  218. }),
  219. },
  220. ],
  221. },
  222. ],
  223. additionalInfo: crashReportCallout({
  224. link: 'https://docs.sentry.io/platforms/javascript/guides/nextjs/user-feedback/#crash-report-modal',
  225. }),
  226. },
  227. ],
  228. verify: () => [],
  229. nextSteps: () => [],
  230. };
  231. const docs: Docs = {
  232. onboarding,
  233. feedbackOnboardingNpm: feedbackOnboarding,
  234. replayOnboardingNpm: replayOnboarding,
  235. customMetricsOnboarding: getJSMetricsOnboarding({
  236. getInstallConfig: getManualInstallConfig,
  237. }),
  238. };
  239. export default docs;
  240. const DSNText = styled('div')`
  241. margin-bottom: ${space(0.5)};
  242. `;
  243. const ManualSetupTitle = styled('p')`
  244. font-size: ${p => p.theme.fontSizeLarge};
  245. font-weight: bold;
  246. `;