node.tsx 2.8 KB

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