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