quart.tsx 4.5 KB

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