awslambda.tsx 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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 {t, tct} from 'sentry/locale';
  14. import {trackAnalytics} from 'sentry/utils/analytics';
  15. import {getInstallConfig, getSdkInitSnippet} from 'sentry/utils/gettingStartedDocs/node';
  16. import {
  17. InstallationMode,
  18. platformOptions,
  19. } from 'sentry/views/onboarding/integrationSetup';
  20. type PlatformOptions = typeof platformOptions;
  21. type Params = DocsParams<PlatformOptions>;
  22. const getSdkSetupSnippet = (params: Params) => `
  23. // IMPORTANT: Make sure to import and initialize Sentry at the top of your file.
  24. ${getSdkInitSnippet(params, 'aws')}
  25. // Place any other require/import statements here
  26. exports.handler = Sentry.wrapHandler(async (event, context) => {
  27. // Your handler code
  28. });`;
  29. const getVerifySnippet = () => `
  30. exports.handler = Sentry.wrapHandler(async (event, context) => {
  31. throw new Error("This should show up in Sentry!")
  32. });`;
  33. const onboarding: OnboardingConfig<PlatformOptions> = {
  34. introduction: () =>
  35. tct('In this quick guide you’ll use [strong:npm] or [strong:yarn] to set up:', {
  36. strong: <strong />,
  37. }),
  38. install: params => [
  39. {
  40. type: StepType.INSTALL,
  41. description: t('Add the Sentry AWS Serverless SDK as a dependency:'),
  42. configurations: getInstallConfig(params, {
  43. basePackage: '@sentry/aws-serverless',
  44. }),
  45. },
  46. ],
  47. configure: params => [
  48. {
  49. type: StepType.CONFIGURE,
  50. description: tct(
  51. "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:",
  52. {
  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. onPlatformOptionsChange(params) {
  84. return option => {
  85. if (option.installationMode === InstallationMode.MANUAL) {
  86. trackAnalytics('integrations.switch_manual_sdk_setup', {
  87. integration_type: 'first_party',
  88. integration: 'aws_lambda',
  89. view: 'onboarding',
  90. organization: params.organization,
  91. });
  92. }
  93. };
  94. },
  95. };
  96. const crashReportOnboarding: OnboardingConfig<PlatformOptions> = {
  97. introduction: () => getCrashReportModalIntroduction(),
  98. install: (params: Params) => getCrashReportJavaScriptInstallStep(params),
  99. configure: () => [
  100. {
  101. type: StepType.CONFIGURE,
  102. description: getCrashReportModalConfigDescription({
  103. link: 'https://docs.sentry.io/platforms/javascript/guides/aws-lambda/user-feedback/configuration/#crash-report-modal',
  104. }),
  105. },
  106. ],
  107. verify: () => [],
  108. nextSteps: () => [],
  109. };
  110. const docs: Docs<PlatformOptions> = {
  111. onboarding,
  112. crashReportOnboarding,
  113. platformOptions,
  114. };
  115. export default docs;