awslambda.tsx 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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: 'https://docs.sentry.io/platforms/node/guides/aws-lambda/sourcemaps/',
  96. ...params,
  97. }),
  98. ],
  99. verify: () => [
  100. {
  101. type: StepType.VERIFY,
  102. description: t(
  103. "This snippet contains an intentional error and can be used as a test to make sure that everything's working as expected."
  104. ),
  105. configurations: [
  106. {
  107. language: 'javascript',
  108. code: getVerifySnippet(),
  109. },
  110. ],
  111. },
  112. ],
  113. };
  114. const customMetricsOnboarding: OnboardingConfig = {
  115. install: params => [
  116. {
  117. type: StepType.INSTALL,
  118. description: tct(
  119. 'You need a minimum version [codeVersion:7.91.0] of [codePackage:@sentry/serverless]:',
  120. {
  121. codeVersion: <code />,
  122. codePackage: <code />,
  123. }
  124. ),
  125. configurations: getInstallConfig(params, {
  126. basePackage: '@sentry/serverless',
  127. }),
  128. },
  129. ],
  130. configure: params => [
  131. {
  132. type: StepType.CONFIGURE,
  133. description: tct(
  134. 'To enable capturing metrics, you first need to add the [codeIntegration:metricsAggregator] experiment to your [codeNamespace:Sentry.init] call in your main process.',
  135. {
  136. codeIntegration: <code />,
  137. codeNamespace: <code />,
  138. }
  139. ),
  140. configurations: [
  141. {
  142. code: [
  143. {
  144. label: 'JavaScript',
  145. value: 'javascript',
  146. language: 'javascript',
  147. code: getMetricsConfigureSnippet(params),
  148. },
  149. ],
  150. },
  151. ],
  152. },
  153. ],
  154. verify: getJSServerMetricsOnboarding().verify,
  155. };
  156. const crashReportOnboarding: OnboardingConfig = {
  157. introduction: () => getCrashReportModalIntroduction(),
  158. install: (params: Params) => getCrashReportJavaScriptInstallStep(params),
  159. configure: () => [
  160. {
  161. type: StepType.CONFIGURE,
  162. description: getCrashReportModalConfigDescription({
  163. link: 'https://docs.sentry.io/platforms/node/guides/aws-lambda/user-feedback/configuration/#crash-report-modal',
  164. }),
  165. },
  166. ],
  167. verify: () => [],
  168. nextSteps: () => [],
  169. };
  170. const docs: Docs = {
  171. onboarding,
  172. customMetricsOnboarding,
  173. crashReportOnboarding,
  174. };
  175. export default docs;