hapi.tsx 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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 {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 Hapi = require('@hapi/hapi');
  29. const init = async () => {
  30. const server = Hapi.server({
  31. port: 3030,
  32. host: 'localhost',
  33. });
  34. // All your routes live here
  35. await Sentry.setupHapiErrorHandler(server);
  36. await server.start();
  37. };
  38. init();
  39. `;
  40. const getVerifySnippet = () => `
  41. app.use(async function () {
  42. throw new Error("My first Sentry error!");
  43. });
  44. `;
  45. const onboarding: OnboardingConfig = {
  46. introduction: () =>
  47. tct('In this quick guide you’ll use [strong:npm] or [strong:yarn] to set up:', {
  48. strong: <strong />,
  49. }),
  50. install: params => [
  51. {
  52. type: StepType.INSTALL,
  53. description: t('Add the Sentry Node SDK as a dependency:'),
  54. configurations: getInstallConfig(params),
  55. },
  56. ],
  57. configure: params => [
  58. {
  59. type: StepType.CONFIGURE,
  60. description: t(
  61. "Initialize Sentry as early as possible in your application's lifecycle."
  62. ),
  63. configurations: [
  64. {
  65. description: tct(
  66. 'To initialize the SDK before everything else, create an external file called [code:instrument.js/mjs].',
  67. {code: <code />}
  68. ),
  69. code: [
  70. {
  71. label: 'JavaScript',
  72. value: 'javascript',
  73. language: 'javascript',
  74. filename: 'instrument.(js|mjs)',
  75. code: getSdkInitSnippet(params, 'node'),
  76. },
  77. ],
  78. },
  79. {
  80. description: tct(
  81. "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].",
  82. {
  83. code: <code />,
  84. docs: (
  85. <ExternalLink href="https://docs.sentry.io/platforms/javascript/guides/hapi/install/" />
  86. ),
  87. }
  88. ),
  89. code: [
  90. {
  91. label: 'JavaScript',
  92. value: 'javascript',
  93. language: 'javascript',
  94. filename: 'index.(js|mjs)',
  95. code: getSdkSetupSnippet(),
  96. },
  97. ],
  98. },
  99. ],
  100. },
  101. getUploadSourceMapsStep({
  102. guideLink: 'https://docs.sentry.io/platforms/javascript/guides/hapi/sourcemaps/',
  103. ...params,
  104. }),
  105. ],
  106. verify: () => [
  107. {
  108. type: StepType.VERIFY,
  109. description: t(
  110. "This snippet contains an intentional error and can be used as a test to make sure that everything's working as expected."
  111. ),
  112. configurations: [
  113. {
  114. language: 'javascript',
  115. code: getVerifySnippet(),
  116. },
  117. ],
  118. },
  119. ],
  120. };
  121. const feedbackOnboardingNode: OnboardingConfig = {
  122. introduction: () => getCrashReportApiIntroduction(),
  123. install: () => [
  124. {
  125. type: StepType.INSTALL,
  126. description: getCrashReportInstallDescription(),
  127. configurations: [
  128. {
  129. code: [
  130. {
  131. label: 'JavaScript',
  132. value: 'javascript',
  133. language: 'javascript',
  134. code: `import * as Sentry from "@sentry/node";
  135. const eventId = Sentry.captureMessage("User Feedback");
  136. // OR: const eventId = Sentry.lastEventId();
  137. const userFeedback = {
  138. event_id: eventId,
  139. name: "John Doe",
  140. email: "john@doe.com",
  141. comments: "I really like your App, thanks!",
  142. };
  143. Sentry.captureUserFeedback(userFeedback);
  144. `,
  145. },
  146. ],
  147. },
  148. ],
  149. },
  150. ],
  151. configure: () => [],
  152. verify: () => [],
  153. nextSteps: () => [],
  154. };
  155. const crashReportOnboarding: OnboardingConfig = {
  156. introduction: () => getCrashReportModalIntroduction(),
  157. install: (params: Params) => getCrashReportJavaScriptInstallStep(params),
  158. configure: () => [
  159. {
  160. type: StepType.CONFIGURE,
  161. description: getCrashReportModalConfigDescription({
  162. link: 'https://docs.sentry.io/platforms/javascript/guides/hapi/user-feedback/configuration/#crash-report-modal',
  163. }),
  164. },
  165. ],
  166. verify: () => [],
  167. nextSteps: () => [],
  168. };
  169. const docs: Docs = {
  170. onboarding,
  171. feedbackOnboardingCrashApi: feedbackOnboardingNode,
  172. crashReportOnboarding,
  173. };
  174. export default docs;