nextjs.tsx 6.2 KB

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