flask.tsx 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. import ExternalLink from 'sentry/components/links/externalLink';
  2. import {Layout, LayoutProps} from 'sentry/components/onboarding/gettingStartedDoc/layout';
  3. import {ModuleProps} from 'sentry/components/onboarding/gettingStartedDoc/sdkDocumentation';
  4. import {StepType} from 'sentry/components/onboarding/gettingStartedDoc/step';
  5. import {ProductSolution} from 'sentry/components/onboarding/productSelection';
  6. import {t, tct} from 'sentry/locale';
  7. // Configuration Start
  8. const profilingConfiguration = ` # Set profiles_sample_rate to 1.0 to profile 100%
  9. # of sampled transactions.
  10. # We recommend adjusting this value in production.
  11. profiles_sample_rate=1.0,`;
  12. const performanceConfiguration = ` # Set traces_sample_rate to 1.0 to capture 100%
  13. # of transactions for performance monitoring.
  14. # We recommend adjusting this value in production.
  15. traces_sample_rate=1.0,`;
  16. export const steps = ({
  17. sentryInitContent,
  18. }: {
  19. sentryInitContent: string;
  20. }): LayoutProps['steps'] => [
  21. {
  22. type: StepType.INSTALL,
  23. description: (
  24. <p>
  25. {tct(
  26. 'The Flask integration adds support for the [flaskWebFrameworkLink:Flask Web Framework].',
  27. {
  28. flaskWebFrameworkLink: (
  29. <ExternalLink href="https://flask.palletsprojects.com/en/2.3.x/" />
  30. ),
  31. }
  32. )}
  33. </p>
  34. ),
  35. configurations: [
  36. {
  37. language: 'bash',
  38. description: (
  39. <p>
  40. {tct(
  41. 'Install [sentrySdkCode:sentry-sdk] from PyPI with the [sentryFlaskCode:flask] extra:',
  42. {
  43. sentrySdkCode: <code />,
  44. sentryFlaskCode: <code />,
  45. }
  46. )}
  47. </p>
  48. ),
  49. code: "pip install --upgrade 'sentry-sdk[flask]'",
  50. },
  51. ],
  52. },
  53. {
  54. type: StepType.CONFIGURE,
  55. description: t(
  56. 'To configure the SDK, initialize it with the integration before or after your app has been initialized:'
  57. ),
  58. configurations: [
  59. {
  60. language: 'python',
  61. code: `
  62. import sentry_sdk
  63. from flask import Flask
  64. from sentry_sdk.integrations.flask import FlaskIntegration
  65. sentry_sdk.init(
  66. ${sentryInitContent}
  67. )
  68. app = Flask(__name__)
  69. `,
  70. },
  71. ],
  72. additionalInfo: (
  73. <p>
  74. {tct(
  75. 'The above configuration captures both error and performance data. To reduce the volume of performance data captured, change [code:traces_sample_rate] to a value between 0 and 1.',
  76. {code: <code />}
  77. )}
  78. </p>
  79. ),
  80. },
  81. {
  82. type: StepType.VERIFY,
  83. description: t(
  84. 'You can easily verify your Sentry installation by creating a route that triggers an error:'
  85. ),
  86. configurations: [
  87. {
  88. language: 'python',
  89. code: `
  90. @app.route('/debug-sentry')
  91. def trigger_error():
  92. division_by_zero = 1 / 0
  93. `,
  94. },
  95. ],
  96. additionalInfo: t(
  97. 'Visiting this route will trigger an error that will be captured by Sentry.'
  98. ),
  99. },
  100. ];
  101. // Configuration End
  102. export function GettingStartedWithFlask({
  103. dsn,
  104. activeProductSelection = [],
  105. ...props
  106. }: ModuleProps) {
  107. const otherConfigs: string[] = [];
  108. let sentryInitContent: string[] = [
  109. ` dsn="${dsn}",`,
  110. ` integrations=[FlaskIntegration()],`,
  111. ];
  112. if (activeProductSelection.includes(ProductSolution.PERFORMANCE_MONITORING)) {
  113. otherConfigs.push(performanceConfiguration);
  114. }
  115. if (activeProductSelection.includes(ProductSolution.PROFILING)) {
  116. otherConfigs.push(profilingConfiguration);
  117. }
  118. sentryInitContent = sentryInitContent.concat(otherConfigs);
  119. return (
  120. <Layout
  121. steps={steps({
  122. sentryInitContent: sentryInitContent.join('\n'),
  123. })}
  124. {...props}
  125. />
  126. );
  127. }
  128. export default GettingStartedWithFlask;