serverlesscloud.tsx 2.8 KB

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