hapi.tsx 5.3 KB

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