awslambda.tsx 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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}",
  31. _experiments: {
  32. metricsAggregator: true,
  33. },
  34. });`;
  35. const onboarding: OnboardingConfig = {
  36. install: params => [
  37. {
  38. type: StepType.INSTALL,
  39. description: t('Add the Sentry AWS Serverless SDK as a dependency:'),
  40. configurations: getInstallConfig(params, {
  41. basePackage: '@sentry/aws-serverless',
  42. }),
  43. },
  44. ],
  45. configure: params => [
  46. {
  47. type: StepType.CONFIGURE,
  48. description: tct(
  49. "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:",
  50. {
  51. import: <code />,
  52. require: <code />,
  53. code: <code />,
  54. }
  55. ),
  56. configurations: [
  57. {
  58. language: 'javascript',
  59. code: getSdkSetupSnippet(params),
  60. },
  61. ],
  62. },
  63. getUploadSourceMapsStep({
  64. guideLink:
  65. 'https://docs.sentry.io/platforms/javascript/guides/aws-lambda/sourcemaps/',
  66. ...params,
  67. }),
  68. ],
  69. verify: () => [
  70. {
  71. type: StepType.VERIFY,
  72. description: t(
  73. "This snippet contains an intentional error and can be used as a test to make sure that everything's working as expected."
  74. ),
  75. configurations: [
  76. {
  77. language: 'javascript',
  78. code: getVerifySnippet(),
  79. },
  80. ],
  81. },
  82. ],
  83. };
  84. const customMetricsOnboarding: OnboardingConfig = {
  85. install: params => [
  86. {
  87. type: StepType.INSTALL,
  88. description: tct(
  89. 'You need a minimum version [codeVersion:8.0.0] of [codePackage:@sentry/aws-serverless]:',
  90. {
  91. codeVersion: <code />,
  92. codePackage: <code />,
  93. }
  94. ),
  95. configurations: getInstallConfig(params, {
  96. basePackage: '@sentry/aws-serverless',
  97. }),
  98. },
  99. ],
  100. configure: params => [
  101. {
  102. type: StepType.CONFIGURE,
  103. description: tct(
  104. 'To enable capturing metrics, you first need to add the [codeIntegration:metricsAggregator] experiment to your [codeNamespace:Sentry.init] call in your main process.',
  105. {
  106. codeIntegration: <code />,
  107. codeNamespace: <code />,
  108. }
  109. ),
  110. configurations: [
  111. {
  112. code: [
  113. {
  114. label: 'JavaScript',
  115. value: 'javascript',
  116. language: 'javascript',
  117. code: getMetricsConfigureSnippet(params),
  118. },
  119. ],
  120. },
  121. ],
  122. },
  123. ],
  124. verify: getJSServerMetricsOnboarding().verify,
  125. };
  126. const crashReportOnboarding: OnboardingConfig = {
  127. introduction: () => getCrashReportModalIntroduction(),
  128. install: (params: Params) => getCrashReportJavaScriptInstallStep(params),
  129. configure: () => [
  130. {
  131. type: StepType.CONFIGURE,
  132. description: getCrashReportModalConfigDescription({
  133. link: 'https://docs.sentry.io/platforms/javascript/guides/aws-lambda/user-feedback/configuration/#crash-report-modal',
  134. }),
  135. },
  136. ],
  137. verify: () => [],
  138. nextSteps: () => [],
  139. };
  140. const docs: Docs = {
  141. onboarding,
  142. customMetricsOnboarding,
  143. crashReportOnboarding,
  144. };
  145. export default docs;