awslambda.tsx 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. import {StepType} from 'sentry/components/onboarding/gettingStartedDoc/step';
  2. import {
  3. Docs,
  4. DocsParams,
  5. OnboardingConfig,
  6. } from 'sentry/components/onboarding/gettingStartedDoc/types';
  7. import {getUploadSourceMapsStep} from 'sentry/components/onboarding/gettingStartedDoc/utils';
  8. import {ProductSolution} from 'sentry/components/onboarding/productSelection';
  9. import {t, tct} from 'sentry/locale';
  10. import {
  11. getDefaulServerlessImports,
  12. getInstallConfig,
  13. ProductSelectionMap,
  14. } from 'sentry/utils/gettingStartedDocs/node';
  15. type Params = DocsParams;
  16. const productSelection = (params: Params): ProductSelectionMap => {
  17. return {
  18. [ProductSolution.ERROR_MONITORING]: true,
  19. [ProductSolution.PROFILING]: params.isProfilingSelected,
  20. [ProductSolution.PERFORMANCE_MONITORING]: params.isPerformanceSelected,
  21. [ProductSolution.SESSION_REPLAY]: params.isReplaySelected,
  22. };
  23. };
  24. const getSdkSetupSnippet = (params: Params) => `
  25. ${getDefaulServerlessImports({productSelection: productSelection(params)}).join('\n')}
  26. Sentry.AWSLambda.init({
  27. dsn: "${params.dsn}",
  28. integrations: [${
  29. params.isProfilingSelected
  30. ? `
  31. new ProfilingIntegration(),`
  32. : ''
  33. }
  34. ],${
  35. params.isPerformanceSelected
  36. ? `
  37. // Performance Monitoring
  38. tracesSampleRate: 1.0, // Capture 100% of the transactions`
  39. : ''
  40. }${
  41. params.isProfilingSelected
  42. ? `
  43. // Set sampling rate for profiling - this is relative to tracesSampleRate
  44. profilesSampleRate: 1.0,`
  45. : ''
  46. }
  47. });
  48. exports.handler = Sentry.AWSLambda.wrapHandler(async (event, context) => {
  49. // Your handler code
  50. });`;
  51. const getVerifySnippet = () => `
  52. exports.handler = Sentry.AWSLambda.wrapHandler(async (event, context) => {
  53. throw new Error("This should show up in Sentry!")
  54. });`;
  55. const onboarding: OnboardingConfig = {
  56. install: params => [
  57. {
  58. type: StepType.INSTALL,
  59. description: t('Add the Sentry Serverless SDK as a dependency:'),
  60. configurations: getInstallConfig(params, {
  61. basePackage: '@sentry/serverless',
  62. }),
  63. },
  64. ],
  65. configure: params => [
  66. {
  67. type: StepType.CONFIGURE,
  68. description: tct(
  69. "Wrap your lambda handler with Sentry's [code:wraphandler] function:",
  70. {
  71. code: <code />,
  72. }
  73. ),
  74. configurations: [
  75. {
  76. language: 'javascript',
  77. code: getSdkSetupSnippet(params),
  78. },
  79. ],
  80. },
  81. getUploadSourceMapsStep({
  82. guideLink: 'https://docs.sentry.io/platforms/node/guides/aws-lambda/sourcemaps/',
  83. ...params,
  84. }),
  85. ],
  86. verify: () => [
  87. {
  88. type: StepType.VERIFY,
  89. description: t(
  90. "This snippet contains an intentional error and can be used as a test to make sure that everything's working as expected."
  91. ),
  92. configurations: [
  93. {
  94. language: 'javascript',
  95. code: getVerifySnippet(),
  96. },
  97. ],
  98. },
  99. ],
  100. };
  101. const docs: Docs = {
  102. onboarding,
  103. };
  104. export default docs;