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