serverlesscloud.tsx 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. import {StepType} from 'sentry/components/onboarding/gettingStartedDoc/step';
  2. import type {
  3. Docs,
  4. DocsParams,
  5. OnboardingConfig,
  6. } from 'sentry/components/onboarding/gettingStartedDoc/types';
  7. import {CrashReportWebApiOnboarding} from 'sentry/components/onboarding/gettingStartedDoc/utils/feedbackOnboarding';
  8. import {t, tct} from 'sentry/locale';
  9. type Params = DocsParams;
  10. const getSdkSetupSnippet = (params: Params) => `
  11. const api = require("@serverless/cloud");
  12. const Sentry = require('@sentry/node');
  13. // or using ESM
  14. // import api from "@serverless/cloud";
  15. // import * as Sentry from "@sentry/node";
  16. Sentry.init({
  17. dsn: "${params.dsn}",
  18. integrations: [
  19. // enable HTTP calls tracing
  20. new Sentry.Integrations.Http({ tracing: true }),
  21. // enable Express.js middleware tracing
  22. new Sentry.Integrations.Express({ app }),
  23. // Automatically instrument Node.js libraries and frameworks
  24. ...Sentry.autoDiscoverNodePerformanceMonitoringIntegrations(),
  25. ],
  26. environment: params.INSTANCE_NAME,
  27. // Performance Monitoring
  28. // Capture 100% of the transactions
  29. tracesSampleRate: 1.0,
  30. });
  31. // RequestHandler creates a separate execution context, so that all
  32. // transactions/spans/breadcrumbs are isolated across requests
  33. api.use(Sentry.Handlers.requestHandler());
  34. // TracingHandler creates a trace for every incoming request
  35. api.use(Sentry.Handlers.tracingHandler());
  36. // All controllers should live here
  37. api.get("/", function rootHandler(req, res) {
  38. res.end("Hello world!");
  39. });
  40. // The error handler must be before any other error middleware and after all controllers
  41. api.use(Sentry.Handlers.errorHandler());
  42. // Optional fallthrough error handler
  43. api.use(function onError(err, req, res, next) {
  44. // The error id is attached to \`res.sentry\` to be returned
  45. // and optionally displayed to the user for support.
  46. res.statusCode = 500;
  47. res.end(res.sentry + "\\n");
  48. });`;
  49. const getVerifySnippet = () => `
  50. api.get("/debug-sentry", function mainHandler(req, res) {
  51. throw new Error("My first Sentry error!");
  52. });
  53. `;
  54. const onboarding: OnboardingConfig = {
  55. install: () => [
  56. {
  57. type: StepType.INSTALL,
  58. description: tct('Add [code:@sentry/node] as a dependency:', {code: <code />}),
  59. configurations: [
  60. {
  61. language: 'bash',
  62. code: `cloud install @sentry/node:`,
  63. },
  64. ],
  65. },
  66. ],
  67. configure: params => [
  68. {
  69. type: StepType.CONFIGURE,
  70. description: t('Sentry should be initialized as early in your app as possible.'),
  71. configurations: [
  72. {
  73. language: 'javascript',
  74. code: getSdkSetupSnippet(params),
  75. },
  76. ],
  77. },
  78. ],
  79. verify: () => [
  80. {
  81. type: StepType.VERIFY,
  82. description: t(
  83. "This snippet contains an intentional error and can be used as a test to make sure that everything's working as expected."
  84. ),
  85. configurations: [
  86. {
  87. language: 'javascript',
  88. code: getVerifySnippet(),
  89. },
  90. ],
  91. },
  92. ],
  93. };
  94. const docs: Docs = {
  95. onboarding,
  96. crashReportOnboarding: CrashReportWebApiOnboarding,
  97. };
  98. export default docs;