awslambda.tsx 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  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 {StepType} from 'sentry/components/onboarding/gettingStartedDoc/step';
  6. import {
  7. type Docs,
  8. DocsPageLocation,
  9. type DocsParams,
  10. type OnboardingConfig,
  11. } from 'sentry/components/onboarding/gettingStartedDoc/types';
  12. import {getPythonMetricsOnboarding} from 'sentry/components/onboarding/gettingStartedDoc/utils/metricsOnboarding';
  13. import {
  14. AlternativeConfiguration,
  15. crashReportOnboardingPython,
  16. } from 'sentry/gettingStartedDocs/python/python';
  17. import {t, tct} from 'sentry/locale';
  18. import {space} from 'sentry/styles/space';
  19. import {trackAnalytics} from 'sentry/utils/analytics';
  20. import {
  21. InstallationMode,
  22. platformOptions,
  23. } from 'sentry/views/onboarding/integrationSetup';
  24. type PlatformOptions = typeof platformOptions;
  25. type Params = DocsParams<PlatformOptions>;
  26. const getInstallSnippet = () => `pip install --upgrade sentry-sdk`;
  27. const getSdkSetupSnippet = (params: Params) => `
  28. import sentry_sdk
  29. from sentry_sdk.integrations.aws_lambda import AwsLambdaIntegration
  30. sentry_sdk.init(
  31. dsn="${params.dsn.public}",
  32. integrations=[AwsLambdaIntegration()],${
  33. params.isPerformanceSelected
  34. ? `
  35. # Set traces_sample_rate to 1.0 to capture 100%
  36. # of transactions for tracing.
  37. traces_sample_rate=1.0,`
  38. : ''
  39. }${
  40. params.isProfilingSelected &&
  41. params.profilingOptions?.defaultProfilingMode !== 'continuous'
  42. ? `
  43. # Set profiles_sample_rate to 1.0 to profile 100%
  44. # of sampled transactions.
  45. # We recommend adjusting this value in production.
  46. profiles_sample_rate=1.0,`
  47. : params.isProfilingSelected &&
  48. params.profilingOptions?.defaultProfilingMode === 'continuous'
  49. ? `
  50. _experiments={
  51. # Set continuous_profiling_auto_start to True
  52. # to automatically start the profiler on when
  53. # possible.
  54. "continuous_profiling_auto_start": True,
  55. },`
  56. : ''
  57. }
  58. )
  59. def my_function(event, context):
  60. ....`;
  61. const getTimeoutWarningSnippet = (params: Params) => `
  62. sentry_sdk.init(
  63. dsn="${params.dsn.public}",
  64. integrations=[
  65. AwsLambdaIntegration(timeout_warning=True),
  66. ],
  67. )`;
  68. const onboarding: OnboardingConfig<PlatformOptions> = {
  69. introduction: () =>
  70. tct(
  71. '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].',
  72. {
  73. link: (
  74. <ExternalLink href="https://docs.aws.amazon.com/lambda/latest/dg/python-package.html" />
  75. ),
  76. }
  77. ),
  78. install: (params: Params) => [
  79. {
  80. type: StepType.INSTALL,
  81. description: tct('Install our Python SDK using [code:pip]:', {code: <code />}),
  82. configurations: [
  83. {
  84. description:
  85. params.docsLocation === DocsPageLocation.PROFILING_PAGE
  86. ? tct(
  87. 'You need a minimum version [code:1.18.0] of the [code:sentry-python] SDK for the profiling feature.',
  88. {
  89. code: <code />,
  90. }
  91. )
  92. : undefined,
  93. language: 'bash',
  94. code: getInstallSnippet(),
  95. },
  96. ],
  97. },
  98. ],
  99. configure: (params: Params) => [
  100. {
  101. type: StepType.CONFIGURE,
  102. description: t(
  103. 'You can use the AWS Lambda integration for the Python SDK like this:'
  104. ),
  105. configurations: [
  106. {
  107. language: 'python',
  108. code: getSdkSetupSnippet(params),
  109. },
  110. ],
  111. additionalInfo: (
  112. <Fragment>
  113. {params.isProfilingSelected &&
  114. params.profilingOptions?.defaultProfilingMode === 'continuous' && (
  115. <Fragment>
  116. <AlternativeConfiguration />
  117. <br />
  118. </Fragment>
  119. )}
  120. {tct("Check out Sentry's [link:AWS sample apps] for detailed examples.", {
  121. link: (
  122. <ExternalLink href="https://github.com/getsentry/examples/tree/master/aws-lambda/python" />
  123. ),
  124. })}
  125. </Fragment>
  126. ),
  127. },
  128. {
  129. title: t('Timeout Warning'),
  130. description: tct(
  131. 'The timeout warning reports an issue when the function execution time is near the [link:configured timeout].',
  132. {
  133. link: (
  134. <ExternalLink href="https://docs.aws.amazon.com/lambda/latest/dg/configuration-function-common.html" />
  135. ),
  136. }
  137. ),
  138. configurations: [
  139. {
  140. description: tct(
  141. 'To enable the warning, update the SDK initialization to set [code:timeout_warning] to [code:true]:',
  142. {code: <code />}
  143. ),
  144. language: 'python',
  145. code: getTimeoutWarningSnippet(params),
  146. },
  147. {
  148. description: t(
  149. 'The timeout warning is sent only if the timeout in the Lambda Function configuration is set to a value greater than one second.'
  150. ),
  151. },
  152. ],
  153. additionalInfo: (
  154. <AlertWithMarginBottom type="info">
  155. {tct(
  156. '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.',
  157. {
  158. link: (
  159. <ExternalLink href="https://docs.sentry.io/platforms/python/#integrations" />
  160. ),
  161. }
  162. )}
  163. </AlertWithMarginBottom>
  164. ),
  165. },
  166. ],
  167. verify: () => [],
  168. onPlatformOptionsChange(params) {
  169. return option => {
  170. if (option.installationMode === InstallationMode.MANUAL) {
  171. trackAnalytics('integrations.switch_manual_sdk_setup', {
  172. integration_type: 'first_party',
  173. integration: 'aws_lambda',
  174. view: 'onboarding',
  175. organization: params.organization,
  176. });
  177. }
  178. };
  179. },
  180. };
  181. const docs: Docs<PlatformOptions> = {
  182. onboarding,
  183. customMetricsOnboarding: getPythonMetricsOnboarding({
  184. installSnippet: getInstallSnippet(),
  185. }),
  186. crashReportOnboarding: crashReportOnboardingPython,
  187. platformOptions,
  188. };
  189. export default docs;
  190. const AlertWithMarginBottom = styled(Alert)`
  191. margin-top: ${space(2)};
  192. margin-bottom: 0;
  193. `;