awslambda.tsx 5.0 KB

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