bottle.tsx 4.7 KB

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