bottle.tsx 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. import ExternalLink from 'sentry/components/links/externalLink';
  2. import {Layout, LayoutProps} from 'sentry/components/onboarding/gettingStartedDoc/layout';
  3. import {ModuleProps} from 'sentry/components/onboarding/gettingStartedDoc/sdkDocumentation';
  4. import {StepType} from 'sentry/components/onboarding/gettingStartedDoc/step';
  5. import {ProductSolution} from 'sentry/components/onboarding/productSelection';
  6. import {t, tct} from 'sentry/locale';
  7. // Configuration Start
  8. const performanceConfiguration = ` # Set traces_sample_rate to 1.0 to capture 100%
  9. # of transactions for performance monitoring.
  10. traces_sample_rate=1.0,`;
  11. const profilingConfiguration = ` # Set profiles_sample_rate to 1.0 to profile 100%
  12. # of sampled transactions.
  13. # We recommend adjusting this value in production.
  14. profiles_sample_rate=1.0,`;
  15. const introduction = (
  16. <p>
  17. {tct('The Bottle integration adds support for the [link:Bottle Web Framework].', {
  18. link: <ExternalLink href="https://bottlepy.org/docs/dev/" />,
  19. })}
  20. </p>
  21. );
  22. export const steps = ({
  23. sentryInitContent,
  24. }: {
  25. sentryInitContent: string;
  26. }): LayoutProps['steps'] => [
  27. {
  28. type: StepType.INSTALL,
  29. description: (
  30. <p>
  31. {tct(
  32. 'Install [sentrySdkCode:sentry-sdk] from PyPI with the [sentryBotteCode:bottle] extra:',
  33. {
  34. sentrySdkCode: <code />,
  35. sentryBotteCode: <code />,
  36. }
  37. )}
  38. </p>
  39. ),
  40. configurations: [
  41. {
  42. language: 'bash',
  43. code: 'pip install --upgrade sentry-sdk[bottle]',
  44. },
  45. ],
  46. },
  47. {
  48. type: StepType.CONFIGURE,
  49. description: (
  50. <p>
  51. {tct(
  52. '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:',
  53. {
  54. code: <code />,
  55. }
  56. )}
  57. </p>
  58. ),
  59. configurations: [
  60. {
  61. language: 'python',
  62. code: `
  63. import sentry_sdk
  64. from bottle import Bottle
  65. sentry_sdk.init(
  66. ${sentryInitContent}
  67. )
  68. app = Bottle()
  69. `,
  70. },
  71. ],
  72. },
  73. {
  74. type: StepType.VERIFY,
  75. description: (
  76. <p>{t('To verify that everything is working trigger an error on purpose:')}</p>
  77. ),
  78. configurations: [
  79. {
  80. language: 'python',
  81. code: `from bottle import Bottle, run
  82. sentry_sdk.init(
  83. ${sentryInitContent}
  84. )
  85. app = Bottle()
  86. @app.route('/')
  87. def hello():
  88. 1/0
  89. return "Hello World!"
  90. run(app, host='localhost', port=8000)
  91. `,
  92. },
  93. ],
  94. additionalInfo: (
  95. <span>
  96. <p>
  97. {tct(
  98. 'When you point your browser to [link:http://localhost:8000/] a transaction in the Performance section of Sentry will be created.',
  99. {
  100. link: <ExternalLink href="http://localhost:8000/" />,
  101. }
  102. )}
  103. </p>
  104. <p>
  105. {t(
  106. 'Additionally, an error event will be sent to Sentry and will be connected to the transaction.'
  107. )}
  108. </p>
  109. <p>{t('It takes a couple of moments for the data to appear in Sentry.')}</p>
  110. </span>
  111. ),
  112. },
  113. ];
  114. // Configuration End
  115. export function GettingStartedWithBottle({
  116. dsn,
  117. activeProductSelection = [],
  118. ...props
  119. }: ModuleProps) {
  120. const otherConfigs: string[] = [];
  121. let sentryInitContent: string[] = [` dsn="${dsn}",`];
  122. if (activeProductSelection.includes(ProductSolution.PERFORMANCE_MONITORING)) {
  123. otherConfigs.push(performanceConfiguration);
  124. }
  125. if (activeProductSelection.includes(ProductSolution.PROFILING)) {
  126. otherConfigs.push(profilingConfiguration);
  127. }
  128. sentryInitContent = sentryInitContent.concat(otherConfigs);
  129. return (
  130. <Layout
  131. introduction={introduction}
  132. steps={steps({
  133. sentryInitContent: sentryInitContent.join('\n'),
  134. })}
  135. {...props}
  136. />
  137. );
  138. }
  139. export default GettingStartedWithBottle;