nestjs.tsx 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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. getCrashReportApiIntroduction,
  11. getCrashReportInstallDescription,
  12. getCrashReportJavaScriptInstallStep,
  13. getCrashReportModalConfigDescription,
  14. getCrashReportModalIntroduction,
  15. } from 'sentry/components/onboarding/gettingStartedDoc/utils/feedbackOnboarding';
  16. import {getJSServerMetricsOnboarding} from 'sentry/components/onboarding/gettingStartedDoc/utils/metricsOnboarding';
  17. import {t, tct} from 'sentry/locale';
  18. import {
  19. getImportInstrumentSnippet,
  20. getInstallConfig,
  21. getSdkInitSnippet,
  22. getSentryImportSnippet,
  23. } from 'sentry/utils/gettingStartedDocs/node';
  24. type Params = DocsParams;
  25. const getSdkSetupSnippet = () => `
  26. ${getImportInstrumentSnippet('esm')}
  27. // All other imports below
  28. ${getSentryImportSnippet('node', 'esm')}
  29. import { BaseExceptionFilter, HttpAdapterHost, NestFactory } from '@nestjs/core';
  30. import { AppModule } from './app.module';
  31. async function bootstrap() {
  32. const app = await NestFactory.create(AppModule);
  33. const { httpAdapter } = app.get(HttpAdapterHost);
  34. Sentry.setupNestErrorHandler(app, new BaseExceptionFilter(httpAdapter));
  35. await app.listen(3000);
  36. }
  37. bootstrap();
  38. `;
  39. const getVerifySnippet = () => `
  40. app.use(async function () {
  41. throw new Error("My first Sentry error!");
  42. });
  43. `;
  44. const onboarding: OnboardingConfig = {
  45. install: params => [
  46. {
  47. type: StepType.INSTALL,
  48. description: t('Add the Sentry Node SDK as a dependency:'),
  49. configurations: getInstallConfig(params),
  50. },
  51. ],
  52. configure: params => [
  53. {
  54. type: StepType.CONFIGURE,
  55. description: t(
  56. "Initialize Sentry as early as possible in your application's lifecycle. Otherwise, auto-instrumentation will not work."
  57. ),
  58. configurations: [
  59. {
  60. description: tct(
  61. 'To initialize the SDK before everything else, create an external file called [code:instrument.js/mjs].',
  62. {code: <code />}
  63. ),
  64. code: [
  65. {
  66. label: 'JavaScript',
  67. value: 'javascript',
  68. language: 'javascript',
  69. filename: 'instrument.(js|ts)',
  70. code: getSdkInitSnippet(params, 'node', 'esm'),
  71. },
  72. ],
  73. },
  74. {
  75. description: tct(
  76. 'Make sure to import [code1:instrument.js/mjs] at the top of your [code2:main.ts/js] file. Set up the error handler by passing the [code3:BaseExceptionFilter].',
  77. {
  78. code1: <code />,
  79. code2: <code />,
  80. code3: <code />,
  81. docs: (
  82. <ExternalLink href="https://docs.sentry.io/platforms/javascript/guides/koa/install/" />
  83. ),
  84. }
  85. ),
  86. code: [
  87. {
  88. label: 'JavaScript',
  89. value: 'javascript',
  90. language: 'javascript',
  91. filename: 'main.(js|ts)',
  92. code: getSdkSetupSnippet(),
  93. },
  94. ],
  95. },
  96. ],
  97. },
  98. getUploadSourceMapsStep({
  99. guideLink: 'https://docs.sentry.io/platforms/javascript/guides/hapi/sourcemaps/',
  100. ...params,
  101. }),
  102. ],
  103. verify: () => [
  104. {
  105. type: StepType.VERIFY,
  106. description: t(
  107. "This snippet contains an intentional error and can be used as a test to make sure that everything's working as expected."
  108. ),
  109. configurations: [
  110. {
  111. language: 'javascript',
  112. code: getVerifySnippet(),
  113. },
  114. ],
  115. },
  116. ],
  117. };
  118. const feedbackOnboardingNode: OnboardingConfig = {
  119. introduction: () => getCrashReportApiIntroduction(),
  120. install: () => [
  121. {
  122. type: StepType.INSTALL,
  123. description: getCrashReportInstallDescription(),
  124. configurations: [
  125. {
  126. code: [
  127. {
  128. label: 'JavaScript',
  129. value: 'javascript',
  130. language: 'javascript',
  131. code: `import * as Sentry from "@sentry/node";
  132. const eventId = Sentry.captureMessage("User Feedback");
  133. // OR: const eventId = Sentry.lastEventId();
  134. const userFeedback = {
  135. event_id: eventId,
  136. name: "John Doe",
  137. email: "john@doe.com",
  138. comments: "I really like your App, thanks!",
  139. };
  140. Sentry.captureUserFeedback(userFeedback);
  141. `,
  142. },
  143. ],
  144. },
  145. ],
  146. },
  147. ],
  148. configure: () => [],
  149. verify: () => [],
  150. nextSteps: () => [],
  151. };
  152. const crashReportOnboarding: OnboardingConfig = {
  153. introduction: () => getCrashReportModalIntroduction(),
  154. install: (params: Params) => getCrashReportJavaScriptInstallStep(params),
  155. configure: () => [
  156. {
  157. type: StepType.CONFIGURE,
  158. description: getCrashReportModalConfigDescription({
  159. link: 'https://docs.sentry.io/platforms/javascript/guides/hapi/user-feedback/configuration/#crash-report-modal',
  160. }),
  161. },
  162. ],
  163. verify: () => [],
  164. nextSteps: () => [],
  165. };
  166. const docs: Docs = {
  167. onboarding,
  168. feedbackOnboardingCrashApi: feedbackOnboardingNode,
  169. customMetricsOnboarding: getJSServerMetricsOnboarding(),
  170. crashReportOnboarding,
  171. };
  172. export default docs;