bottle.tsx 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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 {getPythonMetricsOnboarding} from 'sentry/components/onboarding/gettingStartedDoc/utils/metricsOnboarding';
  10. import {
  11. feedbackOnboardingJsLoader,
  12. replayOnboardingJsLoader,
  13. } from 'sentry/gettingStartedDocs/javascript/jsLoader/jsLoader';
  14. import {
  15. AlternativeConfiguration,
  16. crashReportOnboardingPython,
  17. featureFlagOnboarding,
  18. } from 'sentry/gettingStartedDocs/python/python';
  19. import {t, tct} from 'sentry/locale';
  20. type Params = DocsParams;
  21. const getInstallSnippet = () => `pip install --upgrade 'sentry-sdk[bottle]'`;
  22. const getSdkSetupSnippet = (params: Params) => `
  23. import sentry_sdk
  24. sentry_sdk.init(
  25. dsn="${params.dsn.public}",${
  26. params.isPerformanceSelected
  27. ? `
  28. # Set traces_sample_rate to 1.0 to capture 100%
  29. # of transactions for tracing.
  30. traces_sample_rate=1.0,`
  31. : ''
  32. }${
  33. params.isProfilingSelected &&
  34. params.profilingOptions?.defaultProfilingMode !== 'continuous'
  35. ? `
  36. # Set profiles_sample_rate to 1.0 to profile 100%
  37. # of sampled transactions.
  38. # We recommend adjusting this value in production.
  39. profiles_sample_rate=1.0,`
  40. : params.isProfilingSelected &&
  41. params.profilingOptions?.defaultProfilingMode === 'continuous'
  42. ? `
  43. _experiments={
  44. # Set continuous_profiling_auto_start to True
  45. # to automatically start the profiler on when
  46. # possible.
  47. "continuous_profiling_auto_start": True,
  48. },`
  49. : ''
  50. }
  51. )
  52. `;
  53. const onboarding: OnboardingConfig = {
  54. introduction: () =>
  55. tct('The Bottle integration adds support for the [link:Bottle Web Framework].', {
  56. link: <ExternalLink href="https://bottlepy.org/docs/dev/" />,
  57. }),
  58. install: (params: Params) => [
  59. {
  60. type: StepType.INSTALL,
  61. description: tct(
  62. 'Install [code:sentry-sdk] from PyPI with the [code:bottle] extra:',
  63. {
  64. code: <code />,
  65. }
  66. ),
  67. configurations: [
  68. {
  69. description:
  70. params.docsLocation === DocsPageLocation.PROFILING_PAGE
  71. ? tct(
  72. 'You need a minimum version [code:1.18.0] of the [code:sentry-python] SDK for the profiling feature.',
  73. {
  74. code: <code />,
  75. }
  76. )
  77. : undefined,
  78. language: 'bash',
  79. code: getInstallSnippet(),
  80. },
  81. ],
  82. },
  83. ],
  84. configure: (params: Params) => [
  85. {
  86. type: StepType.CONFIGURE,
  87. description: tct(
  88. 'If you have the [code:bottle] package in your dependencies, the Bottle integration will be enabled automatically when you initialize the Sentry SDK. Initialize the Sentry SDK before your app has been initialized:',
  89. {
  90. code: <code />,
  91. }
  92. ),
  93. configurations: [
  94. {
  95. language: 'python',
  96. code: `from bottle import Bottle
  97. ${getSdkSetupSnippet(params)}
  98. app = Bottle()
  99. `,
  100. },
  101. ],
  102. additionalInfo: params.isProfilingSelected &&
  103. params.profilingOptions?.defaultProfilingMode === 'continuous' && (
  104. <AlternativeConfiguration />
  105. ),
  106. },
  107. ],
  108. verify: (params: Params) => [
  109. {
  110. type: StepType.VERIFY,
  111. description: t(
  112. 'To verify that everything is working, trigger an error on purpose:'
  113. ),
  114. configurations: [
  115. {
  116. language: 'python',
  117. code: `from bottle import Bottle, run
  118. ${getSdkSetupSnippet(params)}
  119. app = Bottle()
  120. @app.route('/')
  121. def hello():
  122. 1/0
  123. return "Hello World!"
  124. run(app, host='localhost', port=8000)
  125. `,
  126. },
  127. ],
  128. additionalInfo: (
  129. <span>
  130. <p>
  131. {tct(
  132. 'When you point your browser to [link:http://localhost:8000/] a transaction in the Performance section of Sentry will be created.',
  133. {
  134. link: <ExternalLink href="http://localhost:8000/" />,
  135. }
  136. )}
  137. </p>
  138. <p>
  139. {t(
  140. 'Additionally, an error event will be sent to Sentry and will be connected to the transaction.'
  141. )}
  142. </p>
  143. <p>{t('It takes a couple of moments for the data to appear in Sentry.')}</p>
  144. </span>
  145. ),
  146. },
  147. ],
  148. nextSteps: () => [],
  149. };
  150. const docs: Docs = {
  151. onboarding,
  152. replayOnboardingJsLoader,
  153. customMetricsOnboarding: getPythonMetricsOnboarding({
  154. installSnippet: getInstallSnippet(),
  155. }),
  156. crashReportOnboarding: crashReportOnboardingPython,
  157. featureFlagOnboarding,
  158. feedbackOnboardingJsLoader,
  159. };
  160. export default docs;