bottle.tsx 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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 replayOnboardingJsLoader from 'sentry/gettingStartedDocs/javascript/jsLoader/jsLoader';
  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[bottle]'`;
  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. : params.isProfilingSelected &&
  37. params.profilingOptions?.defaultProfilingMode === 'continuous'
  38. ? `
  39. _experiments={
  40. # Set continuous_profiling_auto_start to True
  41. # to automatically start the profiler on when
  42. # possible.
  43. "continuous_profiling_auto_start": True,
  44. },`
  45. : ''
  46. }
  47. )
  48. `;
  49. const onboarding: OnboardingConfig = {
  50. introduction: () =>
  51. tct('The Bottle integration adds support for the [link:Bottle Web Framework].', {
  52. link: <ExternalLink href="https://bottlepy.org/docs/dev/" />,
  53. }),
  54. install: (params: Params) => [
  55. {
  56. type: StepType.INSTALL,
  57. description: tct(
  58. 'Install [code:sentry-sdk] from PyPI with the [code:bottle] extra:',
  59. {
  60. code: <code />,
  61. }
  62. ),
  63. configurations: [
  64. {
  65. description:
  66. params.docsLocation === DocsPageLocation.PROFILING_PAGE
  67. ? tct(
  68. 'You need a minimum version [code:1.18.0] of the [code:sentry-python] SDK for the profiling feature.',
  69. {
  70. code: <code />,
  71. }
  72. )
  73. : undefined,
  74. language: 'bash',
  75. code: getInstallSnippet(),
  76. },
  77. ],
  78. },
  79. ],
  80. configure: (params: Params) => [
  81. {
  82. type: StepType.CONFIGURE,
  83. description: tct(
  84. '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:',
  85. {
  86. code: <code />,
  87. }
  88. ),
  89. configurations: [
  90. {
  91. language: 'python',
  92. code: `from bottle import Bottle
  93. ${getSdkSetupSnippet(params)}
  94. app = Bottle()
  95. `,
  96. },
  97. ],
  98. additionalInfo: params.isProfilingSelected &&
  99. params.profilingOptions?.defaultProfilingMode === 'continuous' && (
  100. <AlternativeConfiguration />
  101. ),
  102. },
  103. ],
  104. verify: (params: Params) => [
  105. {
  106. type: StepType.VERIFY,
  107. description: t(
  108. 'To verify that everything is working, trigger an error on purpose:'
  109. ),
  110. configurations: [
  111. {
  112. language: 'python',
  113. code: `from bottle import Bottle, run
  114. ${getSdkSetupSnippet(params)}
  115. app = Bottle()
  116. @app.route('/')
  117. def hello():
  118. 1/0
  119. return "Hello World!"
  120. run(app, host='localhost', port=8000)
  121. `,
  122. },
  123. ],
  124. additionalInfo: (
  125. <span>
  126. <p>
  127. {tct(
  128. 'When you point your browser to [link:http://localhost:8000/] a transaction in the Performance section of Sentry will be created.',
  129. {
  130. link: <ExternalLink href="http://localhost:8000/" />,
  131. }
  132. )}
  133. </p>
  134. <p>
  135. {t(
  136. 'Additionally, an error event will be sent to Sentry and will be connected to the transaction.'
  137. )}
  138. </p>
  139. <p>{t('It takes a couple of moments for the data to appear in Sentry.')}</p>
  140. </span>
  141. ),
  142. },
  143. ],
  144. nextSteps: () => [],
  145. };
  146. const docs: Docs = {
  147. onboarding,
  148. replayOnboardingJsLoader,
  149. customMetricsOnboarding: getPythonMetricsOnboarding({
  150. installSnippet: getInstallSnippet(),
  151. }),
  152. crashReportOnboarding: crashReportOnboardingPython,
  153. };
  154. export default docs;