connect.tsx 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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 {t, tct} from 'sentry/locale';
  16. import {
  17. getImportInstrumentSnippet,
  18. getInstallConfig,
  19. getSdkInitSnippet,
  20. getSentryImportSnippet,
  21. } from 'sentry/utils/gettingStartedDocs/node';
  22. type Params = DocsParams;
  23. const getSdkSetupSnippet = () => `
  24. ${getImportInstrumentSnippet()}
  25. // All other imports below
  26. ${getSentryImportSnippet('node')}
  27. const connect = require("connect");
  28. const app = connect();
  29. Sentry.setupConnectErrorHandler(app);
  30. // All your controllers should live here
  31. app.listen(3000);
  32. `;
  33. const onboarding: OnboardingConfig = {
  34. install: params => [
  35. {
  36. type: StepType.INSTALL,
  37. description: t('Add the Sentry Node SDK as a dependency:'),
  38. configurations: getInstallConfig(params),
  39. },
  40. ],
  41. configure: params => [
  42. {
  43. type: StepType.CONFIGURE,
  44. description: t(
  45. "Initialize Sentry as early as possible in your application's lifecycle. Otherwise, auto-instrumentation will not work."
  46. ),
  47. configurations: [
  48. {
  49. description: tct(
  50. 'To initialize the SDK before everything else, create an external file called [code:instrument.js/mjs].',
  51. {code: <code />}
  52. ),
  53. code: [
  54. {
  55. label: 'JavaScript',
  56. value: 'javascript',
  57. language: 'javascript',
  58. filename: 'instrument.(js|mjs)',
  59. code: getSdkInitSnippet(params, 'node'),
  60. },
  61. ],
  62. },
  63. {
  64. description: tct(
  65. "Make sure to import [code1:instrument.js/mjs] at the top of your file. Set up the error handler after all controllers and before any other error middleware. This setup is typically done in your application's entry point file, which is usually [code2: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].",
  66. {
  67. code1: <code />,
  68. code2: <code />,
  69. docs: (
  70. <ExternalLink href="https://docs.sentry.io/platforms/javascript/guides/connect/install/" />
  71. ),
  72. }
  73. ),
  74. code: [
  75. {
  76. label: 'JavaScript',
  77. value: 'javascript',
  78. language: 'javascript',
  79. filename: 'index.(js|mjs)',
  80. code: getSdkSetupSnippet(),
  81. },
  82. ],
  83. },
  84. ],
  85. },
  86. getUploadSourceMapsStep({
  87. guideLink: 'https://docs.sentry.io/platforms/javascript/guides/connect/sourcemaps/',
  88. ...params,
  89. }),
  90. ],
  91. verify: () => [
  92. {
  93. type: StepType.VERIFY,
  94. description: t(
  95. "This snippet contains an intentional error and can be used as a test to make sure that everything's working as expected."
  96. ),
  97. configurations: [
  98. {
  99. language: 'javascript',
  100. code: getVerifySnippet(),
  101. },
  102. ],
  103. },
  104. ],
  105. };
  106. const getVerifySnippet = () => `
  107. app.use(async function () {
  108. throw new Error("My first Sentry error!");
  109. });
  110. `;
  111. const crashReportOnboarding: OnboardingConfig = {
  112. introduction: () => getCrashReportModalIntroduction(),
  113. install: (params: Params) => getCrashReportJavaScriptInstallStep(params),
  114. configure: () => [
  115. {
  116. type: StepType.CONFIGURE,
  117. description: getCrashReportModalConfigDescription({
  118. link: 'https://docs.sentry.io/platforms/javascript/guides/connect/user-feedback/configuration/#crash-report-modal',
  119. }),
  120. },
  121. ],
  122. verify: () => [],
  123. nextSteps: () => [],
  124. };
  125. const docs: Docs = {
  126. onboarding,
  127. customMetricsOnboarding: getJSServerMetricsOnboarding(),
  128. crashReportOnboarding,
  129. };
  130. export default docs;