flask.tsx 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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 {t, tct} from 'sentry/locale';
  6. // Configuration Start
  7. export const steps = ({
  8. dsn,
  9. }: Partial<Pick<ModuleProps, 'dsn'>> = {}): LayoutProps['steps'] => [
  10. {
  11. type: StepType.INSTALL,
  12. description: (
  13. <p>
  14. {tct(
  15. 'The Flask integration adds support for the [flaskWebFrameworkLink:Flask Web Framework].',
  16. {
  17. flaskWebFrameworkLink: (
  18. <ExternalLink href="https://flask.palletsprojects.com/en/2.3.x/" />
  19. ),
  20. }
  21. )}
  22. </p>
  23. ),
  24. configurations: [
  25. {
  26. language: 'bash',
  27. description: (
  28. <p>
  29. {tct(
  30. 'Install [sentrySdkCode:sentry-sdk] from PyPI with the [sentryFlaskCode:flask] extra:',
  31. {
  32. sentrySdkCode: <code />,
  33. sentryFlaskCode: <code />,
  34. }
  35. )}
  36. </p>
  37. ),
  38. code: "pip install --upgrade 'sentry-sdk[flask]'",
  39. },
  40. ],
  41. },
  42. {
  43. type: StepType.CONFIGURE,
  44. description: t(
  45. 'To configure the SDK, initialize it with the integration before or after your app has been initialized:'
  46. ),
  47. configurations: [
  48. {
  49. language: 'python',
  50. code: `
  51. import sentry_sdk
  52. from flask import Flask
  53. from sentry_sdk.integrations.flask import FlaskIntegration
  54. sentry_sdk.init(
  55. dsn="${dsn}",
  56. integrations=[
  57. FlaskIntegration(),
  58. ],
  59. # Set traces_sample_rate to 1.0 to capture 100%
  60. # of transactions for performance monitoring.
  61. # We recommend adjusting this value in production.
  62. traces_sample_rate=1.0
  63. )
  64. app = Flask(__name__)
  65. `,
  66. },
  67. ],
  68. additionalInfo: (
  69. <p>
  70. {tct(
  71. '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.',
  72. {code: <code />}
  73. )}
  74. </p>
  75. ),
  76. },
  77. {
  78. type: StepType.VERIFY,
  79. description: t(
  80. 'You can easily verify your Sentry installation by creating a route that triggers an error:'
  81. ),
  82. configurations: [
  83. {
  84. language: 'python',
  85. code: `
  86. @app.route('/debug-sentry')
  87. def trigger_error():
  88. division_by_zero = 1 / 0
  89. `,
  90. },
  91. ],
  92. additionalInfo: t(
  93. 'Visiting this route will trigger an error that will be captured by Sentry.'
  94. ),
  95. },
  96. ];
  97. // Configuration End
  98. export function GettingStartedWithFlask({dsn, ...props}: ModuleProps) {
  99. return <Layout steps={steps({dsn})} {...props} />;
  100. }
  101. export default GettingStartedWithFlask;