awslambda.tsx 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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 {getUploadSourceMapsStep} from 'sentry/components/onboarding/gettingStartedDoc/utils';
  8. import {
  9. getCrashReportJavaScriptInstallStep,
  10. getCrashReportModalConfigDescription,
  11. getCrashReportModalIntroduction,
  12. } from 'sentry/components/onboarding/gettingStartedDoc/utils/feedbackOnboarding';
  13. import {getJSServerMetricsOnboarding} from 'sentry/components/onboarding/gettingStartedDoc/utils/metricsOnboarding';
  14. import {t, tct} from 'sentry/locale';
  15. import {getInstallConfig, getSdkInitSnippet} from 'sentry/utils/gettingStartedDocs/node';
  16. type Params = DocsParams;
  17. const getSdkSetupSnippet = (params: Params) => `
  18. // IMPORTANT: Make sure to import and initialize Sentry at the top of your file.
  19. ${getSdkInitSnippet(params, 'aws')}
  20. // Place any other require/import statements here
  21. exports.handler = Sentry.wrapHandler(async (event, context) => {
  22. // Your handler code
  23. });`;
  24. const getVerifySnippet = () => `
  25. exports.handler = Sentry.wrapHandler(async (event, context) => {
  26. throw new Error("This should show up in Sentry!")
  27. });`;
  28. const getMetricsConfigureSnippet = (params: DocsParams) => `
  29. Sentry.init({
  30. dsn: "${params.dsn.public}",
  31. // Only needed for SDK versions < 8.0.0
  32. // _experiments: {
  33. // metricsAggregator: true,
  34. // },
  35. });`;
  36. const onboarding: OnboardingConfig = {
  37. install: params => [
  38. {
  39. type: StepType.INSTALL,
  40. description: t('Add the Sentry AWS Serverless SDK as a dependency:'),
  41. configurations: getInstallConfig(params, {
  42. basePackage: '@sentry/aws-serverless',
  43. }),
  44. },
  45. ],
  46. configure: params => [
  47. {
  48. type: StepType.CONFIGURE,
  49. description: tct(
  50. "Ensure that Sentry is imported and initialized at the beginning of your file, prior to any other [require:require] or [import:import] statements. Then, wrap your lambda handler with Sentry's [code:wraphandler] function:",
  51. {
  52. import: <code />,
  53. require: <code />,
  54. code: <code />,
  55. }
  56. ),
  57. configurations: [
  58. {
  59. language: 'javascript',
  60. code: getSdkSetupSnippet(params),
  61. },
  62. ],
  63. },
  64. getUploadSourceMapsStep({
  65. guideLink:
  66. 'https://docs.sentry.io/platforms/javascript/guides/aws-lambda/sourcemaps/',
  67. ...params,
  68. }),
  69. ],
  70. verify: () => [
  71. {
  72. type: StepType.VERIFY,
  73. description: t(
  74. "This snippet contains an intentional error and can be used as a test to make sure that everything's working as expected."
  75. ),
  76. configurations: [
  77. {
  78. language: 'javascript',
  79. code: getVerifySnippet(),
  80. },
  81. ],
  82. },
  83. ],
  84. };
  85. const customMetricsOnboarding: OnboardingConfig = {
  86. install: params => [
  87. {
  88. type: StepType.INSTALL,
  89. description: tct(
  90. 'You need a minimum version [codeVersion:8.0.0] of [codePackage:@sentry/aws-serverless]:',
  91. {
  92. codeVersion: <code />,
  93. codePackage: <code />,
  94. }
  95. ),
  96. configurations: getInstallConfig(params, {
  97. basePackage: '@sentry/aws-serverless',
  98. }),
  99. },
  100. ],
  101. configure: params => [
  102. {
  103. type: StepType.CONFIGURE,
  104. description: t(
  105. 'With the default snippet in place, there is no need for any further configuration.'
  106. ),
  107. configurations: [
  108. {
  109. code: getMetricsConfigureSnippet(params),
  110. language: 'javascript',
  111. },
  112. ],
  113. },
  114. ],
  115. verify: getJSServerMetricsOnboarding().verify,
  116. };
  117. const crashReportOnboarding: OnboardingConfig = {
  118. introduction: () => getCrashReportModalIntroduction(),
  119. install: (params: Params) => getCrashReportJavaScriptInstallStep(params),
  120. configure: () => [
  121. {
  122. type: StepType.CONFIGURE,
  123. description: getCrashReportModalConfigDescription({
  124. link: 'https://docs.sentry.io/platforms/javascript/guides/aws-lambda/user-feedback/configuration/#crash-report-modal',
  125. }),
  126. },
  127. ],
  128. verify: () => [],
  129. nextSteps: () => [],
  130. };
  131. const docs: Docs = {
  132. onboarding,
  133. customMetricsOnboarding,
  134. crashReportOnboarding,
  135. };
  136. export default docs;