awslambda.tsx 4.4 KB

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