tornado.tsx 3.9 KB

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