node.tsx 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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. ...props
  95. }: ModuleProps) {
  96. const productSelection = getProductSelectionMap(activeProductSelection);
  97. const installSnippet = getInstallSnippet({productSelection});
  98. const imports = getDefaultNodeImports({productSelection});
  99. const integrations = getProductIntegrations({productSelection});
  100. const integrationParam =
  101. integrations.length > 0
  102. ? `integrations: [\n${joinWithIndentation(integrations)}\n],`
  103. : null;
  104. const initContent = joinWithIndentation([
  105. ...getDefaultInitParams({dsn}),
  106. ...(integrationParam ? [integrationParam] : []),
  107. ...getProductInitParams({productSelection}),
  108. ]);
  109. return (
  110. <Layout
  111. steps={steps({
  112. installSnippet,
  113. importContent: imports.join('\n'),
  114. initContent,
  115. sourceMapStep: getUploadSourceMapsStep({
  116. guideLink: 'https://docs.sentry.io/platforms/node/sourcemaps/',
  117. organization,
  118. platformKey,
  119. projectId,
  120. newOrg,
  121. }),
  122. })}
  123. newOrg={newOrg}
  124. platformKey={platformKey}
  125. {...props}
  126. />
  127. );
  128. }
  129. export default GettingStartedWithNode;