quart.tsx 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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[quart]'`;
  22. const getSdkSetupSnippet = (params: Params) => `
  23. import sentry_sdk
  24. from sentry_sdk.integrations.quart import QuartIntegration
  25. from quart import Quart
  26. sentry_sdk.init(
  27. dsn="${params.dsn.public}",
  28. integrations=[QuartIntegration()],${
  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 on when
  49. # possible.
  50. "continuous_profiling_auto_start": True,
  51. },`
  52. : ''
  53. }
  54. )
  55. `;
  56. const onboarding: OnboardingConfig = {
  57. introduction: () =>
  58. tct('The Quart integration adds support for the [link:Quart Web Framework].', {
  59. link: <ExternalLink href="https://quart.palletsprojects.com/" />,
  60. }),
  61. install: (params: Params) => [
  62. {
  63. type: StepType.INSTALL,
  64. description: tct(
  65. 'Install [code:sentry-sdk] from PyPI with the [code:quart] extra:',
  66. {
  67. code: <code />,
  68. }
  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. },
  86. ],
  87. configure: (params: Params) => [
  88. {
  89. type: StepType.CONFIGURE,
  90. description: t(
  91. 'To configure the SDK, initialize it with the integration before or after your app has been initialized:'
  92. ),
  93. configurations: [
  94. {
  95. language: 'python',
  96. code: `
  97. ${getSdkSetupSnippet(params)}
  98. app = Quart(__name__)
  99. `,
  100. },
  101. ],
  102. additionalInfo: <AlternativeConfiguration />,
  103. },
  104. ],
  105. verify: (params: Params) => [
  106. {
  107. type: StepType.VERIFY,
  108. description: t(
  109. 'You can easily verify your Sentry installation by creating a route that triggers an error:'
  110. ),
  111. configurations: [
  112. {
  113. language: 'python',
  114. code: `
  115. ${getSdkSetupSnippet(params)}
  116. app = Quart(__name__)
  117. @app.route("/")
  118. async def hello():
  119. 1/0 # raises an error
  120. return {"hello": "world"}
  121. app.run()
  122. `,
  123. },
  124. ],
  125. additionalInfo: (
  126. <span>
  127. <p>
  128. {tct(
  129. 'When you point your browser to [link:http://localhost:5000/] a transaction in the Performance section of Sentry will be created.',
  130. {
  131. link: <ExternalLink href="http://localhost:5000/" />,
  132. }
  133. )}
  134. </p>
  135. <p>
  136. {t(
  137. 'Additionally, an error event will be sent to Sentry and will be connected to the transaction.'
  138. )}
  139. </p>
  140. <p>{t('It takes a couple of moments for the data to appear in Sentry.')}</p>
  141. </span>
  142. ),
  143. },
  144. ],
  145. nextSteps: () => [],
  146. };
  147. const docs: Docs = {
  148. onboarding,
  149. replayOnboardingJsLoader,
  150. customMetricsOnboarding: getPythonMetricsOnboarding({
  151. installSnippet: getInstallSnippet(),
  152. }),
  153. crashReportOnboarding: crashReportOnboardingPython,
  154. featureFlagOnboarding,
  155. feedbackOnboardingJsLoader,
  156. };
  157. export default docs;