nextjs.tsx 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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 {Layout, LayoutProps} from 'sentry/components/onboarding/gettingStartedDoc/layout';
  7. import {ModuleProps} from 'sentry/components/onboarding/gettingStartedDoc/sdkDocumentation';
  8. import {StepType} from 'sentry/components/onboarding/gettingStartedDoc/step';
  9. import TextCopyInput from 'sentry/components/textCopyInput';
  10. import {t, tct} from 'sentry/locale';
  11. import {space} from 'sentry/styles/space';
  12. import {Organization} from 'sentry/types';
  13. import {trackAnalytics} from 'sentry/utils/analytics';
  14. type Props = {
  15. dsn: string;
  16. organization: Organization | undefined;
  17. projectSlug: string;
  18. };
  19. export const steps = ({dsn, projectSlug, organization}: Props): LayoutProps['steps'] => [
  20. {
  21. type: StepType.INSTALL,
  22. description: (
  23. <p>
  24. {tct('Configure your app automatically with the [wizardLink:Sentry wizard].', {
  25. wizardLink: (
  26. <ExternalLink href="https://docs.sentry.io/platforms/javascript/guides/nextjs/#install" />
  27. ),
  28. })}
  29. </p>
  30. ),
  31. configurations: [
  32. {
  33. language: 'bash',
  34. code: `npx @sentry/wizard@latest -i nextjs`,
  35. },
  36. ],
  37. additionalInfo: (
  38. <Fragment>
  39. {t(
  40. 'The Sentry wizard will automatically patch your application to configure the Sentry SDK:'
  41. )}
  42. <List symbol="bullet">
  43. <ListItem>
  44. {tct(
  45. 'Create [clientCode:sentry.client.config.js] and [serverCode:sentry.server.config.js] with the default [sentryInitCode:Sentry.init].',
  46. {
  47. clientCode: <code />,
  48. serverCode: <code />,
  49. sentryInitCode: <code />,
  50. }
  51. )}
  52. </ListItem>
  53. <ListItem>
  54. {tct(
  55. 'Create or update your Next.js config [nextConfig:next.config.js] with the default Sentry configuration.',
  56. {
  57. nextConfig: <code />,
  58. }
  59. )}
  60. </ListItem>
  61. <ListItem>
  62. {tct(
  63. 'Create [sentryClircCode:.sentryclirc] and [sentryPropertiesCode:sentry.properties] files with configuration for sentry-cli (which is used when automatically uploading source maps).',
  64. {
  65. sentryClircCode: <code />,
  66. sentryPropertiesCode: <code />,
  67. }
  68. )}
  69. </ListItem>
  70. <ListItem>
  71. {tct('Add an example page to your app to verify your Sentry setup.', {
  72. sentryClircCode: <code />,
  73. })}
  74. </ListItem>
  75. </List>
  76. <br />
  77. <ManualSetupTitle>{t('Manual Setup')}</ManualSetupTitle>
  78. <p>
  79. {tct('Alternatively, you can also [manualSetupLink:set up the SDK manually].', {
  80. manualSetupLink: (
  81. <ExternalLink href="https://docs.sentry.io/platforms/javascript/guides/nextjs/manual-setup/" />
  82. ),
  83. })}
  84. </p>
  85. <br />
  86. <DSNText>
  87. <p>
  88. {tct(
  89. "If you already have the configuration for Sentry in your application, and just need this project's ([projectSlug]) DSN, you can find it below:",
  90. {
  91. projectSlug: <code>{projectSlug}</code>,
  92. }
  93. )}
  94. </p>
  95. </DSNText>
  96. {organization && (
  97. <TextCopyInput
  98. onCopy={() => trackAnalytics('onboarding.nextjs-dsn-copied', {organization})}
  99. >
  100. {dsn}
  101. </TextCopyInput>
  102. )}
  103. </Fragment>
  104. ),
  105. },
  106. ];
  107. // Configuration End
  108. export function GettingStartedWithNextJs({...props}: ModuleProps) {
  109. const {projectSlug, dsn, organization} = props;
  110. return <Layout steps={steps({dsn, projectSlug, organization})} {...props} />;
  111. }
  112. export default GettingStartedWithNextJs;
  113. const DSNText = styled('div')`
  114. margin-bottom: ${space(0.5)};
  115. `;
  116. const ManualSetupTitle = styled('p')`
  117. font-size: ${p => p.theme.fontSizeLarge};
  118. font-weight: bold;
  119. `;