node.tsx 3.7 KB

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