awslambda.tsx 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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. }: ModuleProps) {
  87. const productSelection = getProductSelectionMap(activeProductSelection);
  88. const installSnippet = getInstallSnippet({
  89. productSelection,
  90. basePackage: '@sentry/serverless',
  91. });
  92. const imports = getDefaulServerlessImports({productSelection});
  93. const integrations = getProductIntegrations({productSelection});
  94. const integrationParam =
  95. integrations.length > 0
  96. ? `integrations: [\n${joinWithIndentation(integrations)}\n],`
  97. : null;
  98. const initContent = joinWithIndentation([
  99. ...getDefaultInitParams({dsn}),
  100. ...(integrationParam ? [integrationParam] : []),
  101. ...getProductInitParams({productSelection}),
  102. ]);
  103. return (
  104. <Layout
  105. steps={steps({
  106. installSnippet,
  107. importContent: imports.join('\n'),
  108. initContent,
  109. sourceMapStep: getUploadSourceMapsStep({
  110. guideLink:
  111. 'https://docs.sentry.io/platforms/node/guides/aws-lambda/sourcemaps/',
  112. organization,
  113. platformKey,
  114. projectId,
  115. newOrg,
  116. }),
  117. })}
  118. newOrg={newOrg}
  119. platformKey={platformKey}
  120. />
  121. );
  122. }
  123. export default GettingStartedWithAwsLambda;