node.tsx 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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 {PlatformKey} from 'sentry/data/platformCategories';
  5. import {t, tct} from 'sentry/locale';
  6. import type {Organization} from 'sentry/types';
  7. type StepProps = {
  8. newOrg: boolean;
  9. organization: Organization;
  10. platformKey: PlatformKey;
  11. projectId: string;
  12. sentryInitContent: string;
  13. };
  14. const performanceOtherConfig = `
  15. // Performance Monitoring
  16. tracesSampleRate: 1.0, // Capture 100% of the transactions, reduce in production!`;
  17. export const steps = ({
  18. sentryInitContent,
  19. }: Partial<StepProps> = {}): LayoutProps['steps'] => [
  20. {
  21. type: StepType.INSTALL,
  22. description: t('Add the Sentry Node SDK as a dependency:'),
  23. configurations: [
  24. {
  25. language: 'bash',
  26. code: `
  27. # Using yarn
  28. yarn add @sentry/node
  29. # Using npm
  30. npm install --save @sentry/node
  31. `,
  32. },
  33. ],
  34. },
  35. {
  36. type: StepType.CONFIGURE,
  37. description: (
  38. <p>
  39. {tct(
  40. "Initialize Sentry as early as possible in your application's lifecycle, for example in your [code:index.ts/js] entry point:",
  41. {code: <code />}
  42. )}
  43. </p>
  44. ),
  45. configurations: [
  46. {
  47. language: 'javascript',
  48. code: `
  49. const Sentry = require("@sentry/node");
  50. // or use ESM import statements
  51. // import * as Sentry from '@sentry/node';
  52. Sentry.init({
  53. ${sentryInitContent}
  54. });
  55. `,
  56. },
  57. ],
  58. },
  59. {
  60. type: StepType.VERIFY,
  61. description: t(
  62. "This snippet contains an intentional error and can be used as a test to make sure that everything's working as expected."
  63. ),
  64. configurations: [
  65. {
  66. language: 'javascript',
  67. code: `
  68. const transaction = Sentry.startTransaction({
  69. op: "test",
  70. name: "My First Test Transaction",
  71. });
  72. setTimeout(() => {
  73. try {
  74. foo();
  75. } catch (e) {
  76. Sentry.captureException(e);
  77. } finally {
  78. transaction.finish();
  79. }
  80. }, 99);
  81. `,
  82. },
  83. ],
  84. },
  85. ];
  86. export function GettingStartedWithNode({dsn, newOrg, platformKey}: ModuleProps) {
  87. const sentryInitContent: string[] = [`dsn: "${dsn}",`, performanceOtherConfig];
  88. return (
  89. <Layout
  90. steps={steps({
  91. sentryInitContent: sentryInitContent.join('\n'),
  92. })}
  93. newOrg={newOrg}
  94. platformKey={platformKey}
  95. />
  96. );
  97. }
  98. export default GettingStartedWithNode;