aiohttp.tsx 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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(
  18. 'The AIOHTTP integration adds support for the [link:AIOHTTP-Server Web Framework].',
  19. {
  20. link: <ExternalLink href="https://docs.aiohttp.org/en/stable/web.html" />,
  21. }
  22. )}
  23. </p>
  24. );
  25. export const steps = ({
  26. sentryInitContent,
  27. }: {
  28. sentryInitContent: string;
  29. }): LayoutProps['steps'] => [
  30. {
  31. type: StepType.INSTALL,
  32. description: (
  33. <p>
  34. {tct('Install [code:sentry-sdk] from PyPI:', {
  35. code: <code />,
  36. })}
  37. </p>
  38. ),
  39. configurations: [
  40. {
  41. language: 'bash',
  42. code: '$ pip install --upgrade sentry-sdk',
  43. },
  44. {
  45. description: (
  46. <p>
  47. {tct(
  48. "If you're on Python 3.6, you also need the [code:aiocontextvars] package:",
  49. {
  50. code: <code />,
  51. }
  52. )}
  53. </p>
  54. ),
  55. language: 'bash',
  56. code: '$ pip install --upgrade aiocontextvars',
  57. },
  58. ],
  59. },
  60. {
  61. type: StepType.CONFIGURE,
  62. description: (
  63. <p>
  64. {tct(
  65. 'If you have the [code:aiohttp] package in your dependencies, the AIOHTTO integration will be enabled automatically. There is nothing to do for you except initializing the Sentry SDK before initializing your application:',
  66. {
  67. code: <code />,
  68. }
  69. )}
  70. </p>
  71. ),
  72. configurations: [
  73. {
  74. language: 'python',
  75. code: `
  76. from aiohttp import web
  77. import sentry_sdk
  78. sentry_sdk.init(
  79. ${sentryInitContent}
  80. )
  81. async def hello(request):
  82. return web.Response(text="Hello, world")
  83. app = web.Application()
  84. app.add_routes([web.get('/', hello)])
  85. web.run_app(app)
  86. `,
  87. },
  88. ],
  89. },
  90. {
  91. type: StepType.VERIFY,
  92. description: t(
  93. 'You can easily verify your Sentry installation by creating a route that triggers an error:'
  94. ),
  95. configurations: [
  96. {
  97. language: 'python',
  98. code: `
  99. from aiohttp import web
  100. sentry_sdk.init(
  101. ${sentryInitContent}
  102. )
  103. async def hello(request):
  104. 1/0 # raises an error
  105. return web.Response(text="Hello, world")
  106. app = web.Application()
  107. app.add_routes([web.get('/', hello)])
  108. web.run_app(app)`,
  109. },
  110. ],
  111. additionalInfo: (
  112. <span>
  113. <p>
  114. {tct(
  115. `When you point your browser to [localhostLInk:http://localhost:8080/] a transaction in the Performance section of Sentry will be created.`,
  116. {
  117. localhostLInk: <ExternalLink href="http://localhost:8080/" />,
  118. }
  119. )}
  120. </p>
  121. <p>
  122. {t(
  123. 'Additionally, an error event will be sent to Sentry and will be connected to the transaction.'
  124. )}
  125. </p>
  126. <p>{t('It takes a couple of moments for the data to appear in Sentry.')}</p>
  127. </span>
  128. ),
  129. },
  130. ];
  131. // Configuration End
  132. export function GettingStartedWithAIOHTTP({
  133. dsn,
  134. activeProductSelection = [],
  135. ...props
  136. }: ModuleProps) {
  137. const otherConfigs: string[] = [];
  138. let sentryInitContent: string[] = [` dsn="${dsn}",`];
  139. if (activeProductSelection.includes(ProductSolution.PERFORMANCE_MONITORING)) {
  140. otherConfigs.push(performanceConfiguration);
  141. }
  142. if (activeProductSelection.includes(ProductSolution.PROFILING)) {
  143. otherConfigs.push(profilingConfiguration);
  144. }
  145. sentryInitContent = sentryInitContent.concat(otherConfigs);
  146. return (
  147. <Layout
  148. introduction={introduction}
  149. steps={steps({
  150. sentryInitContent: sentryInitContent.join('\n'),
  151. })}
  152. {...props}
  153. />
  154. );
  155. }
  156. export default GettingStartedWithAIOHTTP;