node.tsx 3.6 KB

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