aiohttp.tsx 4.0 KB

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