connect.tsx 3.8 KB

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