awslambda.tsx 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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 {getUploadSourceMapsStep} from 'sentry/components/onboarding/gettingStartedDoc/utils';
  5. import {PlatformKey} from 'sentry/data/platformCategories';
  6. import {t, tct} from 'sentry/locale';
  7. import {Organization} from 'sentry/types';
  8. type StepProps = {
  9. newOrg: boolean;
  10. organization: Organization;
  11. platformKey: PlatformKey;
  12. projectId: string;
  13. sentryInitContent: string;
  14. };
  15. const performanceOtherConfig = `
  16. // Performance Monitoring
  17. tracesSampleRate: 1.0, // Capture 100% of the transactions, reduce in production!`;
  18. export const steps = ({
  19. sentryInitContent,
  20. ...props
  21. }: Partial<StepProps> = {}): LayoutProps['steps'] => [
  22. {
  23. type: StepType.INSTALL,
  24. description: t('Add the Sentry Serverless SDK as a dependency:'),
  25. configurations: [
  26. {
  27. language: 'bash',
  28. code: `
  29. # Using yarn
  30. yarn add @sentry/serverless
  31. # Using npm
  32. npm install --save @sentry/serverless
  33. `,
  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. const Sentry = require("@sentry/serverless");
  51. Sentry.AWSLambda.init({
  52. ${sentryInitContent},
  53. });
  54. exports.handler = Sentry.AWSLambda.wrapHandler(async (event, context) => {
  55. // Your handler code
  56. });
  57. `,
  58. },
  59. ],
  60. },
  61. getUploadSourceMapsStep({
  62. guideLink: 'https://docs.sentry.io/platforms/node/sourcemaps/',
  63. ...props,
  64. }),
  65. {
  66. type: StepType.VERIFY,
  67. description: t(
  68. "This snippet contains an intentional error and can be used as a test to make sure that everything's working as expected."
  69. ),
  70. configurations: [
  71. {
  72. language: 'javascript',
  73. code: `
  74. exports.handler = Sentry.AWSLambda.wrapHandler(async (event, context) => {
  75. throw new Error("This should show up in Sentry!")
  76. });
  77. `,
  78. },
  79. ],
  80. },
  81. ];
  82. export function GettingStartedWithAwsLambda({
  83. dsn,
  84. organization,
  85. newOrg,
  86. platformKey,
  87. projectId,
  88. }: ModuleProps) {
  89. const sentryInitContent: string[] = [`dsn: "${dsn}",`, performanceOtherConfig];
  90. return (
  91. <Layout
  92. steps={steps({
  93. sentryInitContent: sentryInitContent.join('\n'),
  94. organization,
  95. newOrg,
  96. platformKey,
  97. projectId,
  98. })}
  99. newOrg={newOrg}
  100. platformKey={platformKey}
  101. />
  102. );
  103. }
  104. export default GettingStartedWithAwsLambda;