awslambda.tsx 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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 {ProductSolution} from 'sentry/components/onboarding/productSelection';
  15. import {t, tct} from 'sentry/locale';
  16. import type {ProductSelectionMap} from 'sentry/utils/gettingStartedDocs/node';
  17. import {
  18. getDefaulServerlessImports,
  19. getInstallConfig,
  20. } from 'sentry/utils/gettingStartedDocs/node';
  21. type Params = DocsParams;
  22. const productSelection = (params: Params): ProductSelectionMap => {
  23. return {
  24. [ProductSolution.ERROR_MONITORING]: true,
  25. [ProductSolution.PROFILING]: params.isProfilingSelected,
  26. [ProductSolution.PERFORMANCE_MONITORING]: params.isPerformanceSelected,
  27. [ProductSolution.SESSION_REPLAY]: params.isReplaySelected,
  28. };
  29. };
  30. const getSdkSetupSnippet = (params: Params) => `
  31. ${getDefaulServerlessImports({productSelection: productSelection(params)}).join('\n')}
  32. Sentry.AWSLambda.init({
  33. dsn: "${params.dsn}",
  34. integrations: [${
  35. params.isProfilingSelected
  36. ? `
  37. nodeProfilingIntegration(),`
  38. : ''
  39. }
  40. ],${
  41. params.isPerformanceSelected
  42. ? `
  43. // Performance Monitoring
  44. tracesSampleRate: 1.0, // Capture 100% of the transactions`
  45. : ''
  46. }${
  47. params.isProfilingSelected
  48. ? `
  49. // Set sampling rate for profiling - this is relative to tracesSampleRate
  50. profilesSampleRate: 1.0,`
  51. : ''
  52. }
  53. });
  54. exports.handler = Sentry.AWSLambda.wrapHandler(async (event, context) => {
  55. // Your handler code
  56. });`;
  57. const getVerifySnippet = () => `
  58. exports.handler = Sentry.AWSLambda.wrapHandler(async (event, context) => {
  59. throw new Error("This should show up in Sentry!")
  60. });`;
  61. const getMetricsConfigureSnippet = (params: DocsParams) => `
  62. Sentry.AWSLambda.init({
  63. dsn: "${params.dsn}",
  64. _experiments: {
  65. metricsAggregator: true,
  66. },
  67. });`;
  68. const onboarding: OnboardingConfig = {
  69. install: params => [
  70. {
  71. type: StepType.INSTALL,
  72. description: t('Add the Sentry Serverless SDK as a dependency:'),
  73. configurations: getInstallConfig(params, {
  74. basePackage: '@sentry/serverless',
  75. }),
  76. },
  77. ],
  78. configure: params => [
  79. {
  80. type: StepType.CONFIGURE,
  81. description: tct(
  82. "Wrap your lambda handler with Sentry's [code:wraphandler] function:",
  83. {
  84. code: <code />,
  85. }
  86. ),
  87. configurations: [
  88. {
  89. language: 'javascript',
  90. code: getSdkSetupSnippet(params),
  91. },
  92. ],
  93. },
  94. getUploadSourceMapsStep({
  95. guideLink:
  96. 'https://docs.sentry.io/platforms/javascript/guides/aws-lambda/sourcemaps/',
  97. ...params,
  98. }),
  99. ],
  100. verify: () => [
  101. {
  102. type: StepType.VERIFY,
  103. description: t(
  104. "This snippet contains an intentional error and can be used as a test to make sure that everything's working as expected."
  105. ),
  106. configurations: [
  107. {
  108. language: 'javascript',
  109. code: getVerifySnippet(),
  110. },
  111. ],
  112. },
  113. ],
  114. };
  115. const customMetricsOnboarding: OnboardingConfig = {
  116. install: params => [
  117. {
  118. type: StepType.INSTALL,
  119. description: tct(
  120. 'You need a minimum version [codeVersion:7.91.0] of [codePackage:@sentry/serverless]:',
  121. {
  122. codeVersion: <code />,
  123. codePackage: <code />,
  124. }
  125. ),
  126. configurations: getInstallConfig(params, {
  127. basePackage: '@sentry/serverless',
  128. }),
  129. },
  130. ],
  131. configure: params => [
  132. {
  133. type: StepType.CONFIGURE,
  134. description: tct(
  135. 'To enable capturing metrics, you first need to add the [codeIntegration:metricsAggregator] experiment to your [codeNamespace:Sentry.init] call in your main process.',
  136. {
  137. codeIntegration: <code />,
  138. codeNamespace: <code />,
  139. }
  140. ),
  141. configurations: [
  142. {
  143. code: [
  144. {
  145. label: 'JavaScript',
  146. value: 'javascript',
  147. language: 'javascript',
  148. code: getMetricsConfigureSnippet(params),
  149. },
  150. ],
  151. },
  152. ],
  153. },
  154. ],
  155. verify: getJSServerMetricsOnboarding().verify,
  156. };
  157. const crashReportOnboarding: OnboardingConfig = {
  158. introduction: () => getCrashReportModalIntroduction(),
  159. install: (params: Params) => getCrashReportJavaScriptInstallStep(params),
  160. configure: () => [
  161. {
  162. type: StepType.CONFIGURE,
  163. description: getCrashReportModalConfigDescription({
  164. link: 'https://docs.sentry.io/platforms/javascript/guides/aws-lambda/user-feedback/configuration/#crash-report-modal',
  165. }),
  166. },
  167. ],
  168. verify: () => [],
  169. nextSteps: () => [],
  170. };
  171. const docs: Docs = {
  172. onboarding,
  173. customMetricsOnboarding,
  174. crashReportOnboarding,
  175. };
  176. export default docs;