serverless.tsx 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. import {Fragment} from 'react';
  2. import ExternalLink from 'sentry/components/links/externalLink';
  3. import {StepType} from 'sentry/components/onboarding/gettingStartedDoc/step';
  4. import {
  5. type Docs,
  6. DocsPageLocation,
  7. type DocsParams,
  8. type OnboardingConfig,
  9. } from 'sentry/components/onboarding/gettingStartedDoc/types';
  10. import {
  11. AlternativeConfiguration,
  12. crashReportOnboardingPython,
  13. } from 'sentry/gettingStartedDocs/python/python';
  14. import {t, tct} from 'sentry/locale';
  15. type Params = DocsParams;
  16. const getInstallSnippet = () => `pip install --upgrade sentry-sdk`;
  17. const getSdkSetupSnippet = (params: Params) => `
  18. import sentry_sdk
  19. from sentry_sdk.integrations.serverless import serverless_function
  20. sentry_sdk.init(
  21. dsn="${params.dsn.public}",
  22. # Add data like request headers and IP for users,
  23. # see https://docs.sentry.io/platforms/python/data-management/data-collected/ for more info
  24. send_default_pii=True,${
  25. params.isPerformanceSelected
  26. ? `
  27. # Set traces_sample_rate to 1.0 to capture 100%
  28. # of transactions for tracing.
  29. traces_sample_rate=1.0,`
  30. : ''
  31. }${
  32. params.isProfilingSelected &&
  33. params.profilingOptions?.defaultProfilingMode !== 'continuous'
  34. ? `
  35. # Set profiles_sample_rate to 1.0 to profile 100%
  36. # of sampled transactions.
  37. # We recommend adjusting this value in production.
  38. profiles_sample_rate=1.0,`
  39. : params.isProfilingSelected &&
  40. params.profilingOptions?.defaultProfilingMode === 'continuous'
  41. ? `
  42. _experiments={
  43. # Set continuous_profiling_auto_start to True
  44. # to automatically start the profiler on when
  45. # possible.
  46. "continuous_profiling_auto_start": True,
  47. },`
  48. : ''
  49. }
  50. )
  51. @serverless_function
  52. def my_function(...): ...`;
  53. const getVerifySnippet = () => `import sentry_sdk
  54. from sentry_sdk.integrations.serverless import serverless_function
  55. sentry_sdk.init(...) # same as above
  56. @serverless_function
  57. def my_function(...):
  58. 1/0 # raises an error`;
  59. const onboarding: OnboardingConfig = {
  60. introduction: () => (
  61. <Fragment>
  62. <p>
  63. {tct(
  64. 'It is recommended to use an [link:integration for your particular serverless environment if available], as those are easier to use and capture more useful information.',
  65. {
  66. link: (
  67. <ExternalLink href="https://docs.sentry.io/platforms/python/#serverless" />
  68. ),
  69. }
  70. )}
  71. </p>
  72. <p>
  73. {t(
  74. 'If you use a serverless provider not directly supported by the SDK, you can use this generic integration.'
  75. )}
  76. </p>
  77. </Fragment>
  78. ),
  79. install: (params: Params) => [
  80. {
  81. type: StepType.INSTALL,
  82. description: tct('Install our Python SDK using [code:pip]:', {
  83. code: <code />,
  84. }),
  85. configurations: [
  86. {
  87. description:
  88. params.docsLocation === DocsPageLocation.PROFILING_PAGE
  89. ? tct(
  90. 'You need a minimum version [code:1.18.0] of the [code:sentry-python] SDK for the profiling feature.',
  91. {
  92. code: <code />,
  93. }
  94. )
  95. : undefined,
  96. language: 'bash',
  97. code: getInstallSnippet(),
  98. },
  99. ],
  100. },
  101. ],
  102. configure: (params: Params) => [
  103. {
  104. type: StepType.CONFIGURE,
  105. description: tct(
  106. 'Apply the [code:serverless_function] decorator to each function that might throw errors:',
  107. {code: <code />}
  108. ),
  109. configurations: [
  110. {
  111. language: 'python',
  112. code: getSdkSetupSnippet(params),
  113. },
  114. ],
  115. additionalInfo: params.isProfilingSelected &&
  116. params.profilingOptions?.defaultProfilingMode === 'continuous' && (
  117. <AlternativeConfiguration />
  118. ),
  119. },
  120. ],
  121. verify: () => [
  122. {
  123. type: StepType.VERIFY,
  124. description: tct(
  125. 'Wrap a functions with the [code:serverless_function] that triggers an error:',
  126. {
  127. code: <code />,
  128. }
  129. ),
  130. configurations: [
  131. {
  132. language: 'python',
  133. code: getVerifySnippet(),
  134. },
  135. ],
  136. additionalInfo: t(
  137. 'Now deploy your function. When you now run your function an error event will be sent to Sentry.'
  138. ),
  139. },
  140. ],
  141. };
  142. const docs: Docs = {
  143. onboarding,
  144. crashReportOnboarding: crashReportOnboardingPython,
  145. };
  146. export default docs;