awslambda.tsx 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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. }: {
  26. dsn?: string;
  27. } = {}): LayoutProps['steps'] => [
  28. {
  29. type: StepType.INSTALL,
  30. description: (
  31. <p>{tct('Install our Python SDK using [code:pip]:', {code: <code />})}</p>
  32. ),
  33. configurations: [
  34. {
  35. language: 'bash',
  36. code: 'pip install --upgrade sentry-sdk',
  37. },
  38. ],
  39. },
  40. {
  41. type: StepType.CONFIGURE,
  42. description: t(
  43. 'You can use the AWS Lambda integration for the Python SDK like this:'
  44. ),
  45. configurations: [
  46. {
  47. language: 'python',
  48. code: `
  49. import sentry_sdk
  50. from sentry_sdk.integrations.aws_lambda import AwsLambdaIntegration
  51. sentry_sdk.init(
  52. dsn="${dsn}",
  53. integrations=[
  54. AwsLambdaIntegration(),
  55. ],
  56. # Set traces_sample_rate to 1.0 to capture 100%
  57. # of transactions for performance monitoring.
  58. # We recommend adjusting this value in production,
  59. traces_sample_rate=1.0,
  60. )
  61. def my_function(event, context):
  62. ....
  63. `,
  64. },
  65. ],
  66. additionalInfo: (
  67. <p>
  68. {tct("Check out Sentry's [link:AWS sample apps] for detailed examples.", {
  69. link: (
  70. <ExternalLink href="https://github.com/getsentry/examples/tree/master/aws-lambda/python" />
  71. ),
  72. })}
  73. </p>
  74. ),
  75. },
  76. {
  77. title: t('Timeout Warning'),
  78. description: (
  79. <p>
  80. {tct(
  81. 'The timeout warning reports an issue when the function execution time is near the [link:configured timeout].',
  82. {
  83. link: (
  84. <ExternalLink href="https://docs.aws.amazon.com/lambda/latest/dg/configuration-function-common.html" />
  85. ),
  86. }
  87. )}
  88. </p>
  89. ),
  90. configurations: [
  91. {
  92. description: (
  93. <p>
  94. {tct(
  95. 'To enable the warning, update the SDK initialization to set [codeTimeout:timeout_warning] to [codeStatus:true]:',
  96. {codeTimeout: <code />, codeStatus: <code />}
  97. )}
  98. </p>
  99. ),
  100. language: 'python',
  101. code: `
  102. sentry_sdk.init(
  103. dsn="${dsn}",
  104. integrations=[
  105. AwsLambdaIntegration(timeout_warning=True),
  106. ],
  107. # Set traces_sample_rate to 1.0 to capture 100%
  108. # of transactions for performance monitoring.
  109. # We recommend adjusting this value in production,
  110. traces_sample_rate=1.0,
  111. )
  112. `,
  113. },
  114. ],
  115. additionalInfo: t(
  116. 'The timeout warning is sent only if the timeout in the Lambda Function configuration is set to a value greater than one second.'
  117. ),
  118. },
  119. ];
  120. // Configuration End
  121. export function GettingStartedWithAwsLambda({dsn, ...props}: ModuleProps) {
  122. return (
  123. <Fragment>
  124. <Layout steps={steps({dsn})} introduction={introduction} {...props} />
  125. <AlertWithMarginBottom type="info">
  126. {tct(
  127. '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.',
  128. {
  129. link: (
  130. <ExternalLink href="https://docs.sentry.io/platforms/python/#integrations" />
  131. ),
  132. }
  133. )}
  134. </AlertWithMarginBottom>
  135. </Fragment>
  136. );
  137. }
  138. export default GettingStartedWithAwsLambda;
  139. const AlertWithMarginBottom = styled(Alert)`
  140. margin-top: ${space(2)};
  141. margin-bottom: 0;
  142. `;