node.tsx 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. import {Layout, LayoutProps} from 'sentry/components/onboarding/gettingStartedDoc/layout';
  2. import {ModuleProps} from 'sentry/components/onboarding/gettingStartedDoc/sdkDocumentation';
  3. import {StepProps, StepType} from 'sentry/components/onboarding/gettingStartedDoc/step';
  4. import {getUploadSourceMapsStep} from 'sentry/components/onboarding/gettingStartedDoc/utils';
  5. import {t, tct} from 'sentry/locale';
  6. import {
  7. getDefaultInitParams,
  8. getDefaultNodeImports,
  9. getInstallSnippet,
  10. getProductInitParams,
  11. getProductIntegrations,
  12. getProductSelectionMap,
  13. joinWithIndentation,
  14. } from 'sentry/utils/gettingStartedDocs/node';
  15. interface StepsParams {
  16. importContent: string;
  17. initContent: string;
  18. installSnippet: string;
  19. sourceMapStep: StepProps;
  20. }
  21. export const steps = ({
  22. installSnippet,
  23. importContent,
  24. initContent,
  25. sourceMapStep,
  26. }: StepsParams): LayoutProps['steps'] => [
  27. {
  28. type: StepType.INSTALL,
  29. description: t('Add the Sentry Node SDK as a dependency:'),
  30. configurations: [
  31. {
  32. language: 'bash',
  33. code: installSnippet,
  34. },
  35. ],
  36. },
  37. {
  38. type: StepType.CONFIGURE,
  39. description: (
  40. <p>
  41. {tct(
  42. "Initialize Sentry as early as possible in your application's lifecycle, for example in your [code:index.ts/js] entry point:",
  43. {code: <code />}
  44. )}
  45. </p>
  46. ),
  47. configurations: [
  48. {
  49. language: 'javascript',
  50. code: `
  51. ${importContent}
  52. Sentry.init({
  53. ${initContent}
  54. });
  55. `,
  56. },
  57. ],
  58. },
  59. sourceMapStep,
  60. {
  61. type: StepType.VERIFY,
  62. description: t(
  63. "This snippet contains an intentional error and can be used as a test to make sure that everything's working as expected."
  64. ),
  65. configurations: [
  66. {
  67. language: 'javascript',
  68. code: `
  69. const transaction = Sentry.startTransaction({
  70. op: "test",
  71. name: "My First Test Transaction",
  72. });
  73. setTimeout(() => {
  74. try {
  75. foo();
  76. } catch (e) {
  77. Sentry.captureException(e);
  78. } finally {
  79. transaction.finish();
  80. }
  81. }, 99);
  82. `,
  83. },
  84. ],
  85. },
  86. ];
  87. export function GettingStartedWithNode({
  88. dsn,
  89. newOrg,
  90. platformKey,
  91. activeProductSelection = [],
  92. organization,
  93. projectId,
  94. }: ModuleProps) {
  95. const productSelection = getProductSelectionMap(activeProductSelection);
  96. const installSnippet = getInstallSnippet({productSelection});
  97. const imports = getDefaultNodeImports({productSelection});
  98. const integrations = getProductIntegrations({productSelection});
  99. const integrationParam =
  100. integrations.length > 0
  101. ? `integrations: [\n${joinWithIndentation(integrations)}\n],`
  102. : null;
  103. const initContent = joinWithIndentation([
  104. ...getDefaultInitParams({dsn}),
  105. ...(integrationParam ? [integrationParam] : []),
  106. ...getProductInitParams({productSelection}),
  107. ]);
  108. return (
  109. <Layout
  110. steps={steps({
  111. installSnippet,
  112. importContent: imports.join('\n'),
  113. initContent,
  114. sourceMapStep: getUploadSourceMapsStep({
  115. guideLink: 'https://docs.sentry.io/platforms/node/sourcemaps/',
  116. organization,
  117. platformKey,
  118. projectId,
  119. newOrg,
  120. }),
  121. })}
  122. newOrg={newOrg}
  123. platformKey={platformKey}
  124. />
  125. );
  126. }
  127. export default GettingStartedWithNode;