fastify.tsx 4.6 KB

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