tornado.tsx 4.3 KB

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