awslambda.tsx 4.5 KB

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