tornado.tsx 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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 {
  10. feedbackOnboardingJsLoader,
  11. replayOnboardingJsLoader,
  12. } from 'sentry/gettingStartedDocs/javascript/jsLoader/jsLoader';
  13. import {
  14. AlternativeConfiguration,
  15. crashReportOnboardingPython,
  16. featureFlagOnboarding,
  17. } from 'sentry/gettingStartedDocs/python/python';
  18. import {t, tct} from 'sentry/locale';
  19. type Params = DocsParams;
  20. const getInstallSnippet = () => `pip install --upgrade sentry-sdk`;
  21. const getSdkSetupSnippet = (params: Params) => `
  22. import sentry_sdk
  23. sentry_sdk.init(
  24. dsn="${params.dsn.public}",
  25. # Add data like request headers and IP for users,
  26. # see https://docs.sentry.io/platforms/python/data-management/data-collected/ for more info
  27. send_default_pii=True,${
  28. params.isPerformanceSelected
  29. ? `
  30. # Set traces_sample_rate to 1.0 to capture 100%
  31. # of transactions for tracing.
  32. traces_sample_rate=1.0,`
  33. : ''
  34. }${
  35. params.isProfilingSelected &&
  36. params.profilingOptions?.defaultProfilingMode !== 'continuous'
  37. ? `
  38. # Set profiles_sample_rate to 1.0 to profile 100%
  39. # of sampled transactions.
  40. # We recommend adjusting this value in production.
  41. profiles_sample_rate=1.0,`
  42. : params.isProfilingSelected &&
  43. params.profilingOptions?.defaultProfilingMode === 'continuous'
  44. ? `
  45. _experiments={
  46. # Set continuous_profiling_auto_start to True
  47. # to automatically start the profiler on when
  48. # possible.
  49. "continuous_profiling_auto_start": True,
  50. },`
  51. : ''
  52. }
  53. )
  54. `;
  55. const onboarding: OnboardingConfig = {
  56. introduction: () =>
  57. tct('The Tornado integration adds support for the [link:Tornado Web Framework].', {
  58. link: <ExternalLink href="https://www.tornadoweb.org/en/stable/" />,
  59. }),
  60. install: (params: Params) => [
  61. {
  62. type: StepType.INSTALL,
  63. description: tct(
  64. 'Install [code:sentry-sdk] from PyPI with the [code:tornado] extra:',
  65. {
  66. code: <code />,
  67. }
  68. ),
  69. configurations: [
  70. {
  71. description:
  72. params.docsLocation === DocsPageLocation.PROFILING_PAGE
  73. ? tct(
  74. 'You need a minimum version [code:1.18.0] of the [code:sentry-python] SDK for the profiling feature.',
  75. {
  76. code: <code />,
  77. }
  78. )
  79. : undefined,
  80. language: 'bash',
  81. code: getInstallSnippet(),
  82. },
  83. {
  84. description: tct(
  85. "If you're on Python 3.6, you also need the [code:aiocontextvars] package:",
  86. {
  87. code: <code />,
  88. }
  89. ),
  90. language: 'bash',
  91. code: 'pip install --upgrade aiocontextvars',
  92. },
  93. ],
  94. },
  95. ],
  96. configure: (params: Params) => [
  97. {
  98. type: StepType.CONFIGURE,
  99. description: tct(
  100. '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:',
  101. {
  102. codeTornado: <code />,
  103. }
  104. ),
  105. configurations: [
  106. {
  107. language: 'python',
  108. code: `
  109. ${getSdkSetupSnippet(params)}
  110. class MainHandler(tornado.web.RequestHandler):
  111. # ...
  112. `,
  113. },
  114. ],
  115. additionalInfo: <AlternativeConfiguration />,
  116. },
  117. ],
  118. verify: (params: Params) => [
  119. {
  120. type: StepType.VERIFY,
  121. description: t(
  122. 'You can easily verify your Sentry installation by creating a route that triggers an error:'
  123. ),
  124. configurations: [
  125. {
  126. language: 'python',
  127. code: `
  128. import asyncio
  129. import tornado
  130. ${getSdkSetupSnippet(params)}
  131. class MainHandler(tornado.web.RequestHandler):
  132. def get(self):
  133. 1/0 # raises an error
  134. self.write("Hello, world")
  135. def make_app():
  136. return tornado.web.Application([
  137. (r"/", MainHandler),
  138. ])
  139. async def main():
  140. app = make_app()
  141. app.listen(8888)
  142. await asyncio.Event().wait()
  143. asyncio.run(main())
  144. `,
  145. },
  146. ],
  147. additionalInfo: (
  148. <div>
  149. <p>
  150. {tct(
  151. 'When you point your browser to [link:http://localhost:8888/] a transaction in the Performance section of Sentry will be created.',
  152. {
  153. link: <ExternalLink href="http://localhost:8888/" />,
  154. }
  155. )}
  156. </p>
  157. <p>
  158. {t(
  159. 'Additionally, an error event will be sent to Sentry and will be connected to the transaction.'
  160. )}
  161. </p>
  162. <p>{t('It takes a couple of moments for the data to appear in Sentry.')}</p>
  163. </div>
  164. ),
  165. },
  166. ],
  167. nextSteps: () => [],
  168. };
  169. const docs: Docs = {
  170. onboarding,
  171. replayOnboardingJsLoader,
  172. crashReportOnboarding: crashReportOnboardingPython,
  173. featureFlagOnboarding,
  174. feedbackOnboardingJsLoader,
  175. };
  176. export default docs;