node.tsx 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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 {getUploadSourceMapsStep} from 'sentry/components/onboarding/gettingStartedDoc/utils';
  5. import {PlatformKey} from 'sentry/data/platformCategories';
  6. import {t, tct} from 'sentry/locale';
  7. import type {Organization} from 'sentry/types';
  8. type StepProps = {
  9. newOrg: boolean;
  10. organization: Organization;
  11. platformKey: PlatformKey;
  12. projectId: string;
  13. sentryInitContent: string;
  14. };
  15. const performanceOtherConfig = `
  16. // Performance Monitoring
  17. tracesSampleRate: 1.0, // Capture 100% of the transactions, reduce in production!`;
  18. export const steps = ({
  19. sentryInitContent,
  20. ...props
  21. }: Partial<StepProps> = {}): LayoutProps['steps'] => [
  22. {
  23. type: StepType.INSTALL,
  24. description: t('Add the Sentry Node SDK as a dependency:'),
  25. configurations: [
  26. {
  27. language: 'bash',
  28. code: `
  29. # Using yarn
  30. yarn add @sentry/node
  31. # Using npm
  32. npm install --save @sentry/node
  33. `,
  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. const Sentry = require("@sentry/node");
  52. // or use ESM import statements
  53. // import * as Sentry from '@sentry/node';
  54. Sentry.init({
  55. ${sentryInitContent}
  56. });
  57. `,
  58. },
  59. ],
  60. },
  61. getUploadSourceMapsStep({
  62. guideLink: 'https://docs.sentry.io/platforms/node/sourcemaps/',
  63. ...props,
  64. }),
  65. {
  66. type: StepType.VERIFY,
  67. description: t(
  68. "This snippet contains an intentional error and can be used as a test to make sure that everything's working as expected."
  69. ),
  70. configurations: [
  71. {
  72. language: 'javascript',
  73. code: `
  74. const transaction = Sentry.startTransaction({
  75. op: "test",
  76. name: "My First Test Transaction",
  77. });
  78. setTimeout(() => {
  79. try {
  80. foo();
  81. } catch (e) {
  82. Sentry.captureException(e);
  83. } finally {
  84. transaction.finish();
  85. }
  86. }, 99);
  87. `,
  88. },
  89. ],
  90. },
  91. ];
  92. export function GettingStartedWithNode({
  93. dsn,
  94. organization,
  95. newOrg,
  96. platformKey,
  97. projectId,
  98. }: ModuleProps) {
  99. const sentryInitContent: string[] = [`dsn: "${dsn}",`, performanceOtherConfig];
  100. return (
  101. <Layout
  102. steps={steps({
  103. sentryInitContent: sentryInitContent.join('\n'),
  104. organization,
  105. newOrg,
  106. platformKey,
  107. projectId,
  108. })}
  109. newOrg={newOrg}
  110. platformKey={platformKey}
  111. />
  112. );
  113. }
  114. export default GettingStartedWithNode;