nextjs.tsx 5.4 KB

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