awslambda.tsx 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. import {Fragment} from 'react';
  2. import styled from '@emotion/styled';
  3. import Alert from 'sentry/components/alert';
  4. import ExternalLink from 'sentry/components/links/externalLink';
  5. import {Layout, LayoutProps} from 'sentry/components/onboarding/gettingStartedDoc/layout';
  6. import {ModuleProps} from 'sentry/components/onboarding/gettingStartedDoc/sdkDocumentation';
  7. import {StepType} from 'sentry/components/onboarding/gettingStartedDoc/step';
  8. import {t, tct} from 'sentry/locale';
  9. import {space} from 'sentry/styles/space';
  10. // Configuration Start
  11. const introduction = (
  12. <p>
  13. {tct(
  14. 'Create a deployment package on your local machine and install the required dependencies in the deployment package. For more information, see [link:AWS Lambda deployment package in Python].',
  15. {
  16. link: (
  17. <ExternalLink href="https://docs.aws.amazon.com/lambda/latest/dg/python-package.html" />
  18. ),
  19. }
  20. )}
  21. </p>
  22. );
  23. export const steps = ({
  24. dsn,
  25. }: Partial<Pick<ModuleProps, 'dsn'>> = {}): LayoutProps['steps'] => [
  26. {
  27. type: StepType.INSTALL,
  28. description: (
  29. <p>{tct('Install our Python SDK using [code:pip]:', {code: <code />})}</p>
  30. ),
  31. configurations: [
  32. {
  33. language: 'bash',
  34. code: 'pip install --upgrade sentry-sdk',
  35. },
  36. ],
  37. },
  38. {
  39. type: StepType.CONFIGURE,
  40. description: t(
  41. 'You can use the AWS Lambda integration for the Python SDK like this:'
  42. ),
  43. configurations: [
  44. {
  45. language: 'python',
  46. code: `
  47. import sentry_sdk
  48. from sentry_sdk.integrations.aws_lambda import AwsLambdaIntegration
  49. sentry_sdk.init(
  50. dsn="${dsn}",
  51. integrations=[
  52. AwsLambdaIntegration(),
  53. ],
  54. # Set traces_sample_rate to 1.0 to capture 100%
  55. # of transactions for performance monitoring.
  56. # We recommend adjusting this value in production,
  57. traces_sample_rate=1.0,
  58. )
  59. def my_function(event, context):
  60. ....
  61. `,
  62. },
  63. ],
  64. additionalInfo: (
  65. <p>
  66. {tct("Check out Sentry's [link:AWS sample apps] for detailed examples.", {
  67. link: (
  68. <ExternalLink href="https://github.com/getsentry/examples/tree/master/aws-lambda/python" />
  69. ),
  70. })}
  71. </p>
  72. ),
  73. },
  74. {
  75. title: t('Timeout Warning'),
  76. description: (
  77. <p>
  78. {tct(
  79. 'The timeout warning reports an issue when the function execution time is near the [link:configured timeout].',
  80. {
  81. link: (
  82. <ExternalLink href="https://docs.aws.amazon.com/lambda/latest/dg/configuration-function-common.html" />
  83. ),
  84. }
  85. )}
  86. </p>
  87. ),
  88. configurations: [
  89. {
  90. description: (
  91. <p>
  92. {tct(
  93. 'To enable the warning, update the SDK initialization to set [codeTimeout:timeout_warning] to [codeStatus:true]:',
  94. {codeTimeout: <code />, codeStatus: <code />}
  95. )}
  96. </p>
  97. ),
  98. language: 'python',
  99. code: `
  100. sentry_sdk.init(
  101. dsn="${dsn}",
  102. integrations=[
  103. AwsLambdaIntegration(timeout_warning=True),
  104. ],
  105. # Set traces_sample_rate to 1.0 to capture 100%
  106. # of transactions for performance monitoring.
  107. # We recommend adjusting this value in production,
  108. traces_sample_rate=1.0,
  109. )
  110. `,
  111. },
  112. ],
  113. additionalInfo: t(
  114. 'The timeout warning is sent only if the timeout in the Lambda Function configuration is set to a value greater than one second.'
  115. ),
  116. },
  117. ];
  118. // Configuration End
  119. export function GettingStartedWithAwsLambda({dsn, ...props}: ModuleProps) {
  120. return (
  121. <Fragment>
  122. <Layout steps={steps({dsn})} introduction={introduction} {...props} />
  123. <AlertWithMarginBottom type="info">
  124. {tct(
  125. 'If you are using another web framework inside of AWS Lambda, the framework might catch those exceptions before we get to see them. Make sure to enable the framework specific integration as well, if one exists. See [link:Integrations] for more information.',
  126. {
  127. link: (
  128. <ExternalLink href="https://docs.sentry.io/platforms/python/#integrations" />
  129. ),
  130. }
  131. )}
  132. </AlertWithMarginBottom>
  133. </Fragment>
  134. );
  135. }
  136. export default GettingStartedWithAwsLambda;
  137. const AlertWithMarginBottom = styled(Alert)`
  138. margin-top: ${space(2)};
  139. margin-bottom: 0;
  140. `;