nextjs.tsx 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  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 {StepType} from 'sentry/components/onboarding/gettingStartedDoc/step';
  7. import {
  8. Docs,
  9. DocsParams,
  10. OnboardingConfig,
  11. } from 'sentry/components/onboarding/gettingStartedDoc/types';
  12. import {
  13. getReplayConfigureDescription,
  14. getReplaySDKSetupSnippet,
  15. } from 'sentry/components/onboarding/gettingStartedDoc/utils';
  16. import {getJSMetricsOnboarding} from 'sentry/components/onboarding/gettingStartedDoc/utils/metricsOnboarding';
  17. import TextCopyInput from 'sentry/components/textCopyInput';
  18. import {t, tct} from 'sentry/locale';
  19. import {space} from 'sentry/styles/space';
  20. import {trackAnalytics} from 'sentry/utils/analytics';
  21. type Params = DocsParams;
  22. const getInstallConfig = () => [
  23. {
  24. description: tct(
  25. 'Configure your app automatically with the [wizardLink:Sentry wizard].',
  26. {
  27. wizardLink: (
  28. <ExternalLink href="https://docs.sentry.io/platforms/javascript/guides/nextjs/#install" />
  29. ),
  30. }
  31. ),
  32. language: 'bash',
  33. code: `npx @sentry/wizard@latest -i nextjs`,
  34. },
  35. ];
  36. const getManualInstallConfig = () => [
  37. {
  38. language: 'bash',
  39. code: [
  40. {
  41. label: 'npm',
  42. value: 'npm',
  43. language: 'bash',
  44. code: 'npm install --save @sentry/nextjs',
  45. },
  46. {
  47. label: 'yarn',
  48. value: 'yarn',
  49. language: 'bash',
  50. code: 'yarn add @sentry/nextjs',
  51. },
  52. ],
  53. },
  54. ];
  55. const onboarding: OnboardingConfig = {
  56. install: (params: Params) => [
  57. {
  58. type: StepType.INSTALL,
  59. configurations: getInstallConfig(),
  60. additionalInfo: (
  61. <Fragment>
  62. {t(
  63. 'The Sentry wizard will automatically patch your application to configure the Sentry SDK:'
  64. )}
  65. <List symbol="bullet">
  66. <ListItem>
  67. {tct(
  68. 'Create [clientCode:sentry.client.config.js] and [serverCode:sentry.server.config.js] with the default [sentryInitCode:Sentry.init].',
  69. {
  70. clientCode: <code />,
  71. serverCode: <code />,
  72. sentryInitCode: <code />,
  73. }
  74. )}
  75. </ListItem>
  76. <ListItem>
  77. {tct(
  78. 'Create or update your Next.js config [nextConfig:next.config.js] with the default Sentry configuration.',
  79. {
  80. nextConfig: <code />,
  81. }
  82. )}
  83. </ListItem>
  84. <ListItem>
  85. {tct(
  86. 'Create [sentryClircCode:.sentryclirc] and [sentryPropertiesCode:sentry.properties] files with configuration for sentry-cli (which is used when automatically uploading source maps).',
  87. {
  88. sentryClircCode: <code />,
  89. sentryPropertiesCode: <code />,
  90. }
  91. )}
  92. </ListItem>
  93. <ListItem>
  94. {tct('Add an example page to your app to verify your Sentry setup.', {
  95. sentryClircCode: <code />,
  96. })}
  97. </ListItem>
  98. </List>
  99. <br />
  100. <ManualSetupTitle>{t('Manual Setup')}</ManualSetupTitle>
  101. <p>
  102. {tct(
  103. 'Alternatively, you can also [manualSetupLink:set up the SDK manually].',
  104. {
  105. manualSetupLink: (
  106. <ExternalLink href="https://docs.sentry.io/platforms/javascript/guides/nextjs/manual-setup/" />
  107. ),
  108. }
  109. )}
  110. </p>
  111. <br />
  112. <DSNText>
  113. <p>
  114. {tct(
  115. "If you already have the configuration for Sentry in your application, and just need this project's ([projectSlug]) DSN, you can find it below:",
  116. {
  117. projectSlug: <code>{params.projectSlug}</code>,
  118. }
  119. )}
  120. </p>
  121. </DSNText>
  122. {params.organization && (
  123. <TextCopyInput
  124. onCopy={() =>
  125. trackAnalytics('onboarding.nextjs-dsn-copied', {
  126. organization: params.organization,
  127. })
  128. }
  129. >
  130. {params.dsn}
  131. </TextCopyInput>
  132. )}
  133. </Fragment>
  134. ),
  135. },
  136. ],
  137. configure: () => [],
  138. verify: () => [],
  139. };
  140. const replayOnboarding: OnboardingConfig = {
  141. install: () => [{type: StepType.INSTALL, configurations: getInstallConfig()}],
  142. configure: (params: Params) => [
  143. {
  144. type: StepType.CONFIGURE,
  145. description: getReplayConfigureDescription({
  146. link: 'https://docs.sentry.io/platforms/javascript/guides/nextjs/session-replay/',
  147. }),
  148. configurations: [
  149. {
  150. code: [
  151. {
  152. label: 'JavaScript',
  153. value: 'javascript',
  154. language: 'javascript',
  155. code: getReplaySDKSetupSnippet({
  156. importStatement: `import * as Sentry from "@sentry/nextjs";`,
  157. dsn: params.dsn,
  158. mask: params.replayOptions?.mask,
  159. block: params.replayOptions?.block,
  160. }),
  161. },
  162. ],
  163. },
  164. ],
  165. additionalInfo: tct(
  166. '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.',
  167. {sentryClient: <code />, sentryServer: <code />, sentryEdge: <code />}
  168. ),
  169. },
  170. ],
  171. verify: () => [],
  172. nextSteps: () => [],
  173. };
  174. const docs: Docs = {
  175. onboarding,
  176. replayOnboardingNpm: replayOnboarding,
  177. customMetricsOnboarding: getJSMetricsOnboarding({
  178. getInstallConfig: getManualInstallConfig,
  179. }),
  180. };
  181. export default docs;
  182. const DSNText = styled('div')`
  183. margin-bottom: ${space(0.5)};
  184. `;
  185. const ManualSetupTitle = styled('p')`
  186. font-size: ${p => p.theme.fontSizeLarge};
  187. font-weight: bold;
  188. `;