awslambda.tsx 4.9 KB

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