node.tsx 3.4 KB

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