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