aiohttp.tsx 4.5 KB

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