awslambda.tsx 5.0 KB

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