flask.tsx 2.8 KB

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