awslambda.tsx 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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. getInstallSnippet,
  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: [
  61. {
  62. code: [
  63. {
  64. label: 'npm',
  65. value: 'npm',
  66. language: 'bash',
  67. code: getInstallSnippet({
  68. basePackage: '@sentry/serverless',
  69. productSelection: productSelection(params),
  70. packageManager: 'npm',
  71. }),
  72. },
  73. {
  74. label: 'yarn',
  75. value: 'yarn',
  76. language: 'bash',
  77. code: getInstallSnippet({
  78. basePackage: '@sentry/serverless',
  79. productSelection: productSelection(params),
  80. packageManager: 'yarn',
  81. }),
  82. },
  83. ],
  84. },
  85. ],
  86. },
  87. ],
  88. configure: params => [
  89. {
  90. type: StepType.CONFIGURE,
  91. description: tct(
  92. "Wrap your lambda handler with Sentry's [code:wraphandler] function:",
  93. {
  94. code: <code />,
  95. }
  96. ),
  97. configurations: [
  98. {
  99. language: 'javascript',
  100. code: getSdkSetupSnippet(params),
  101. },
  102. ],
  103. },
  104. getUploadSourceMapsStep({
  105. guideLink: 'https://docs.sentry.io/platforms/node/guides/aws-lambda/sourcemaps/',
  106. ...params,
  107. }),
  108. ],
  109. verify: () => [
  110. {
  111. type: StepType.VERIFY,
  112. description: t(
  113. "This snippet contains an intentional error and can be used as a test to make sure that everything's working as expected."
  114. ),
  115. configurations: [
  116. {
  117. language: 'javascript',
  118. code: getVerifySnippet(),
  119. },
  120. ],
  121. },
  122. ],
  123. };
  124. const docs: Docs = {
  125. onboarding,
  126. };
  127. export default docs;