awslambda.tsx 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. import {Layout, LayoutProps} from 'sentry/components/onboarding/gettingStartedDoc/layout';
  2. import {ModuleProps} from 'sentry/components/onboarding/gettingStartedDoc/sdkDocumentation';
  3. import {StepProps, StepType} from 'sentry/components/onboarding/gettingStartedDoc/step';
  4. import {getUploadSourceMapsStep} from 'sentry/components/onboarding/gettingStartedDoc/utils';
  5. import {t, tct} from 'sentry/locale';
  6. import {
  7. getDefaulServerlessImports,
  8. getDefaultInitParams,
  9. getInstallSnippet,
  10. getProductInitParams,
  11. getProductIntegrations,
  12. getProductSelectionMap,
  13. joinWithIndentation,
  14. } from 'sentry/utils/gettingStartedDocs/node';
  15. interface StepsParams {
  16. importContent: string;
  17. initContent: string;
  18. installSnippetNpm: string;
  19. installSnippetYarn: string;
  20. sourceMapStep: StepProps;
  21. }
  22. export const steps = ({
  23. installSnippetYarn,
  24. installSnippetNpm,
  25. importContent,
  26. initContent,
  27. sourceMapStep,
  28. }: StepsParams): LayoutProps['steps'] => [
  29. {
  30. type: StepType.INSTALL,
  31. description: t('Add the Sentry Serverless SDK as a dependency:'),
  32. configurations: [
  33. {
  34. code: [
  35. {
  36. label: 'npm',
  37. value: 'npm',
  38. language: 'bash',
  39. code: installSnippetNpm,
  40. },
  41. {
  42. label: 'yarn',
  43. value: 'yarn',
  44. language: 'bash',
  45. code: installSnippetYarn,
  46. },
  47. ],
  48. },
  49. ],
  50. },
  51. {
  52. type: StepType.CONFIGURE,
  53. description: (
  54. <p>
  55. {tct("Wrap your lambda handler with Sentry's [code:wraphandler] function:", {
  56. code: <code />,
  57. })}
  58. </p>
  59. ),
  60. configurations: [
  61. {
  62. language: 'javascript',
  63. code: `
  64. ${importContent}
  65. Sentry.AWSLambda.init({
  66. ${initContent}
  67. });
  68. exports.handler = Sentry.AWSLambda.wrapHandler(async (event, context) => {
  69. // Your handler code
  70. });
  71. `,
  72. },
  73. ],
  74. },
  75. sourceMapStep,
  76. {
  77. type: StepType.VERIFY,
  78. description: t(
  79. "This snippet contains an intentional error and can be used as a test to make sure that everything's working as expected."
  80. ),
  81. configurations: [
  82. {
  83. language: 'javascript',
  84. code: `
  85. exports.handler = Sentry.AWSLambda.wrapHandler(async (event, context) => {
  86. throw new Error("This should show up in Sentry!")
  87. });
  88. `,
  89. },
  90. ],
  91. },
  92. ];
  93. export function GettingStartedWithAwsLambda({
  94. dsn,
  95. newOrg,
  96. platformKey,
  97. activeProductSelection = [],
  98. organization,
  99. projectId,
  100. ...props
  101. }: ModuleProps) {
  102. const productSelection = getProductSelectionMap(activeProductSelection);
  103. const imports = getDefaulServerlessImports({productSelection});
  104. const integrations = getProductIntegrations({productSelection});
  105. const integrationParam =
  106. integrations.length > 0
  107. ? `integrations: [\n${joinWithIndentation(integrations)}\n],`
  108. : null;
  109. const initContent = joinWithIndentation([
  110. ...getDefaultInitParams({dsn}),
  111. ...(integrationParam ? [integrationParam] : []),
  112. ...getProductInitParams({productSelection}),
  113. ]);
  114. return (
  115. <Layout
  116. steps={steps({
  117. installSnippetNpm: getInstallSnippet({
  118. basePackage: '@sentry/serverless',
  119. productSelection,
  120. packageManager: 'npm',
  121. }),
  122. installSnippetYarn: getInstallSnippet({
  123. basePackage: '@sentry/serverless',
  124. productSelection,
  125. packageManager: 'yarn',
  126. }),
  127. importContent: imports.join('\n'),
  128. initContent,
  129. sourceMapStep: getUploadSourceMapsStep({
  130. guideLink:
  131. 'https://docs.sentry.io/platforms/node/guides/aws-lambda/sourcemaps/',
  132. organization,
  133. platformKey,
  134. projectId,
  135. newOrg,
  136. }),
  137. })}
  138. newOrg={newOrg}
  139. platformKey={platformKey}
  140. {...props}
  141. />
  142. );
  143. }
  144. export default GettingStartedWithAwsLambda;