awslambda.tsx 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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. installSnippet: string;
  19. sourceMapStep: StepProps;
  20. }
  21. export const steps = ({
  22. installSnippet,
  23. importContent,
  24. initContent,
  25. sourceMapStep,
  26. }: StepsParams): LayoutProps['steps'] => [
  27. {
  28. type: StepType.INSTALL,
  29. description: t('Add the Sentry Serverless SDK as a dependency:'),
  30. configurations: [
  31. {
  32. language: 'bash',
  33. code: installSnippet,
  34. },
  35. ],
  36. },
  37. {
  38. type: StepType.CONFIGURE,
  39. description: (
  40. <p>
  41. {tct("Wrap your lambda handler with Sentry's [code:wraphandler] function:", {
  42. code: <code />,
  43. })}
  44. </p>
  45. ),
  46. configurations: [
  47. {
  48. language: 'javascript',
  49. code: `
  50. ${importContent}
  51. Sentry.AWSLambda.init({
  52. ${initContent}
  53. });
  54. exports.handler = Sentry.AWSLambda.wrapHandler(async (event, context) => {
  55. // Your handler code
  56. });
  57. `,
  58. },
  59. ],
  60. },
  61. sourceMapStep,
  62. {
  63. type: StepType.VERIFY,
  64. description: t(
  65. "This snippet contains an intentional error and can be used as a test to make sure that everything's working as expected."
  66. ),
  67. configurations: [
  68. {
  69. language: 'javascript',
  70. code: `
  71. exports.handler = Sentry.AWSLambda.wrapHandler(async (event, context) => {
  72. throw new Error("This should show up in Sentry!")
  73. });
  74. `,
  75. },
  76. ],
  77. },
  78. ];
  79. export function GettingStartedWithAwsLambda({
  80. dsn,
  81. newOrg,
  82. platformKey,
  83. activeProductSelection = [],
  84. organization,
  85. projectId,
  86. ...props
  87. }: ModuleProps) {
  88. const productSelection = getProductSelectionMap(activeProductSelection);
  89. const installSnippet = getInstallSnippet({
  90. productSelection,
  91. basePackage: '@sentry/serverless',
  92. });
  93. const imports = getDefaulServerlessImports({productSelection});
  94. const integrations = getProductIntegrations({productSelection});
  95. const integrationParam =
  96. integrations.length > 0
  97. ? `integrations: [\n${joinWithIndentation(integrations)}\n],`
  98. : null;
  99. const initContent = joinWithIndentation([
  100. ...getDefaultInitParams({dsn}),
  101. ...(integrationParam ? [integrationParam] : []),
  102. ...getProductInitParams({productSelection}),
  103. ]);
  104. return (
  105. <Layout
  106. steps={steps({
  107. installSnippet,
  108. importContent: imports.join('\n'),
  109. initContent,
  110. sourceMapStep: getUploadSourceMapsStep({
  111. guideLink:
  112. 'https://docs.sentry.io/platforms/node/guides/aws-lambda/sourcemaps/',
  113. organization,
  114. platformKey,
  115. projectId,
  116. newOrg,
  117. }),
  118. })}
  119. newOrg={newOrg}
  120. platformKey={platformKey}
  121. {...props}
  122. />
  123. );
  124. }
  125. export default GettingStartedWithAwsLambda;