tornado.tsx 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  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`;
  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 === 'transaction'
  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 Tornado integration adds support for the [link:Tornado Web Framework].', {
  52. link: <ExternalLink href="https://www.tornadoweb.org/en/stable/" />,
  53. }),
  54. install: (params: Params) => [
  55. {
  56. type: StepType.INSTALL,
  57. description: tct(
  58. 'Install [code:sentry-sdk] from PyPI with the [code:tornado] 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. description: tct(
  79. "If you're on Python 3.6, you also need the [code:aiocontextvars] package:",
  80. {
  81. code: <code />,
  82. }
  83. ),
  84. language: 'bash',
  85. code: 'pip install --upgrade aiocontextvars',
  86. },
  87. ],
  88. },
  89. ],
  90. configure: (params: Params) => [
  91. {
  92. type: StepType.CONFIGURE,
  93. description: tct(
  94. 'If you have the [codeTornado:tornado] package in your dependencies, the Tornado integration will be enabled automatically when you initialize the Sentry SDK. Initialize the Sentry SDK before your app has been initialized:',
  95. {
  96. codeTornado: <code />,
  97. }
  98. ),
  99. configurations: [
  100. {
  101. language: 'python',
  102. code: `
  103. ${getSdkSetupSnippet(params)}
  104. class MainHandler(tornado.web.RequestHandler):
  105. # ...
  106. `,
  107. },
  108. ],
  109. additionalInfo: <AlternativeConfiguration />,
  110. },
  111. ],
  112. verify: (params: Params) => [
  113. {
  114. type: StepType.VERIFY,
  115. description: t(
  116. 'You can easily verify your Sentry installation by creating a route that triggers an error:'
  117. ),
  118. configurations: [
  119. {
  120. language: 'python',
  121. code: `
  122. import asyncio
  123. import tornado
  124. ${getSdkSetupSnippet(params)}
  125. class MainHandler(tornado.web.RequestHandler):
  126. def get(self):
  127. 1/0 # raises an error
  128. self.write("Hello, world")
  129. def make_app():
  130. return tornado.web.Application([
  131. (r"/", MainHandler),
  132. ])
  133. async def main():
  134. app = make_app()
  135. app.listen(8888)
  136. await asyncio.Event().wait()
  137. asyncio.run(main())
  138. `,
  139. },
  140. ],
  141. additionalInfo: (
  142. <div>
  143. <p>
  144. {tct(
  145. 'When you point your browser to [link:http://localhost:8888/] a transaction in the Performance section of Sentry will be created.',
  146. {
  147. link: <ExternalLink href="http://localhost:8888/" />,
  148. }
  149. )}
  150. </p>
  151. <p>
  152. {t(
  153. 'Additionally, an error event will be sent to Sentry and will be connected to the transaction.'
  154. )}
  155. </p>
  156. <p>{t('It takes a couple of moments for the data to appear in Sentry.')}</p>
  157. </div>
  158. ),
  159. },
  160. ],
  161. nextSteps: () => [],
  162. };
  163. const docs: Docs = {
  164. onboarding,
  165. replayOnboardingJsLoader,
  166. customMetricsOnboarding: getPythonMetricsOnboarding({
  167. installSnippet: getInstallSnippet(),
  168. }),
  169. crashReportOnboarding: crashReportOnboardingPython,
  170. };
  171. export default docs;