fastify.tsx 4.5 KB

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