fastify.tsx 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. import ExternalLink from 'sentry/components/links/externalLink';
  2. import {StepType} from 'sentry/components/onboarding/gettingStartedDoc/step';
  3. import type {
  4. Docs,
  5. DocsParams,
  6. OnboardingConfig,
  7. } from 'sentry/components/onboarding/gettingStartedDoc/types';
  8. import {getUploadSourceMapsStep} from 'sentry/components/onboarding/gettingStartedDoc/utils';
  9. import {
  10. getCrashReportJavaScriptInstallStep,
  11. getCrashReportModalConfigDescription,
  12. getCrashReportModalIntroduction,
  13. } from 'sentry/components/onboarding/gettingStartedDoc/utils/feedbackOnboarding';
  14. import {
  15. feedbackOnboardingJsLoader,
  16. replayOnboardingJsLoader,
  17. } from 'sentry/gettingStartedDocs/javascript/jsLoader/jsLoader';
  18. import {t, tct} from 'sentry/locale';
  19. import {
  20. getImportInstrumentSnippet,
  21. getInstallConfig,
  22. getSdkInitSnippet,
  23. getSentryImportSnippet,
  24. } from 'sentry/utils/gettingStartedDocs/node';
  25. type Params = DocsParams;
  26. const getSdkSetupSnippet = () => `
  27. ${getImportInstrumentSnippet()}
  28. // All other imports below
  29. ${getSentryImportSnippet('node')}
  30. const Fastify = require('fastify')
  31. const app = Fastify();
  32. Sentry.setupFastifyErrorHandler(app);
  33. app.get("/", function rootHandler(req, res) {
  34. res.send("Hello world!");
  35. });
  36. app.listen(3000);
  37. `;
  38. const onboarding: OnboardingConfig = {
  39. introduction: () =>
  40. tct('In this quick guide you’ll use [strong:npm] or [strong:yarn] to set up:', {
  41. strong: <strong />,
  42. }),
  43. install: (params: Params) => [
  44. {
  45. type: StepType.INSTALL,
  46. description: t('Add the Sentry Node SDK as a dependency:'),
  47. configurations: getInstallConfig(params),
  48. },
  49. ],
  50. configure: (params: Params) => [
  51. {
  52. type: StepType.CONFIGURE,
  53. description: t(
  54. "Initialize Sentry as early as possible in your application's lifecycle."
  55. ),
  56. configurations: [
  57. {
  58. description: tct(
  59. 'To initialize the SDK before everything else, create an external file called [code:instrument.js/mjs].',
  60. {code: <code />}
  61. ),
  62. code: [
  63. {
  64. label: 'JavaScript',
  65. value: 'javascript',
  66. language: 'javascript',
  67. filename: 'instrument.(js|mjs)',
  68. code: getSdkInitSnippet(params, 'node'),
  69. },
  70. ],
  71. },
  72. {
  73. description: tct(
  74. "Make sure to import [code:instrument.js/mjs] at the top of your file. Set up the error handler. This setup is typically done in your application's entry point file, which is usually [code:index.(js|ts)]. If you're running your application in ESM mode, or looking for alternative ways to set up Sentry, read about [docs:installation methods in our docs].",
  75. {
  76. code: <code />,
  77. docs: (
  78. <ExternalLink href="https://docs.sentry.io/platforms/javascript/guides/fastify/install/" />
  79. ),
  80. }
  81. ),
  82. code: [
  83. {
  84. label: 'JavaScript',
  85. value: 'javascript',
  86. language: 'javascript',
  87. filename: 'index.(js|mjs)',
  88. code: getSdkSetupSnippet(),
  89. },
  90. ],
  91. },
  92. ],
  93. },
  94. getUploadSourceMapsStep({
  95. guideLink: 'https://docs.sentry.io/platforms/javascript/guides/fastify/sourcemaps/',
  96. ...params,
  97. }),
  98. ],
  99. verify: () => [
  100. {
  101. type: StepType.VERIFY,
  102. description: t(
  103. "This snippet contains an intentional error and can be used as a test to make sure that everything's working as expected."
  104. ),
  105. configurations: [
  106. {
  107. language: 'javascript',
  108. code: `
  109. app.get("/debug-sentry", function mainHandler(req, res) {
  110. throw new Error("My first Sentry error!");
  111. });
  112. `,
  113. },
  114. ],
  115. },
  116. ],
  117. };
  118. const crashReportOnboarding: OnboardingConfig = {
  119. introduction: () => getCrashReportModalIntroduction(),
  120. install: (params: Params) => getCrashReportJavaScriptInstallStep(params),
  121. configure: () => [
  122. {
  123. type: StepType.CONFIGURE,
  124. description: getCrashReportModalConfigDescription({
  125. link: 'https://docs.sentry.io/platforms/javascript/guides/express/user-feedback/configuration/#crash-report-modal',
  126. }),
  127. },
  128. ],
  129. verify: () => [],
  130. nextSteps: () => [],
  131. };
  132. const docs: Docs = {
  133. onboarding,
  134. replayOnboardingJsLoader,
  135. crashReportOnboarding,
  136. feedbackOnboardingJsLoader,
  137. };
  138. export default docs;