quart.tsx 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. import {Fragment} from 'react';
  2. import ExternalLink from 'sentry/components/links/externalLink';
  3. import {Layout, LayoutProps} from 'sentry/components/onboarding/gettingStartedDoc/layout';
  4. import {ModuleProps} from 'sentry/components/onboarding/gettingStartedDoc/sdkDocumentation';
  5. import {StepType} from 'sentry/components/onboarding/gettingStartedDoc/step';
  6. import {ProductSolution} from 'sentry/components/onboarding/productSelection';
  7. import {t, tct} from 'sentry/locale';
  8. // Configuration Start
  9. const performanceConfiguration = ` # Set traces_sample_rate to 1.0 to capture 100%
  10. # of transactions for performance monitoring.
  11. traces_sample_rate=1.0,`;
  12. const profilingConfiguration = ` # Set profiles_sample_rate to 1.0 to profile 100%
  13. # of sampled transactions.
  14. # We recommend adjusting this value in production.
  15. profiles_sample_rate=1.0,`;
  16. const introduction = (
  17. <Fragment>
  18. <p>
  19. {tct('The Quart integration adds support for the [link:Quart Web Framework].', {
  20. link: <ExternalLink href="https://quart.palletsprojects.com/" />,
  21. })}
  22. </p>
  23. </Fragment>
  24. );
  25. export const steps = ({
  26. sentryInitContent,
  27. }: {
  28. sentryInitContent: string;
  29. }): LayoutProps['steps'] => [
  30. {
  31. type: StepType.INSTALL,
  32. description: (
  33. <p>
  34. {tct(
  35. 'Install [sentrySdkCode:sentry-sdk] from PyPI with the [sentryQuartCode:quart] extra:',
  36. {
  37. sentrySdkCode: <code />,
  38. sentryQuartCode: <code />,
  39. }
  40. )}
  41. </p>
  42. ),
  43. configurations: [
  44. {
  45. language: 'bash',
  46. code: '$ pip install --upgrade sentry-sdk[quart]',
  47. },
  48. ],
  49. },
  50. {
  51. type: StepType.CONFIGURE,
  52. description: t(
  53. 'To configure the SDK, initialize it with the integration before or after your app has been initialized:'
  54. ),
  55. configurations: [
  56. {
  57. language: 'python',
  58. code: `
  59. import sentry_sdk
  60. from sentry_sdk.integrations.quart import QuartIntegration
  61. from quart import Quart
  62. sentry_sdk.init(
  63. ${sentryInitContent}
  64. )
  65. app = Quart(__name__)
  66. `,
  67. },
  68. ],
  69. },
  70. {
  71. type: StepType.VERIFY,
  72. description: t(
  73. 'You can easily verify your Sentry installation by creating a route that triggers an error:'
  74. ),
  75. configurations: [
  76. {
  77. language: 'python',
  78. code: `from quart import Quart
  79. import sentry_sdk
  80. sentry_sdk.init(
  81. ${sentryInitContent}
  82. )
  83. app = Quart(__name__)
  84. @app.route("/")
  85. async def hello():
  86. 1/0 # raises an error
  87. return {"hello": "world"}
  88. app.run()
  89. `,
  90. },
  91. ],
  92. additionalInfo: (
  93. <span>
  94. <p>
  95. {tct(
  96. 'When you point your browser to [link:http://localhost:5000/] a transaction in the Performance section of Sentry will be created.',
  97. {
  98. link: <ExternalLink href="http://localhost:5000/" />,
  99. }
  100. )}
  101. </p>
  102. <p>
  103. {t(
  104. 'Additionally, an error event will be sent to Sentry and will be connected to the transaction.'
  105. )}
  106. </p>
  107. <p>{t('It takes a couple of moments for the data to appear in Sentry.')}</p>
  108. </span>
  109. ),
  110. },
  111. ];
  112. // Configuration End
  113. export function GettingStartedWithQuart({
  114. dsn,
  115. activeProductSelection = [],
  116. ...props
  117. }: ModuleProps) {
  118. const otherConfigs: string[] = [];
  119. let sentryInitContent: string[] = [
  120. ` dsn="${dsn}",`,
  121. ` integrations=[QuartIntegration()],`,
  122. ];
  123. if (activeProductSelection.includes(ProductSolution.PERFORMANCE_MONITORING)) {
  124. otherConfigs.push(performanceConfiguration);
  125. }
  126. if (activeProductSelection.includes(ProductSolution.PROFILING)) {
  127. otherConfigs.push(profilingConfiguration);
  128. }
  129. sentryInitContent = sentryInitContent.concat(otherConfigs);
  130. return (
  131. <Layout
  132. introduction={introduction}
  133. steps={steps({
  134. sentryInitContent: sentryInitContent.join('\n'),
  135. })}
  136. {...props}
  137. />
  138. );
  139. }
  140. export default GettingStartedWithQuart;