tornado.tsx 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. import ExternalLink from 'sentry/components/links/externalLink';
  2. import {StepType} from 'sentry/components/onboarding/gettingStartedDoc/step';
  3. import {
  4. Docs,
  5. DocsParams,
  6. OnboardingConfig,
  7. } from 'sentry/components/onboarding/gettingStartedDoc/types';
  8. import {getPythonMetricsOnboarding} from 'sentry/components/onboarding/gettingStartedDoc/utils/metricsOnboarding';
  9. import replayOnboardingJsLoader from 'sentry/gettingStartedDocs/javascript/jsLoader/jsLoader';
  10. import {t, tct} from 'sentry/locale';
  11. type Params = DocsParams;
  12. const getInstallSnippet = () => `pip install --upgrade sentry-sdk`;
  13. const getSdkSetupSnippet = (params: Params) => `import sentry_sdk
  14. sentry_sdk.init(
  15. dsn="${params.dsn}",${
  16. params.isPerformanceSelected
  17. ? `
  18. # Set traces_sample_rate to 1.0 to capture 100%
  19. # of transactions for performance monitoring.
  20. traces_sample_rate=1.0,`
  21. : ''
  22. }${
  23. params.isProfilingSelected
  24. ? `
  25. # Set profiles_sample_rate to 1.0 to profile 100%
  26. # of sampled transactions.
  27. # We recommend adjusting this value in production.
  28. profiles_sample_rate=1.0,`
  29. : ''
  30. }
  31. )
  32. `;
  33. const onboarding: OnboardingConfig = {
  34. introduction: () =>
  35. tct('The Tornado integration adds support for the [link:Tornado Web Framework].', {
  36. link: <ExternalLink href="https://www.tornadoweb.org/en/stable/" />,
  37. }),
  38. install: () => [
  39. {
  40. type: StepType.INSTALL,
  41. description: tct(
  42. 'Install [sentrySdkCode:sentry-sdk] from PyPI with the [sentryTornadoCode:tornado] extra:',
  43. {
  44. sentrySdkCode: <code />,
  45. sentryTornadoCode: <code />,
  46. }
  47. ),
  48. configurations: [
  49. {
  50. language: 'bash',
  51. code: getInstallSnippet(),
  52. },
  53. {
  54. description: tct(
  55. "If you're on Python 3.6, you also need the [code:aiocontextvars] package:",
  56. {
  57. code: <code />,
  58. }
  59. ),
  60. language: 'bash',
  61. code: 'pip install --upgrade aiocontextvars',
  62. },
  63. ],
  64. },
  65. ],
  66. configure: (params: Params) => [
  67. {
  68. type: StepType.CONFIGURE,
  69. description: tct(
  70. '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:',
  71. {
  72. codeTornado: <code />,
  73. }
  74. ),
  75. configurations: [
  76. {
  77. language: 'python',
  78. code: `${getSdkSetupSnippet(params)}
  79. class MainHandler(tornado.web.RequestHandler):
  80. # ...
  81. `,
  82. },
  83. ],
  84. },
  85. ],
  86. verify: (params: Params) => [
  87. {
  88. type: StepType.VERIFY,
  89. description: t(
  90. 'You can easily verify your Sentry installation by creating a route that triggers an error:'
  91. ),
  92. configurations: [
  93. {
  94. language: 'python',
  95. code: `
  96. import asyncio
  97. import tornado
  98. ${getSdkSetupSnippet(params)}
  99. class MainHandler(tornado.web.RequestHandler):
  100. def get(self):
  101. 1/0 # raises an error
  102. self.write("Hello, world")
  103. def make_app():
  104. return tornado.web.Application([
  105. (r"/", MainHandler),
  106. ])
  107. async def main():
  108. app = make_app()
  109. app.listen(8888)
  110. await asyncio.Event().wait()
  111. asyncio.run(main())
  112. `,
  113. },
  114. ],
  115. additionalInfo: (
  116. <div>
  117. <p>
  118. {tct(
  119. 'When you point your browser to [link:http://localhost:8888/] a transaction in the Performance section of Sentry will be created.',
  120. {
  121. link: <ExternalLink href="http://localhost:8888/" />,
  122. }
  123. )}
  124. </p>
  125. <p>
  126. {t(
  127. 'Additionally, an error event will be sent to Sentry and will be connected to the transaction.'
  128. )}
  129. </p>
  130. <p>{t('It takes a couple of moments for the data to appear in Sentry.')}</p>
  131. </div>
  132. ),
  133. },
  134. ],
  135. nextSteps: () => [],
  136. };
  137. const docs: Docs = {
  138. onboarding,
  139. replayOnboardingJsLoader,
  140. customMetricsOnboarding: getPythonMetricsOnboarding({
  141. installSnippet: getInstallSnippet(),
  142. }),
  143. };
  144. export default docs;