tornado.tsx 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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: (params: Params) => [
  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. description: params.isProfilingSelected
  52. ? tct(
  53. 'You need a minimum version [codeVersion:1.18.0] of the [codePackage:sentry-python] SDK for the profiling feature.',
  54. {
  55. codeVersion: <code />,
  56. codePackage: <code />,
  57. }
  58. )
  59. : undefined,
  60. language: 'bash',
  61. code: getInstallSnippet(),
  62. },
  63. {
  64. description: tct(
  65. "If you're on Python 3.6, you also need the [code:aiocontextvars] package:",
  66. {
  67. code: <code />,
  68. }
  69. ),
  70. language: 'bash',
  71. code: 'pip install --upgrade aiocontextvars',
  72. },
  73. ],
  74. },
  75. ],
  76. configure: (params: Params) => [
  77. {
  78. type: StepType.CONFIGURE,
  79. description: tct(
  80. '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:',
  81. {
  82. codeTornado: <code />,
  83. }
  84. ),
  85. configurations: [
  86. {
  87. language: 'python',
  88. code: `${getSdkSetupSnippet(params)}
  89. class MainHandler(tornado.web.RequestHandler):
  90. # ...
  91. `,
  92. },
  93. ],
  94. },
  95. ],
  96. verify: (params: Params) => [
  97. {
  98. type: StepType.VERIFY,
  99. description: t(
  100. 'You can easily verify your Sentry installation by creating a route that triggers an error:'
  101. ),
  102. configurations: [
  103. {
  104. language: 'python',
  105. code: `
  106. import asyncio
  107. import tornado
  108. ${getSdkSetupSnippet(params)}
  109. class MainHandler(tornado.web.RequestHandler):
  110. def get(self):
  111. 1/0 # raises an error
  112. self.write("Hello, world")
  113. def make_app():
  114. return tornado.web.Application([
  115. (r"/", MainHandler),
  116. ])
  117. async def main():
  118. app = make_app()
  119. app.listen(8888)
  120. await asyncio.Event().wait()
  121. asyncio.run(main())
  122. `,
  123. },
  124. ],
  125. additionalInfo: (
  126. <div>
  127. <p>
  128. {tct(
  129. 'When you point your browser to [link:http://localhost:8888/] a transaction in the Performance section of Sentry will be created.',
  130. {
  131. link: <ExternalLink href="http://localhost:8888/" />,
  132. }
  133. )}
  134. </p>
  135. <p>
  136. {t(
  137. 'Additionally, an error event will be sent to Sentry and will be connected to the transaction.'
  138. )}
  139. </p>
  140. <p>{t('It takes a couple of moments for the data to appear in Sentry.')}</p>
  141. </div>
  142. ),
  143. },
  144. ],
  145. nextSteps: () => [],
  146. };
  147. const docs: Docs = {
  148. onboarding,
  149. replayOnboardingJsLoader,
  150. customMetricsOnboarding: getPythonMetricsOnboarding({
  151. installSnippet: getInstallSnippet(),
  152. }),
  153. crashReportOnboarding: crashReportOnboardingPython,
  154. };
  155. export default docs;