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