tornado.tsx 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. import ExternalLink from 'sentry/components/links/externalLink';
  2. import {Layout, LayoutProps} from 'sentry/components/onboarding/gettingStartedDoc/layout';
  3. import {ModuleProps} from 'sentry/components/onboarding/gettingStartedDoc/sdkDocumentation';
  4. import {StepType} from 'sentry/components/onboarding/gettingStartedDoc/step';
  5. import {ProductSolution} from 'sentry/components/onboarding/productSelection';
  6. import {t, tct} from 'sentry/locale';
  7. // Configuration Start
  8. const performanceConfiguration = ` # Set traces_sample_rate to 1.0 to capture 100%
  9. # of transactions for performance monitoring.
  10. traces_sample_rate=1.0,`;
  11. const profilingConfiguration = ` # Set profiles_sample_rate to 1.0 to profile 100%
  12. # of sampled transactions.
  13. # We recommend adjusting this value in production.
  14. profiles_sample_rate=1.0,`;
  15. const introduction = (
  16. <p>
  17. {tct('The Tornado integration adds support for the [link:Tornado Web Framework].', {
  18. link: <ExternalLink href="https://www.tornadoweb.org/en/stable/" />,
  19. })}
  20. </p>
  21. );
  22. export const steps = ({
  23. sentryInitContent,
  24. }: {
  25. sentryInitContent: string;
  26. }): LayoutProps['steps'] => [
  27. {
  28. type: StepType.INSTALL,
  29. description: (
  30. <p>
  31. {tct(
  32. 'Install [sentrySdkCode:sentry-sdk] from PyPI with the [sentryTornadoCode:tornado] extra:',
  33. {
  34. sentrySdkCode: <code />,
  35. sentryTornadoCode: <code />,
  36. }
  37. )}
  38. </p>
  39. ),
  40. configurations: [
  41. {
  42. language: 'bash',
  43. code: '$ pip install --upgrade sentry-sdk',
  44. },
  45. {
  46. description: (
  47. <p>
  48. {tct(
  49. "If you're on Python 3.6, you also need the [code:aiocontextvars] package:",
  50. {
  51. code: <code />,
  52. }
  53. )}
  54. </p>
  55. ),
  56. language: 'bash',
  57. code: '$ pip install --upgrade aiocontextvars',
  58. },
  59. ],
  60. },
  61. {
  62. type: StepType.CONFIGURE,
  63. description: (
  64. <p>
  65. {tct(
  66. '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:',
  67. {
  68. codeTornado: <code />,
  69. }
  70. )}
  71. </p>
  72. ),
  73. configurations: [
  74. {
  75. language: 'python',
  76. code: `import sentry_sdk
  77. sentry_sdk.init(
  78. ${sentryInitContent}
  79. )
  80. class MainHandler(tornado.web.RequestHandler):
  81. # ...
  82. `,
  83. },
  84. ],
  85. },
  86. {
  87. type: StepType.VERIFY,
  88. description: t(
  89. 'You can easily verify your Sentry installation by creating a route that triggers an error:'
  90. ),
  91. configurations: [
  92. {
  93. language: 'python',
  94. code: `import asyncio
  95. import tornado
  96. import sentry_sdk
  97. sentry_sdk.init(
  98. ${sentryInitContent}
  99. )
  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. additionalInfo: (
  115. <div>
  116. <p>
  117. {tct(
  118. 'When you point your browser to [link:http://localhost:8888/] a transaction in the Performance section of Sentry will be created.',
  119. {
  120. link: <ExternalLink href="http://localhost:8888/" />,
  121. }
  122. )}
  123. </p>
  124. <p>
  125. {t(
  126. 'Additionally, an error event will be sent to Sentry and will be connected to the transaction.'
  127. )}
  128. </p>
  129. <p>{t('It takes a couple of moments for the data to appear in Sentry.')}</p>
  130. </div>
  131. ),
  132. },
  133. ],
  134. },
  135. ];
  136. // Configuration End
  137. export function GettingStartedWithTornado({
  138. dsn,
  139. activeProductSelection = [],
  140. ...props
  141. }: ModuleProps) {
  142. const otherConfigs: string[] = [];
  143. let sentryInitContent: string[] = [` dsn="${dsn}",`];
  144. if (activeProductSelection.includes(ProductSolution.PERFORMANCE_MONITORING)) {
  145. otherConfigs.push(performanceConfiguration);
  146. }
  147. if (activeProductSelection.includes(ProductSolution.PROFILING)) {
  148. otherConfigs.push(profilingConfiguration);
  149. }
  150. sentryInitContent = sentryInitContent.concat(otherConfigs);
  151. return (
  152. <Layout
  153. introduction={introduction}
  154. steps={steps({
  155. sentryInitContent: sentryInitContent.join('\n'),
  156. })}
  157. {...props}
  158. />
  159. );
  160. }
  161. export default GettingStartedWithTornado;