awslambda.tsx 2.8 KB

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