awslambda.tsx 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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 {PlatformKey} from 'sentry/data/platformCategories';
  5. import {t, tct} from 'sentry/locale';
  6. import {Organization} from 'sentry/types';
  7. type StepProps = {
  8. newOrg: boolean;
  9. organization: Organization;
  10. platformKey: PlatformKey;
  11. projectId: string;
  12. sentryInitContent: string;
  13. };
  14. const performanceOtherConfig = `
  15. // Performance Monitoring
  16. tracesSampleRate: 1.0, // Capture 100% of the transactions, reduce in production!`;
  17. export const steps = ({
  18. sentryInitContent,
  19. }: Partial<StepProps> = {}): LayoutProps['steps'] => [
  20. {
  21. type: StepType.INSTALL,
  22. description: t('Add the Sentry Serverless SDK as a dependency:'),
  23. configurations: [
  24. {
  25. language: 'bash',
  26. code: `
  27. # Using yarn
  28. yarn add @sentry/serverless
  29. # Using npm
  30. npm install --save @sentry/serverless
  31. `,
  32. },
  33. ],
  34. },
  35. {
  36. type: StepType.CONFIGURE,
  37. description: (
  38. <p>
  39. {tct("Wrap your lambda handler with Sentry's [code:wraphandler] function:", {
  40. code: <code />,
  41. })}
  42. </p>
  43. ),
  44. configurations: [
  45. {
  46. language: 'javascript',
  47. code: `
  48. const Sentry = require("@sentry/serverless");
  49. Sentry.AWSLambda.init({
  50. ${sentryInitContent},
  51. });
  52. exports.handler = Sentry.AWSLambda.wrapHandler(async (event, context) => {
  53. // Your handler code
  54. });
  55. `,
  56. },
  57. ],
  58. },
  59. {
  60. type: StepType.VERIFY,
  61. description: t(
  62. "This snippet contains an intentional error and can be used as a test to make sure that everything's working as expected."
  63. ),
  64. configurations: [
  65. {
  66. language: 'javascript',
  67. code: `
  68. exports.handler = Sentry.AWSLambda.wrapHandler(async (event, context) => {
  69. throw new Error("This should show up in Sentry!")
  70. });
  71. `,
  72. },
  73. ],
  74. },
  75. ];
  76. export function GettingStartedWithAwsLambda({dsn, newOrg, platformKey}: ModuleProps) {
  77. const sentryInitContent: string[] = [`dsn: "${dsn}",`, performanceOtherConfig];
  78. return (
  79. <Layout
  80. steps={steps({
  81. sentryInitContent: sentryInitContent.join('\n'),
  82. })}
  83. newOrg={newOrg}
  84. platformKey={platformKey}
  85. />
  86. );
  87. }
  88. export default GettingStartedWithAwsLambda;