node.tsx 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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 {ProductSolution} from 'sentry/components/onboarding/productSelection';
  15. import replayOnboardingJsLoader from 'sentry/gettingStartedDocs/javascript/jsLoader/jsLoader';
  16. import {t, tct} from 'sentry/locale';
  17. import type {ProductSelectionMap} from 'sentry/utils/gettingStartedDocs/node';
  18. import {
  19. getDefaultNodeImports,
  20. getInstallConfig,
  21. } from 'sentry/utils/gettingStartedDocs/node';
  22. type Params = DocsParams;
  23. const productSelection = (params: Params): ProductSelectionMap => {
  24. return {
  25. [ProductSolution.ERROR_MONITORING]: true,
  26. [ProductSolution.PROFILING]: params.isProfilingSelected,
  27. [ProductSolution.PERFORMANCE_MONITORING]: params.isPerformanceSelected,
  28. [ProductSolution.SESSION_REPLAY]: params.isReplaySelected,
  29. };
  30. };
  31. const getSdkSetupSnippet = (params: Params) => `
  32. ${getDefaultNodeImports({productSelection: productSelection(params)}).join('\n')}
  33. Sentry.init({
  34. dsn: "${params.dsn}",
  35. ${
  36. params.isProfilingSelected
  37. ? `integrations: [
  38. nodeProfilingIntegration(),
  39. ],`
  40. : ''
  41. }${
  42. params.isPerformanceSelected
  43. ? `
  44. // Performance Monitoring
  45. tracesSampleRate: 1.0, // Capture 100% of the transactions`
  46. : ''
  47. }${
  48. params.isProfilingSelected
  49. ? `
  50. // Set sampling rate for profiling - this is relative to tracesSampleRate
  51. profilesSampleRate: 1.0,`
  52. : ''
  53. }
  54. });
  55. `;
  56. const onboarding: OnboardingConfig = {
  57. install: (params: Params) => [
  58. {
  59. type: StepType.INSTALL,
  60. description: t('Add the Sentry Node SDK as a dependency:'),
  61. configurations: getInstallConfig(params),
  62. },
  63. ],
  64. configure: (params: Params) => [
  65. {
  66. type: StepType.CONFIGURE,
  67. description: tct(
  68. "Initialize Sentry as early as possible in your application's lifecycle, for example in your [code:index.ts/js] entry point:",
  69. {code: <code />}
  70. ),
  71. configurations: [
  72. {
  73. code: [
  74. {
  75. label: 'JavaScript',
  76. value: 'javascript',
  77. language: 'javascript',
  78. code: getSdkSetupSnippet(params),
  79. },
  80. ],
  81. },
  82. ],
  83. },
  84. getUploadSourceMapsStep({
  85. guideLink: 'https://docs.sentry.io/platforms/javascript/guides/node/sourcemaps/',
  86. }),
  87. ],
  88. verify: () => [
  89. {
  90. type: StepType.VERIFY,
  91. description: t(
  92. "This snippet contains an intentional error and can be used as a test to make sure that everything's working as expected."
  93. ),
  94. configurations: [
  95. {
  96. language: 'javascript',
  97. code: `
  98. const transaction = Sentry.startTransaction({
  99. op: "test",
  100. name: "My First Test Transaction",
  101. });
  102. setTimeout(() => {
  103. try {
  104. foo();
  105. } catch (e) {
  106. Sentry.captureException(e);
  107. } finally {
  108. transaction.finish();
  109. }
  110. }, 99);
  111. `,
  112. },
  113. ],
  114. },
  115. ],
  116. };
  117. const crashReportOnboarding: OnboardingConfig = {
  118. introduction: () => getCrashReportModalIntroduction(),
  119. install: (params: Params) => getCrashReportJavaScriptInstallStep(params),
  120. configure: () => [
  121. {
  122. type: StepType.CONFIGURE,
  123. description: getCrashReportModalConfigDescription({
  124. link: 'https://docs.sentry.io/platforms/javascript/guides/node/user-feedback/configuration/#crash-report-modal',
  125. }),
  126. },
  127. ],
  128. verify: () => [],
  129. nextSteps: () => [],
  130. };
  131. const docs: Docs = {
  132. onboarding,
  133. replayOnboardingJsLoader,
  134. customMetricsOnboarding: getJSServerMetricsOnboarding(),
  135. crashReportOnboarding,
  136. };
  137. export default docs;