aiohttp.tsx 5.0 KB

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