aiohttp.tsx 5.0 KB

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