aiohttp.tsx 5.1 KB

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