quart.tsx 4.5 KB

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