node.tsx 2.5 KB

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