python.tsx 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. import ExternalLink from 'sentry/components/links/externalLink';
  2. import {StepType} from 'sentry/components/onboarding/gettingStartedDoc/step';
  3. import {
  4. type Docs,
  5. DocsPageLocation,
  6. type DocsParams,
  7. type OnboardingConfig,
  8. } from 'sentry/components/onboarding/gettingStartedDoc/types';
  9. import {
  10. getCrashReportBackendInstallStep,
  11. getCrashReportModalConfigDescription,
  12. getCrashReportModalIntroduction,
  13. } from 'sentry/components/onboarding/gettingStartedDoc/utils/feedbackOnboarding';
  14. import {getPythonMetricsOnboarding} from 'sentry/components/onboarding/gettingStartedDoc/utils/metricsOnboarding';
  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. sentry_sdk.init(
  21. dsn="${params.dsn.public}",${
  22. params.isPerformanceSelected
  23. ? `
  24. # Set traces_sample_rate to 1.0 to capture 100%
  25. # of transactions for tracing.
  26. traces_sample_rate=1.0,`
  27. : ''
  28. }${
  29. params.isProfilingSelected &&
  30. params.profilingOptions?.defaultProfilingMode !== 'continuous'
  31. ? `
  32. # Set profiles_sample_rate to 1.0 to profile 100%
  33. # of sampled transactions.
  34. # We recommend adjusting this value in production.
  35. profiles_sample_rate=1.0,`
  36. : ''
  37. }
  38. )${
  39. params.isProfilingSelected &&
  40. params.profilingOptions?.defaultProfilingMode === 'continuous'
  41. ? `
  42. # Manually call start_profiler and stop_profiler
  43. # to profile the code in between
  44. sentry_sdk.profiler.start_profiler()
  45. # this code will be profiled
  46. #
  47. # Calls to stop_profiler are optional - if you don't stop the profiler, it will keep profiling
  48. # your application until the process exits or stop_profiler is called.
  49. sentry_sdk.profiler.stop_profiler()`
  50. : ''
  51. }`;
  52. const onboarding: OnboardingConfig = {
  53. install: (params: Params) => [
  54. {
  55. type: StepType.INSTALL,
  56. description: tct('Install our Python SDK using [code:pip]:', {
  57. code: <code />,
  58. }),
  59. configurations: [
  60. {
  61. description:
  62. params.docsLocation === DocsPageLocation.PROFILING_PAGE
  63. ? tct(
  64. 'You need a minimum version [code:1.18.0] of the [code:sentry-python] SDK for the profiling feature.',
  65. {
  66. code: <code />,
  67. }
  68. )
  69. : undefined,
  70. language: 'bash',
  71. code: getInstallSnippet(),
  72. },
  73. ],
  74. },
  75. ],
  76. configure: (params: Params) => [
  77. {
  78. type: StepType.CONFIGURE,
  79. description: t(
  80. "Import and initialize the Sentry SDK early in your application's setup:"
  81. ),
  82. configurations: [
  83. {
  84. language: 'python',
  85. code: getSdkSetupSnippet(params),
  86. },
  87. ],
  88. additionalInfo: params.isProfilingSelected &&
  89. params.profilingOptions?.defaultProfilingMode === 'continuous' && (
  90. <AlternativeConfiguration />
  91. ),
  92. },
  93. ],
  94. verify: () => [
  95. {
  96. type: StepType.VERIFY,
  97. description: t(
  98. 'One way to verify your setup is by intentionally causing an error that breaks your application.'
  99. ),
  100. configurations: [
  101. {
  102. language: 'python',
  103. description: t(
  104. 'Raise an unhandled Python exception by inserting a divide by zero expression into your application:'
  105. ),
  106. code: 'division_by_zero = 1 / 0',
  107. },
  108. ],
  109. },
  110. ],
  111. };
  112. export const crashReportOnboardingPython: OnboardingConfig = {
  113. introduction: () => getCrashReportModalIntroduction(),
  114. install: (params: Params) => getCrashReportBackendInstallStep(params),
  115. configure: () => [
  116. {
  117. type: StepType.CONFIGURE,
  118. description: getCrashReportModalConfigDescription({
  119. link: 'https://docs.sentry.io/platforms/python/user-feedback/configuration/#crash-report-modal',
  120. }),
  121. },
  122. ],
  123. verify: () => [],
  124. nextSteps: () => [],
  125. };
  126. export const performanceOnboarding: OnboardingConfig = {
  127. introduction: () =>
  128. t(
  129. "Adding Performance to your Python project is simple. Make sure you've got these basics down."
  130. ),
  131. install: onboarding.install,
  132. configure: params => [
  133. {
  134. type: StepType.CONFIGURE,
  135. description: t(
  136. "Configuration should happen as early as possible in your application's lifecycle."
  137. ),
  138. configurations: [
  139. {
  140. description: tct(
  141. "Once this is done, Sentry's Python SDK captures all unhandled exceptions and transactions. Note that [code:enable_tracing] is available in Sentry Python SDK version [code:≥ 1.16.0]. To enable tracing in older SDK versions ([code:≥ 0.11.2]), use [code:traces_sample_rate=1.0].",
  142. {code: <code />}
  143. ),
  144. language: 'python',
  145. code: `
  146. import sentry-sdk
  147. sentry_sdk.init(
  148. dsn="${params.dsn.public}",
  149. enable_tracing=True,
  150. )`,
  151. additionalInfo: tct(
  152. 'Learn more about tracing [linkTracingOptions:options], how to use the [linkTracesSampler:traces_sampler] function, or how to [linkSampleTransactions:sample transactions].',
  153. {
  154. linkTracingOptions: (
  155. <ExternalLink href="https://docs.sentry.io/platforms/python/configuration/options/#tracing-options" />
  156. ),
  157. linkTracesSampler: (
  158. <ExternalLink href="https://docs.sentry.io/platforms/python/configuration/sampling/" />
  159. ),
  160. linkSampleTransactions: (
  161. <ExternalLink href="https://docs.sentry.io/platforms/python/configuration/sampling/" />
  162. ),
  163. }
  164. ),
  165. },
  166. ],
  167. },
  168. ],
  169. verify: () => [
  170. {
  171. type: StepType.VERIFY,
  172. description: tct(
  173. 'Verify that performance monitoring is working correctly with our [link:automatic instrumentation] by simply using your Python application.',
  174. {
  175. link: (
  176. <ExternalLink href="https://docs.sentry.io/platforms/python/tracing/instrumentation/automatic-instrumentation/" />
  177. ),
  178. }
  179. ),
  180. additionalInfo: tct(
  181. 'You have the option to manually construct a transaction using [link:custom instrumentation].',
  182. {
  183. link: (
  184. <ExternalLink href="https://docs.sentry.io/platforms/python/tracing/instrumentation/custom-instrumentation/" />
  185. ),
  186. }
  187. ),
  188. },
  189. ],
  190. nextSteps: () => [],
  191. };
  192. export function AlternativeConfiguration() {
  193. return (
  194. <div>
  195. {tct(
  196. 'Alternatively, you can also explicitly control continuous profiling or use transaction profiling. See our [link:documentation] for more information.',
  197. {
  198. link: (
  199. <ExternalLink href="https://docs.sentry.io/platforms/python/profiling/" />
  200. ),
  201. }
  202. )}
  203. </div>
  204. );
  205. }
  206. const docs: Docs = {
  207. onboarding,
  208. performanceOnboarding,
  209. customMetricsOnboarding: getPythonMetricsOnboarding({
  210. installSnippet: getInstallSnippet(),
  211. }),
  212. crashReportOnboarding: crashReportOnboardingPython,
  213. };
  214. export default docs;